예제 #1
0
 public ActionResult Registry(CreateModel entity)
 {
     if (ModelState.IsValid)
     {
         if (CreateModelBiz.CheckCreateModel(entity))
         {
             if (CreateModelBiz.GetFirst() == null)
             {
                 CreateModelBiz.Add(entity);
             }
             else
             {
                 CreateModelBiz.Edit(entity);
             }
             if (!CreateModelBiz.HasError)
             {
                 SetMessage("注册成功!");
             }
             else
             {
                 ParseBizError(CreateModelBiz);
             }
         }
         else
         {
             SetMessage("验证码不匹配");
         }
     }
     return View(entity);
 }
예제 #2
0
        public CreateModel Edit(CreateModel entity)
        {
            using (var db = new Entities())
            {
                if (db.CreateModel.Any(q => q.CreateUser == entity.CreateUser))
                {
                    var entry = db.Entry(entity);

                    entry.State = EntityState.Unchanged;
                    var regCode = RegistryCodeHelper.GenRegistryCode(entity.CreateUser);
                    if (regCode == entity.CreateModelCode)
                    {
                        entry.Property(q => q.CreateModelCode).IsModified = true;

                        Errors = db.GetErrors();
                        if (!HasError)
                        {
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        Errors.Set("Error", "注册码不匹配");
                    }
                }

                return entity;
            }
        }
예제 #3
0
        public CreateModel Add(CreateModel entity)
        {
            using (var db = new Entities())
            {
                if (db.CreateModel.Any(q => q.CreateUser == entity.CreateUser))
                {
                    return Edit(entity);
                }
                else
                {
                    var regCode = RegistryCodeHelper.GenRegistryCode(entity.CreateUser);
                    if (!string.IsNullOrEmpty(regCode))
                    {
                        if (regCode.ToUpper() == entity.CreateModelCode.ToUpper())
                        {
                            db.CreateModel.Add(entity);

                            Errors = db.GetErrors();

                            if (!HasError)
                            {
                                db.SaveChanges();
                            }
                        }
                        else
                        {
                            Errors.Set("Error", "注册码不匹配");
                        }
                    }
                }
                return entity;
            }
        }
예제 #4
0
 public bool CheckCreateModel(CreateModel model)
 {
     using (var db = new Entities())
     {
         var entity = db.CreateModel.FirstOrDefault(q => q.CreateUser.ToUpper() == model.CreateUser.ToUpper());
         if (null != entity)
         {
             var regCode = RegistryCodeHelper.GenRegistryCode(model.CreateUser);
             return regCode.Equals(model.CreateModelCode);
         }
         return true;
     }
 }