public void SaveLocation(Locations location) { var errors = new NameValueCollection(); errors.Add(GetRuleViolations.checkRequire("Name", "지역명", location.Name)); errors.Add(GetRuleViolations.checkBetween("Name", "부서명", location.Name, 2, 30)); errors.Add(GetRuleViolations.checkRequire("AreaCode", "지역번호", location.AreaCode)); errors.Add(GetRuleViolations.checkBetween("AreaCode", "지역번호", location.AreaCode, 1, 10)); if (errors.Count > 0) throw new RuleException(errors); location.Name = location.Name.Trim().ToUpper(); if(location.LocationID == "") { location.LocationID = GenerateRandomCode.create_5(); context.Locations.Add(location); } else { context.Entry(location).State = EntityState.Modified; } context.SaveChanges(); }
public ActionResult edit(Locations location) { if(ModelState.IsValid) { try { repository.SaveLocation(location); } catch(RuleException ex) { ex.CopyToModelState(ModelState); } } if(ModelState.IsValid) { return RedirectToAction("list"); } return View(); }