Changeset 6317 for branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models
- Timestamp:
- 05/27/11 19:09:49 (14 years ago)
- Location:
- branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/AccountModels.cs
r4985 r6317 11 11 namespace HLWebServiceTestPlugin.Models { 12 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 13 #region Models 14 [PropertiesMustMatch("NewPassword", "ConfirmPassword", ErrorMessage = "The new password and confirmation password do not match.")] 15 public class ChangePasswordModel { 16 [Required] 17 [DataType(DataType.Password)] 18 [DisplayName("Current password")] 19 public string OldPassword { get; set; } 20 21 [Required] 22 [ValidatePasswordLength] 23 [DataType(DataType.Password)] 24 [DisplayName("New password")] 25 public string NewPassword { get; set; } 26 27 [Required] 28 [DataType(DataType.Password)] 29 [DisplayName("Confirm new password")] 30 public string ConfirmPassword { get; set; } 31 } 32 33 public class LogOnModel { 34 [Required] 35 [DisplayName("User name")] 36 public string UserName { get; set; } 37 38 [Required] 39 [DataType(DataType.Password)] 40 [DisplayName("Password")] 41 public string Password { get; set; } 42 43 [DisplayName("Remember me?")] 44 public bool RememberMe { get; set; } 45 } 46 47 [PropertiesMustMatch("Password", "ConfirmPassword", ErrorMessage = "The password and confirmation password do not match.")] 48 public class RegisterModel { 49 [Required] 50 [DisplayName("User name")] 51 public string UserName { get; set; } 52 53 [Required] 54 [DataType(DataType.EmailAddress)] 55 [DisplayName("Email address")] 56 public string Email { get; set; } 57 58 [Required] 59 [ValidatePasswordLength] 60 [DataType(DataType.Password)] 61 [DisplayName("Password")] 62 public string Password { get; set; } 63 64 [Required] 65 [DataType(DataType.Password)] 66 [DisplayName("Confirm password")] 67 public string ConfirmPassword { get; set; } 68 } 69 #endregion 70 71 #region Services 72 // The FormsAuthentication type is sealed and contains static members, so it is difficult to 73 // unit test code that calls its members. The interface and helper class below demonstrate 74 // how to create an abstract wrapper around such a type in order to make the AccountController 75 // code unit testable. 76 77 public interface IMembershipService { 78 int MinPasswordLength { get; } 79 80 bool ValidateUser(string userName, string password); 81 MembershipCreateStatus CreateUser(string userName, string password, string email); 82 bool ChangePassword(string userName, string oldPassword, string newPassword); 83 } 84 85 public class AccountMembershipService : IMembershipService { 86 private readonly MembershipProvider _provider; 87 88 public AccountMembershipService() 89 : this(null) { 90 } 91 92 public AccountMembershipService(MembershipProvider provider) { 93 _provider = provider ?? Membership.Provider; 94 } 95 96 public int MinPasswordLength { 97 get { 98 return _provider.MinRequiredPasswordLength; 99 } 100 } 101 102 public bool ValidateUser(string userName, string password) { 103 if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName"); 104 if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password"); 105 106 return _provider.ValidateUser(userName, password); 107 } 108 109 public MembershipCreateStatus CreateUser(string userName, string password, string email) { 110 if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName"); 111 if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password"); 112 if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email"); 113 114 MembershipCreateStatus status; 115 _provider.CreateUser(userName, password, email, null, null, true, null, out status); 116 return status; 117 } 118 119 public bool ChangePassword(string userName, string oldPassword, string newPassword) { 120 if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName"); 121 if (String.IsNullOrEmpty(oldPassword)) throw new ArgumentException("Value cannot be null or empty.", "oldPassword"); 122 if (String.IsNullOrEmpty(newPassword)) throw new ArgumentException("Value cannot be null or empty.", "newPassword"); 123 124 // The underlying ChangePassword() will throw an exception rather 125 // than return false in certain failure scenarios. 126 try { 127 MembershipUser currentUser = _provider.GetUser(userName, true /* userIsOnline */); 128 return currentUser.ChangePassword(oldPassword, newPassword); 129 } 130 catch (ArgumentException) { 131 return false; 132 } 133 catch (MembershipPasswordException) { 134 return false; 135 } 136 } 137 } 138 139 public interface IFormsAuthenticationService { 140 void SignIn(string userName, bool createPersistentCookie); 141 void SignOut(); 142 } 143 144 public class FormsAuthenticationService : IFormsAuthenticationService { 145 public void SignIn(string userName, bool createPersistentCookie) { 146 if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName"); 147 148 FormsAuthentication.SetAuthCookie(userName, createPersistentCookie); 149 } 150 151 public void SignOut() { 152 FormsAuthentication.SignOut(); 153 } 154 } 155 #endregion 156 157 #region Validation 158 public static class AccountValidation { 159 public static string ErrorCodeToString(MembershipCreateStatus createStatus) { 160 // See http://go.microsoft.com/fwlink/?LinkID=177550 for 161 // a full list of status codes. 162 switch (createStatus) { 163 case MembershipCreateStatus.DuplicateUserName: 164 return "Username already exists. Please enter a different user name."; 165 166 case MembershipCreateStatus.DuplicateEmail: 167 return "A username for that e-mail address already exists. Please enter a different e-mail address."; 168 169 case MembershipCreateStatus.InvalidPassword: 170 return "The password provided is invalid. Please enter a valid password value."; 171 172 case MembershipCreateStatus.InvalidEmail: 173 return "The e-mail address provided is invalid. Please check the value and try again."; 174 175 case MembershipCreateStatus.InvalidAnswer: 176 return "The password retrieval answer provided is invalid. Please check the value and try again."; 177 178 case MembershipCreateStatus.InvalidQuestion: 179 return "The password retrieval question provided is invalid. Please check the value and try again."; 180 181 case MembershipCreateStatus.InvalidUserName: 182 return "The user name provided is invalid. Please check the value and try again."; 183 184 case MembershipCreateStatus.ProviderError: 185 return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator."; 186 187 case MembershipCreateStatus.UserRejected: 188 return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator."; 189 190 default: 191 return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator."; 192 } 193 } 194 } 195 196 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] 197 public sealed class PropertiesMustMatchAttribute : ValidationAttribute { 198 private const string _defaultErrorMessage = "'{0}' and '{1}' do not match."; 199 private readonly object _typeId = new object(); 200 201 public PropertiesMustMatchAttribute(string originalProperty, string confirmProperty) 202 : base(_defaultErrorMessage) { 203 OriginalProperty = originalProperty; 204 ConfirmProperty = confirmProperty; 205 } 206 207 public string ConfirmProperty { get; private set; } 208 public string OriginalProperty { get; private set; } 209 210 public override object TypeId { 211 get { 212 return _typeId; 213 } 214 } 215 216 public override string FormatErrorMessage(string name) { 217 return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString, 218 OriginalProperty, ConfirmProperty); 219 } 220 221 public override bool IsValid(object value) { 222 PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value); 223 object originalValue = properties.Find(OriginalProperty, true /* ignoreCase */).GetValue(value); 224 object confirmValue = properties.Find(ConfirmProperty, true /* ignoreCase */).GetValue(value); 225 return Object.Equals(originalValue, confirmValue); 226 } 227 } 228 229 [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 230 public sealed class ValidatePasswordLengthAttribute : ValidationAttribute { 231 private const string _defaultErrorMessage = "'{0}' must be at least {1} characters long."; 232 private readonly int _minCharacters = Membership.Provider.MinRequiredPasswordLength; 233 234 public ValidatePasswordLengthAttribute() 235 : base(_defaultErrorMessage) { 236 } 237 238 public override string FormatErrorMessage(string name) { 239 return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString, 240 name, _minCharacters); 241 } 242 243 public override bool IsValid(object value) { 244 string valueAsString = value as string; 245 return (valueAsString != null && valueAsString.Length >= _minCharacters); 246 } 247 } 248 #endregion 249 249 250 250 } -
branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/AdminModel.cs
r6246 r6317 7 7 8 8 namespace HLWebOKBAdminPlugin.Models { 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 if(adminClient != null) {26 27 foreach(AlgorithmClass ac in algorithmClasses) {28 29 30 31 32 33 34 35 36 37 38 39 if(adminClient != null) {40 41 42 43 44 45 46 47 48 49 if(adminClient != null) {50 51 52 53 54 55 56 57 if(adminClient != null) {58 if(algorithmClass.Id == 0) {59 60 61 62 63 if(ac != null) {64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 if(adminClient != null) {81 82 foreach(Algorithm al in algorithm) {83 84 85 86 87 88 89 90 91 92 93 94 if(adminClient != null) {95 96 97 98 99 100 101 102 103 104 if(adminClient != null) {105 106 107 108 109 110 111 112 if(adminClient != null) {113 if(algorithm.Id == 0) {114 115 116 117 118 if(al != null) {119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 if(adminClient != null) {135 136 foreach(ProblemClass pc in problemClasses) {137 138 139 140 141 142 143 144 145 146 147 if(adminClient != null) {148 149 150 151 152 153 154 155 156 157 if(adminClient != null) {158 159 160 161 162 163 164 165 if(adminClient != null) {166 if(problemClass.Id == 0) {167 168 169 170 171 if(pc != null) {172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 if(adminClient != null) {188 189 foreach(Problem pr in problem) {190 191 192 193 194 195 196 197 198 199 200 201 if(adminClient != null) {202 203 204 205 206 207 208 209 210 211 if(adminClient != null) {212 213 214 215 216 217 218 219 if(adminClient != null) {220 if(problem.Id == 0) {221 222 223 224 225 if(pr != null) {226 227 228 229 230 231 232 233 234 235 236 9 public class AdminModel { 10 //member var 11 private IList<AlgorithmClass> algorithmClassList; 12 13 14 public String SelectedSubMenu { get; set; } 15 public IList<AlgorithmClass> AlgorithmClassProp { get { return AlgorithmClassGetAll(); } set { ;} } 16 17 18 //***************************************Algorithm Class******************************************** 19 //get all algorithm classes 20 private IList<AlgorithmClass> AlgorithmClassGetAll() { 21 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 22 23 algorithmClassList = new List<AlgorithmClass>(); 24 25 if (adminClient != null) { 26 AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses(); 27 foreach (AlgorithmClass ac in algorithmClasses) { 28 algorithmClassList.Add(ac); 29 30 } 31 }//if (adminClient != null) 32 33 return algorithmClassList; 34 }//AlgorithmClassGetAll 35 36 private long AddAlgorithmClass(AlgorithmClass algorithmClass) { 37 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 38 39 if (adminClient != null) { 40 return adminClient.AddAlgorithmClass(algorithmClass); 41 } 42 43 return 0; 44 }//AddAlgorithmClass 45 46 public void DeleteAlgorithmClass(long id) { 47 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 48 49 if (adminClient != null) { 50 adminClient.DeleteAlgorithmClass(id); 51 } 52 }//DeleteAlgorithmClass 53 54 public long SaveAlgorithmClass(AlgorithmClass algorithmClass) { 55 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 56 57 if (adminClient != null) { 58 if (algorithmClass.Id == 0) { 59 return AddAlgorithmClass(algorithmClass); 60 } else { 61 AlgorithmClass ac = adminClient.GetAlgorithmClass(algorithmClass.Id); 62 63 if (ac != null) { 64 adminClient.UpdateAlgorithmClass(algorithmClass); 65 return algorithmClass.Id; 66 } 67 } 68 } 69 70 return 0; 71 }//SaveAlgorithmClass 72 73 //***************************************Algorithms************************************************* 74 //get all algorithms 75 public IList<Algorithm> AlgorithmsGetAll() { 76 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 77 78 IList<Algorithm> algorithmList = new List<Algorithm>(); 79 80 if (adminClient != null) { 81 Algorithm[] algorithm = adminClient.GetAlgorithms(); 82 foreach (Algorithm al in algorithm) { 83 algorithmList.Add(al); 84 85 } 86 }//if (adminClient != null) 87 88 return algorithmList; 89 }//AlgorithmsGetAll 90 91 private long AddAlgorithm(Algorithm algorithm) { 92 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 93 94 if (adminClient != null) { 95 return adminClient.AddAlgorithm(algorithm); 96 } 97 98 return 0; 99 }//AddAlgorithm 100 101 public void DeleteAlgorithm(long id) { 102 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 103 104 if (adminClient != null) { 105 adminClient.DeleteAlgorithm(id); 106 } 107 }//DeleteAlgorithm 108 109 public long SaveAlgorithm(Algorithm algorithm) { 110 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 111 112 if (adminClient != null) { 113 if (algorithm.Id == 0) { 114 return AddAlgorithm(algorithm); 115 } else { 116 Algorithm al = adminClient.GetAlgorithm(algorithm.Id); 117 118 if (al != null) { 119 adminClient.UpdateAlgorithm(algorithm); 120 return algorithm.Id; 121 } 122 } 123 } 124 125 return 0; 126 }//SaveAlgorithm 127 128 //***************************************Problem Class********************************************** 129 public IList<ProblemClass> ProblemClassGetAll() { 130 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 131 132 IList<ProblemClass> problemClassList = new List<ProblemClass>(); 133 134 if (adminClient != null) { 135 ProblemClass[] problemClasses = adminClient.GetProblemClasses(); 136 foreach (ProblemClass pc in problemClasses) { 137 problemClassList.Add(pc); 138 } 139 }//if (adminClient != null) 140 141 return problemClassList; 142 }//ProblemClassGetAll 143 144 private long AddProblemClass(ProblemClass problemClass) { 145 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 146 147 if (adminClient != null) { 148 return adminClient.AddProblemClass(problemClass); 149 } 150 151 return 0; 152 }//AddProblemClass 153 154 public void DeleteProblemClass(long id) { 155 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 156 157 if (adminClient != null) { 158 adminClient.DeleteProblemClass(id); 159 } 160 }//DeleteProblemClass 161 162 public long SaveProblemClass(ProblemClass problemClass) { 163 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 164 165 if (adminClient != null) { 166 if (problemClass.Id == 0) { 167 return AddProblemClass(problemClass); 168 } else { 169 ProblemClass pc = adminClient.GetProblemClass(problemClass.Id); 170 171 if (pc != null) { 172 adminClient.UpdateProblemClass(problemClass); 173 return problemClass.Id; 174 } 175 } 176 } 177 178 return 0; 179 }//SaveProblemClass 180 181 //***************************************Problems*************************************************** 182 public IList<Problem> ProblemsGetAll() { 183 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 184 185 IList<Problem> problemList = new List<Problem>(); 186 187 if (adminClient != null) { 188 Problem[] problem = adminClient.GetProblems(); 189 foreach (Problem pr in problem) { 190 problemList.Add(pr); 191 192 } 193 }//if (adminClient != null) 194 195 return problemList; 196 }//ProblemsGetAll 197 198 private long AddProblem(Problem problem) { 199 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 200 201 if (adminClient != null) { 202 return adminClient.AddProblem(problem); 203 } 204 205 return 0; 206 }//AddProblem 207 208 public void DeleteProblem(long id) { 209 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 210 211 if (adminClient != null) { 212 adminClient.DeleteProblem(id); 213 } 214 }//DeleteProblem 215 216 public long SaveProblem(Problem problem) { 217 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 218 219 if (adminClient != null) { 220 if (problem.Id == 0) { 221 return AddProblem(problem); 222 } else { 223 Problem pr = adminClient.GetProblem(problem.Id); 224 225 if (pr != null) { 226 adminClient.UpdateProblem(problem); 227 return problem.Id; 228 } 229 } 230 } 231 232 return 0; 233 }//SaveProblem 234 235 236 } 237 237 } -
branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/AlgorithmClassModel.cs
r6246 r6317 9 9 10 10 namespace HLWebOKBAdminPlugin.Models { 11 public class AlgorithmClassModel {11 public class AlgorithmClassModel { 12 12 13 public String SelectedSubMenu { get; set; } 14 public IList<AlgorithmClass> AlgorithmClasses { 15 get { return AlgorithmClassGetAll(); } 16 set { ;} 13 public String SelectedSubMenu { get; set; } 14 public IList<AlgorithmClass> AlgorithmClasses { 15 get { return AlgorithmClassGetAll(); } 16 set { ;} 17 } 18 19 public AlgorithmClass AlgorithmClass { get; set; } 20 21 public AlgorithmClassModel() { 22 AlgorithmClass = new AlgorithmClass(); 23 }//AlgorithmClassModel 24 25 //***************************************Algorithm Class******************************************** 26 private IList<Platform> PlatformsGetAll() { 27 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 28 29 IList<Platform> platformList = new List<Platform>(); 30 31 if (adminClient != null) { 32 Platform[] platforms = adminClient.GetPlatforms(); 33 foreach (Platform pl in platforms) { 34 platformList.Add(pl); 17 35 } 36 }//if (adminClient != null) 18 37 19 public AlgorithmClass AlgorithmClass { get; set; } 38 return platformList; 39 }//ProblemClassGetAll 20 40 21 public AlgorithmClassModel() { 22 AlgorithmClass = new AlgorithmClass(); 23 }//AlgorithmClassModel 41 private IList<ProblemClass> ProblemClassGetAll() { 42 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 24 43 25 //***************************************Algorithm Class******************************************** 26 private IList<Platform> PlatformsGetAll() { 27 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 44 IList<ProblemClass> problemClassList = new List<ProblemClass>(); 28 45 29 IList<Platform> platformList = new List<Platform>(); 46 if (adminClient != null) { 47 ProblemClass[] problemClasses = adminClient.GetProblemClasses(); 48 foreach (ProblemClass pc in problemClasses) { 49 problemClassList.Add(pc); 50 } 51 }//if (adminClient != null) 30 52 31 if (adminClient != null) { 32 Platform[] platforms = adminClient.GetPlatforms(); 33 foreach (Platform pl in platforms) { 34 platformList.Add(pl); 35 } 36 }//if (adminClient != null) 53 return problemClassList; 54 }//ProblemClassGetAll 37 55 38 return platformList; 39 }//ProblemClassGetAll 56 //get all algorithm classes 57 private IList<AlgorithmClass> AlgorithmClassGetAll() { 58 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 40 59 41 private IList<ProblemClass> ProblemClassGetAll() { 42 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 60 IList<AlgorithmClass> algorithmClassList = new List<AlgorithmClass>(); 43 61 44 IList<ProblemClass> problemClassList = new List<ProblemClass>(); 62 if (adminClient != null) { 63 AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses(); 64 foreach (AlgorithmClass ac in algorithmClasses) { 65 algorithmClassList.Add(ac); 45 66 46 if (adminClient != null) { 47 ProblemClass[] problemClasses = adminClient.GetProblemClasses(); 48 foreach (ProblemClass pc in problemClasses) { 49 problemClassList.Add(pc); 50 } 51 }//if (adminClient != null) 67 } 68 }//if (adminClient != null) 52 69 53 return problemClassList;54 }//ProblemClassGetAll70 return algorithmClassList; 71 }//AlgorithmClassGetAll 55 72 56 //get all algorithm classes 57 private IList<AlgorithmClass> AlgorithmClassGetAll() { 58 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 73 private long AddAlgorithmClass(AlgorithmClass algorithmClass) { 74 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 59 75 60 IList<AlgorithmClass> algorithmClassList = new List<AlgorithmClass>(); 76 if (adminClient != null) { 77 return adminClient.AddAlgorithmClass(algorithmClass); 78 } 61 79 62 if (adminClient != null) { 63 AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses(); 64 foreach (AlgorithmClass ac in algorithmClasses) { 65 algorithmClassList.Add(ac); 80 return 0; 81 }//AddAlgorithmClass 66 82 67 }68 }//if (adminClient != null)83 public void DeleteAlgorithmClass(long id) { 84 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 69 85 70 return algorithmClassList; 71 }//AlgorithmClassGetAll 86 if (adminClient != null) { 87 adminClient.DeleteAlgorithmClass(id); 88 } 89 }//DeleteAlgorithmClass 72 90 73 private long AddAlgorithmClass(AlgorithmClass algorithmClass) {74 91 public long SaveAlgorithmClass(AlgorithmClass algorithmClass) { 92 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 75 93 76 if (adminClient != null) { 77 return adminClient.AddAlgorithmClass(algorithmClass); 78 } 94 if (adminClient != null) { 95 if (algorithmClass.Id == 0) { 96 return AddAlgorithmClass(algorithmClass); 97 } else { 98 AlgorithmClass ac = adminClient.GetAlgorithmClass(algorithmClass.Id); 79 99 80 return 0; 81 }//AddAlgorithmClass 100 if (ac != null) { 101 adminClient.UpdateAlgorithmClass(algorithmClass); 102 return algorithmClass.Id; 103 } 104 } 105 } 82 106 83 public void DeleteAlgorithmClass(long id) { 84 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 85 86 if (adminClient != null) { 87 adminClient.DeleteAlgorithmClass(id); 88 } 89 }//DeleteAlgorithmClass 90 91 public long SaveAlgorithmClass(AlgorithmClass algorithmClass) { 92 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 93 94 if (adminClient != null) { 95 if (algorithmClass.Id == 0) { 96 return AddAlgorithmClass(algorithmClass); 97 } 98 else { 99 AlgorithmClass ac = adminClient.GetAlgorithmClass(algorithmClass.Id); 100 101 if (ac != null) { 102 adminClient.UpdateAlgorithmClass(algorithmClass); 103 return algorithmClass.Id; 104 } 105 } 106 } 107 108 return 0; 109 }//SaveAlgorithmClass 110 } 107 return 0; 108 }//SaveAlgorithmClass 109 } 111 110 } -
branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/PlatformModel.cs
r6310 r6317 7 7 8 8 namespace HLWebOKBAdminPlugin.Models { 9 public class PlatformModel { 10 public String SelectedSubMenu { get; set; } 11 public IList<Platform> Platforms { 12 get { return PlatformGetAll();} 13 set {;} 9 public class PlatformModel { 10 public String SelectedSubMenu { get; set; } 11 public IList<Platform> Platforms { 12 get { return PlatformGetAll(); } 13 set { ;} 14 } 15 16 public Platform Platform { get; set; } 17 18 public PlatformModel() { 19 Platform = new Platform(); 20 }//PlatformModel 21 22 //***************************************Platform Class********************************************** 23 private IList<Platform> PlatformGetAll() { 24 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 25 26 IList<Platform> platformList = new List<Platform>(); 27 28 if (adminClient != null) { 29 Platform[] platforms = adminClient.GetPlatforms(); 30 foreach (Platform pl in platforms) { 31 platformList.Add(pl); 14 32 } 33 }//if (adminClient != null) 15 34 16 public Platform Platform { get; set; } 35 return platformList; 36 }//ProblemClassGetAll 17 37 18 public PlatformModel() { 19 Platform = new Platform(); 20 }//PlatformModel 38 private long AddPlatform(Platform plattform) { 39 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 21 40 22 //***************************************Platform Class**********************************************23 private IList<Platform> PlatformGetAll() {24 AdministrationServiceClient adminClient = Admin.GetClientFactory();41 if (adminClient != null) { 42 return adminClient.AddPlatform(plattform); 43 } 25 44 26 IList<Platform> platformList = new List<Platform>(); 45 return 0; 46 }//AddPlatform 27 47 28 if (adminClient != null) { 29 Platform[] platforms = adminClient.GetPlatforms(); 30 foreach (Platform pl in platforms) { 31 platformList.Add(pl); 32 } 33 }//if (adminClient != null) 48 public void DeletePlatform(long id) { 49 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 34 50 35 return platformList; 36 }//ProblemClassGetAll 51 if (adminClient != null) { 52 adminClient.DeletePlatform(id); 53 } 54 }//DeletePlatform 37 55 38 private long AddPlatform(Platform plattform) {39 56 public long SavePlatform(Platform platform) { 57 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 40 58 41 if (adminClient != null) { 42 return adminClient.AddPlatform(plattform); 43 } 59 if (adminClient != null) { 60 if (platform.Id == 0) { 61 return AddPlatform(platform); 62 } else { 63 Platform pl = adminClient.GetPlatform(platform.Id); 44 64 45 return 0; 46 }//AddPlatform 65 if (pl != null) { 66 adminClient.UpdatePlatform(platform); 67 return platform.Id; 68 } 69 } 70 } 47 71 48 public void DeletePlatform(long id) { 49 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 50 51 if (adminClient != null) { 52 adminClient.DeletePlatform(id); 53 } 54 }//DeletePlatform 55 56 public long SavePlatform(Platform platform) { 57 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 58 59 if (adminClient != null) { 60 if (platform.Id == 0) { 61 return AddPlatform(platform); 62 } 63 else { 64 Platform pl = adminClient.GetPlatform(platform.Id); 65 66 if (pl != null) { 67 adminClient.UpdatePlatform(platform); 68 return platform.Id; 69 } 70 } 71 } 72 73 return 0; 74 }//SavePlatform 75 } 72 return 0; 73 }//SavePlatform 74 } 76 75 } -
branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/ProblemClassModel.cs
r6246 r6317 7 7 8 8 namespace HLWebOKBAdminPlugin.Models { 9 public class ProblemClassModel {9 public class ProblemClassModel { 10 10 11 public String SelectedSubMenu { get; set; } 12 public IList<ProblemClass> ProblemClasses { 13 get { return ProblemClassGetAll();} 14 set {;} 11 public String SelectedSubMenu { get; set; } 12 public IList<ProblemClass> ProblemClasses { 13 get { return ProblemClassGetAll(); } 14 set { ;} 15 } 16 17 public ProblemClass ProblemClass { get; set; } 18 19 public ProblemClassModel() { 20 ProblemClass = new ProblemClass(); 21 }//ProblemClassModel 22 23 //***************************************Problem Class********************************************** 24 private IList<Platform> PlatformsGetAll() { 25 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 26 27 IList<Platform> platformList = new List<Platform>(); 28 29 if (adminClient != null) { 30 Platform[] platforms = adminClient.GetPlatforms(); 31 foreach (Platform pl in platforms) { 32 platformList.Add(pl); 15 33 } 34 }//if (adminClient != null) 16 35 17 public ProblemClass ProblemClass { get; set; } 36 return platformList; 37 }//ProblemClassGetAll 18 38 19 public ProblemClassModel() { 20 ProblemClass = new ProblemClass(); 21 }//ProblemClassModel 39 private IList<ProblemClass> ProblemClassGetAll() { 40 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 22 41 23 //***************************************Problem Class********************************************** 24 private IList<Platform> PlatformsGetAll() { 25 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 42 IList<ProblemClass> problemClassList = new List<ProblemClass>(); 26 43 27 IList<Platform> platformList = new List<Platform>(); 44 if (adminClient != null) { 45 ProblemClass[] problemClasses = adminClient.GetProblemClasses(); 46 foreach (ProblemClass pc in problemClasses) { 47 problemClassList.Add(pc); 48 } 49 }//if (adminClient != null) 28 50 29 if (adminClient != null) { 30 Platform[] platforms = adminClient.GetPlatforms(); 31 foreach (Platform pl in platforms) { 32 platformList.Add(pl); 33 } 34 }//if (adminClient != null) 51 return problemClassList; 52 }//ProblemClassGetAll 35 53 36 return platformList; 37 }//ProblemClassGetAll 38 39 private IList<ProblemClass> ProblemClassGetAll() { 40 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 54 private long AddProblemClass(ProblemClass problemClass) { 55 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 41 56 42 IList<ProblemClass> problemClassList = new List<ProblemClass>(); 57 if (adminClient != null) { 58 return adminClient.AddProblemClass(problemClass); 59 } 43 60 44 if (adminClient != null) { 45 ProblemClass[] problemClasses = adminClient.GetProblemClasses(); 46 foreach (ProblemClass pc in problemClasses) { 47 problemClassList.Add(pc); 48 } 49 }//if (adminClient != null) 61 return 0; 62 }//AddProblemClass 50 63 51 return problemClassList;52 }//ProblemClassGetAll64 public void DeleteProblemClass(long id) { 65 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 53 66 54 private long AddProblemClass(ProblemClass problemClass) { 55 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 67 if (adminClient != null) { 68 adminClient.DeleteProblemClass(id); 69 } 70 }//DeleteProblemClass 56 71 57 if (adminClient != null) { 58 return adminClient.AddProblemClass(problemClass); 59 } 72 public long SaveProblemClass(ProblemClass problemClass) { 73 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 60 74 61 return 0; 62 }//AddProblemClass 75 if (adminClient != null) { 76 if (problemClass.Id == 0) { 77 return AddProblemClass(problemClass); 78 } else { 79 ProblemClass pc = adminClient.GetProblemClass(problemClass.Id); 63 80 64 public void DeleteProblemClass(long id) { 65 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 81 if (pc != null) { 82 adminClient.UpdateProblemClass(problemClass); 83 return problemClass.Id; 84 } 85 } 86 } 66 87 67 if (adminClient != null) { 68 adminClient.DeleteProblemClass(id); 69 } 70 }//DeleteProblemClass 71 72 public long SaveProblemClass(ProblemClass problemClass) { 73 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 74 75 if (adminClient != null) { 76 if (problemClass.Id == 0) { 77 return AddProblemClass(problemClass); 78 } 79 else { 80 ProblemClass pc = adminClient.GetProblemClass(problemClass.Id); 81 82 if (pc != null) { 83 adminClient.UpdateProblemClass(problemClass); 84 return problemClass.Id; 85 } 86 } 87 } 88 89 return 0; 90 }//SaveProblemClass 91 } 88 return 0; 89 }//SaveProblemClass 90 } 92 91 } -
branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/ProblemModel.cs
r6246 r6317 6 6 using HLWebOKBAdminPlugin.Helpers; 7 7 8 namespace HLWebOKBAdminPlugin.Models 9 { 10 public class ProblemModel { 8 namespace HLWebOKBAdminPlugin.Models { 9 public class ProblemModel { 11 10 12 public String SelectedSubMenu { get; set; } 13 public IList<Problem> Problems { 14 get { return ProblemsGetAll(); } 15 set { ;} 11 public String SelectedSubMenu { get; set; } 12 public IList<Problem> Problems { 13 get { return ProblemsGetAll(); } 14 set { ;} 15 } 16 public IList<ProblemClass> ProblemClasses { get { return ProblemClassGetAll(); } } 17 public IList<Platform> Platforms { get { return PlatformsGetAll(); } } 18 19 public Problem Problem { get; set; } 20 21 public ProblemModel() { 22 Problem = new Problem(); 23 }//ProblemModel 24 25 //***************************************Problems*************************************************** 26 private IList<Platform> PlatformsGetAll() { 27 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 28 29 IList<Platform> platformList = new List<Platform>(); 30 31 if (adminClient != null) { 32 Platform[] platforms = adminClient.GetPlatforms(); 33 foreach (Platform pl in platforms) { 34 platformList.Add(pl); 16 35 } 17 public IList<ProblemClass> ProblemClasses { get { return ProblemClassGetAll(); } } 18 public IList<Platform> Platforms { get { return PlatformsGetAll(); } } 36 }//if (adminClient != null) 19 37 20 public Problem Problem { get; set; } 38 return platformList; 39 }//ProblemClassGetAll 21 40 22 public ProblemModel() { 23 Problem = new Problem(); 24 }//ProblemModel 41 private IList<ProblemClass> ProblemClassGetAll() { 42 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 25 43 26 //***************************************Problems*************************************************** 27 private IList<Platform> PlatformsGetAll() { 28 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 44 IList<ProblemClass> problemClassList = new List<ProblemClass>(); 29 45 30 IList<Platform> platformList = new List<Platform>(); 46 if (adminClient != null) { 47 ProblemClass[] problemClasses = adminClient.GetProblemClasses(); 48 foreach (ProblemClass pc in problemClasses) { 49 problemClassList.Add(pc); 50 } 51 }//if (adminClient != null) 31 52 32 if (adminClient != null) { 33 Platform[] platforms = adminClient.GetPlatforms(); 34 foreach (Platform pl in platforms) { 35 platformList.Add(pl); 36 } 37 }//if (adminClient != null) 53 return problemClassList; 54 }//ProblemClassGetAll 38 55 39 return platformList;40 }//ProblemClassGetAll56 private IList<Problem> ProblemsGetAll() { 57 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 41 58 42 private IList<ProblemClass> ProblemClassGetAll() { 43 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 59 IList<Problem> problemList = new List<Problem>(); 44 60 45 IList<ProblemClass> problemClassList = new List<ProblemClass>(); 61 if (adminClient != null) { 62 Problem[] problem = adminClient.GetProblems(); 63 foreach (Problem pr in problem) { 64 problemList.Add(pr); 46 65 47 if (adminClient != null) { 48 ProblemClass[] problemClasses = adminClient.GetProblemClasses(); 49 foreach (ProblemClass pc in problemClasses) { 50 problemClassList.Add(pc); 51 } 52 }//if (adminClient != null) 66 } 67 }//if (adminClient != null) 53 68 54 return problemClassList;55 }//ProblemClassGetAll69 return problemList; 70 }//ProblemsGetAll 56 71 57 private IList<Problem> ProblemsGetAll() {58 72 private long AddProblem(Problem problem) { 73 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 59 74 60 IList<Problem> problemList = new List<Problem>(); 75 if (adminClient != null) { 76 return adminClient.AddProblem(problem); 77 } 61 78 62 if (adminClient != null) { 63 Problem[] problem = adminClient.GetProblems(); 64 foreach (Problem pr in problem) { 65 problemList.Add(pr); 79 return 0; 80 }//AddProblem 66 81 67 }68 }//if (adminClient != null)82 public void DeleteProblem(long id) { 83 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 69 84 70 return problemList; 71 }//ProblemsGetAll 85 if (adminClient != null) { 86 adminClient.DeleteProblem(id); 87 } 88 }//DeleteProblem 72 89 73 private long AddProblem(Problem problem) {74 90 public long SaveProblem(Problem problem) { 91 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 75 92 76 if (adminClient != null) { 77 return adminClient.AddProblem(problem); 78 } 93 if (adminClient != null) { 94 if (problem.Id == 0) { 95 return AddProblem(problem); 96 } else { 97 Problem pr = adminClient.GetProblem(problem.Id); 79 98 80 return 0; 81 }//AddProblem 99 if (pr != null) { 100 adminClient.UpdateProblem(problem); 101 return problem.Id; 102 } 103 } 104 } 82 105 83 public void DeleteProblem(long id) {84 AdministrationServiceClient adminClient = Admin.GetClientFactory();106 return 0; 107 }//SaveProblem 85 108 86 if (adminClient != null) { 87 adminClient.DeleteProblem(id); 88 } 89 }//DeleteProblem 109 public void UpdateProblemData(long id, byte[] data) { 110 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 90 111 91 public long SaveProblem(Problem problem) { 92 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 93 94 if (adminClient != null) { 95 if (problem.Id == 0) { 96 return AddProblem(problem); 97 } 98 else { 99 Problem pr = adminClient.GetProblem(problem.Id); 100 101 if (pr != null) { 102 adminClient.UpdateProblem(problem); 103 return problem.Id; 104 } 105 } 106 } 107 108 return 0; 109 }//SaveProblem 110 111 public void UpdateProblemData(long id, byte[] data) { 112 AdministrationServiceClient adminClient = Admin.GetClientFactory(); 113 114 if (adminClient != null) { 115 adminClient.UpdateProblemData(id, data); 116 } 117 }//UpdateProblemData 118 } 112 if (adminClient != null) { 113 adminClient.UpdateProblemData(id, data); 114 } 115 }//UpdateProblemData 116 } 119 117 }
Note: See TracChangeset
for help on using the changeset viewer.