Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/27/11 19:09:49 (14 years ago)
Author:
jwolfing
Message:

#1433 code formatted

Location:
branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/AccountModels.cs

    r4985 r6317  
    1111namespace HLWebServiceTestPlugin.Models {
    1212
    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
     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
    249249
    250250}
  • branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/AdminModel.cs

    r6246 r6317  
    77
    88namespace HLWebOKBAdminPlugin.Models {
    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     }
     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  }
    237237}
  • branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/AlgorithmClassModel.cs

    r6246 r6317  
    99
    1010namespace HLWebOKBAdminPlugin.Models {
    11     public class AlgorithmClassModel {       
     11  public class AlgorithmClassModel {
    1212
    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);
    1735        }
     36      }//if (adminClient != null)
    1837
    19         public AlgorithmClass AlgorithmClass { get; set; }
     38      return platformList;
     39    }//ProblemClassGetAll
    2040
    21         public AlgorithmClassModel() {
    22             AlgorithmClass = new AlgorithmClass();
    23         }//AlgorithmClassModel
     41    private IList<ProblemClass> ProblemClassGetAll() {
     42      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    2443
    25         //***************************************Algorithm Class********************************************
    26         private IList<Platform> PlatformsGetAll() {
    27             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     44      IList<ProblemClass> problemClassList = new List<ProblemClass>();
    2845
    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)
    3052
    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
    3755
    38             return platformList;
    39         }//ProblemClassGetAll
     56    //get all algorithm classes
     57    private IList<AlgorithmClass> AlgorithmClassGetAll() {
     58      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    4059
    41         private IList<ProblemClass> ProblemClassGetAll() {
    42             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     60      IList<AlgorithmClass> algorithmClassList = new List<AlgorithmClass>();
    4361
    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);
    4566
    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)
    5269
    53             return problemClassList;
    54         }//ProblemClassGetAll
     70      return algorithmClassList;
     71    }//AlgorithmClassGetAll
    5572
    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();
    5975
    60             IList<AlgorithmClass>  algorithmClassList = new List<AlgorithmClass>();
     76      if (adminClient != null) {
     77        return adminClient.AddAlgorithmClass(algorithmClass);
     78      }
    6179
    62             if (adminClient != null) {
    63                 AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses();
    64                 foreach (AlgorithmClass ac in algorithmClasses) {
    65                     algorithmClassList.Add(ac);
     80      return 0;
     81    }//AddAlgorithmClass
    6682
    67                 }
    68             }//if (adminClient != null)
     83    public void DeleteAlgorithmClass(long id) {
     84      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    6985
    70             return algorithmClassList;
    71         }//AlgorithmClassGetAll
     86      if (adminClient != null) {
     87        adminClient.DeleteAlgorithmClass(id);
     88      }
     89    }//DeleteAlgorithmClass
    7290
    73         private long AddAlgorithmClass(AlgorithmClass algorithmClass) {
    74             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     91    public long SaveAlgorithmClass(AlgorithmClass algorithmClass) {
     92      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    7593
    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);
    7999
    80             return 0;
    81         }//AddAlgorithmClass
     100          if (ac != null) {
     101            adminClient.UpdateAlgorithmClass(algorithmClass);
     102            return algorithmClass.Id;
     103          }
     104        }
     105      }
    82106
    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  }
    111110}
  • branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/PlatformModel.cs

    r6310 r6317  
    77
    88namespace 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);
    1432        }
     33      }//if (adminClient != null)
    1534
    16         public Platform Platform { get; set; }
     35      return platformList;
     36    }//ProblemClassGetAll               
    1737
    18         public PlatformModel() {
    19             Platform = new Platform();
    20         }//PlatformModel
     38    private long AddPlatform(Platform plattform) {
     39      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    2140
    22         //***************************************Platform Class**********************************************
    23         private IList<Platform> PlatformGetAll() {
    24             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     41      if (adminClient != null) {
     42        return adminClient.AddPlatform(plattform);
     43      }
    2544
    26             IList<Platform> platformList = new List<Platform>();
     45      return 0;
     46    }//AddPlatform
    2747
    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();
    3450
    35             return platformList;
    36         }//ProblemClassGetAll               
     51      if (adminClient != null) {
     52        adminClient.DeletePlatform(id);
     53      }
     54    }//DeletePlatform
    3755
    38         private long AddPlatform(Platform plattform) {
    39             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     56    public long SavePlatform(Platform platform) {
     57      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    4058
    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);
    4464
    45             return 0;
    46         }//AddPlatform
     65          if (pl != null) {
     66            adminClient.UpdatePlatform(platform);
     67            return platform.Id;
     68          }
     69        }
     70      }
    4771
    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  }
    7675}
  • branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/ProblemClassModel.cs

    r6246 r6317  
    77
    88namespace HLWebOKBAdminPlugin.Models {
    9     public class ProblemClassModel {       
     9  public class ProblemClassModel {
    1010
    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);
    1533        }
     34      }//if (adminClient != null)
    1635
    17         public ProblemClass ProblemClass { get; set; }
     36      return platformList;
     37    }//ProblemClassGetAll
    1838
    19         public ProblemClassModel() {
    20             ProblemClass = new ProblemClass();
    21         }//ProblemClassModel
     39    private IList<ProblemClass> ProblemClassGetAll() {
     40      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    2241
    23         //***************************************Problem Class**********************************************
    24         private IList<Platform> PlatformsGetAll() {
    25             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     42      IList<ProblemClass> problemClassList = new List<ProblemClass>();
    2643
    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)
    2850
    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
    3553
    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();
    4156
    42             IList<ProblemClass> problemClassList = new List<ProblemClass>();
     57      if (adminClient != null) {
     58        return adminClient.AddProblemClass(problemClass);
     59      }
    4360
    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
    5063
    51             return problemClassList;
    52         }//ProblemClassGetAll
     64    public void DeleteProblemClass(long id) {
     65      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    5366
    54         private long AddProblemClass(ProblemClass problemClass) {
    55             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     67      if (adminClient != null) {
     68        adminClient.DeleteProblemClass(id);
     69      }
     70    }//DeleteProblemClass
    5671
    57             if (adminClient != null) {
    58                 return adminClient.AddProblemClass(problemClass);
    59             }
     72    public long SaveProblemClass(ProblemClass problemClass) {
     73      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    6074
    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);
    6380
    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      }
    6687
    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  }
    9291}
  • branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/ProblemModel.cs

    r6246 r6317  
    66using HLWebOKBAdminPlugin.Helpers;
    77
    8 namespace HLWebOKBAdminPlugin.Models
    9 {
    10     public class ProblemModel {
     8namespace HLWebOKBAdminPlugin.Models {
     9  public class ProblemModel {
    1110
    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);
    1635        }
    17         public IList<ProblemClass> ProblemClasses { get { return ProblemClassGetAll(); } }
    18         public IList<Platform> Platforms { get { return PlatformsGetAll(); } }
     36      }//if (adminClient != null)
    1937
    20         public Problem Problem { get; set; }
     38      return platformList;
     39    }//ProblemClassGetAll
    2140
    22         public ProblemModel() {
    23             Problem = new Problem();
    24         }//ProblemModel
     41    private IList<ProblemClass> ProblemClassGetAll() {
     42      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    2543
    26         //***************************************Problems***************************************************
    27         private IList<Platform> PlatformsGetAll() {
    28             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     44      IList<ProblemClass> problemClassList = new List<ProblemClass>();
    2945
    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)
    3152
    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
    3855
    39             return platformList;
    40         }//ProblemClassGetAll
     56    private IList<Problem> ProblemsGetAll() {
     57      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    4158
    42         private IList<ProblemClass> ProblemClassGetAll() {
    43             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     59      IList<Problem> problemList = new List<Problem>();
    4460
    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);
    4665
    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)
    5368
    54             return problemClassList;
    55         }//ProblemClassGetAll
     69      return problemList;
     70    }//ProblemsGetAll
    5671
    57         private IList<Problem> ProblemsGetAll() {
    58             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     72    private long AddProblem(Problem problem) {
     73      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    5974
    60             IList<Problem> problemList = new List<Problem>();
     75      if (adminClient != null) {
     76        return adminClient.AddProblem(problem);
     77      }
    6178
    62             if (adminClient != null) {
    63                 Problem[] problem = adminClient.GetProblems();
    64                 foreach (Problem pr in problem) {
    65                     problemList.Add(pr);
     79      return 0;
     80    }//AddProblem
    6681
    67                 }
    68             }//if (adminClient != null)
     82    public void DeleteProblem(long id) {
     83      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    6984
    70             return problemList;
    71         }//ProblemsGetAll
     85      if (adminClient != null) {
     86        adminClient.DeleteProblem(id);
     87      }
     88    }//DeleteProblem
    7289
    73         private long AddProblem(Problem problem) {
    74             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     90    public long SaveProblem(Problem problem) {
     91      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    7592
    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);
    7998
    80             return 0;
    81         }//AddProblem
     99          if (pr != null) {
     100            adminClient.UpdateProblem(problem);
     101            return problem.Id;
     102          }
     103        }
     104      }
    82105
    83         public void DeleteProblem(long id) {
    84             AdministrationServiceClient adminClient = Admin.GetClientFactory();
     106      return 0;
     107    }//SaveProblem
    85108
    86             if (adminClient != null) {
    87                 adminClient.DeleteProblem(id);
    88             }
    89         }//DeleteProblem
     109    public void UpdateProblemData(long id, byte[] data) {
     110      AdministrationServiceClient adminClient = Admin.GetClientFactory();
    90111
    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  }
    119117}
Note: See TracChangeset for help on using the changeset viewer.