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); }
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; } }
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; } }
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; } }