public ActionResult Create(PersonRelationshipTypeViewModel vm) { if (ModelState.IsValid) { PersonRelationshipType type = new PersonRelationshipType(); type.PersonRelationshipTypeName = vm.PersonRelationshipTypeName; type.IsCommutative = vm.IsCommutative; type.Archive = vm.Archive; type.Notes = vm.Notes; type.Code = vm.PersonRelationshipTypeName.ToUpper().Replace(' ', '_'); type = this.personTasks.SavePersonRelationshipType(type); return(RedirectToAction("Details", new { id = type.Id })); } return(Create()); }
public ActionResult Edit(PersonRelationshipTypeViewModel vm) { PersonRelationshipType type = this.personTasks.GetPersonRelationshipType(vm.Id); IList <PersonRelationshipType> types = this.personTasks.GetPersonRelationshipTypesByName(vm.PersonRelationshipTypeName); if (type != null && types != null && types.Any() && types.Where(x => x.Id != type.Id).Any()) { ModelState.AddModelError("PersonRelationshipTypeName", "Relationship type already exists."); } if (ModelState.IsValid) { type.PersonRelationshipTypeName = vm.PersonRelationshipTypeName; type.IsCommutative = vm.IsCommutative; type.Archive = vm.Archive; type.Notes = vm.Notes; type = this.personTasks.SavePersonRelationshipType(type); return(RedirectToAction("Details", new { id = vm.Id })); } return(Edit(vm.Id)); }