Пример #1
0
 /// <summary>
 ///     Validate register code.
 ///     Returns true means validation is correct.
 /// </summary>
 /// <returns></returns>
 public bool RegisterCodeValidate()
 {
     if (!AppVar.Setting.IsRegisterCodeRequiredToRegister)
     {
         _viewMdoel.RegistraterCode = Guid.NewGuid();
         _viewMdoel.Role            = -1;
     }
     else
     {
         var regCode =
             db.RegisterCodes.FirstOrDefault(
                 n =>
                 n.IsUsed == false && n.RoleID == _viewMdoel.Role &&
                 n.RegisterCodeID == _viewMdoel.RegistraterCode && !n.IsExpired);
         if (regCode != null)
         {
             if (regCode.ValidityTill <= DateTime.Now)
             {
                 // not valid
                 regCode.IsExpired = true;
                 ErrorCollector.AddMedium(MessageConstants.RegistercCodeExpired, "", "", "",
                                          MessageConstants.SolutionContactAdmin);
                 db.SaveChanges();
                 return(false);
             }
         }
         else
         {
             ErrorCollector.AddMedium(MessageConstants.RegistercCodeNotValid, "", "", "",
                                      MessageConstants.SolutionContactAdmin);
             return(false);
         }
     }
     return(true);
 }