public async Task<ActionResult> Edit(PeopleContactEdit peopleContactEdit, CancellationToken cancellationToken) { if (!IsAccessEdit(peopleContactEdit)) return RedirectToAccessDenied(); ModelState.Merge(peopleContactEdit.Validate(Db, UserId)); if (ModelState.IsValid) { PeopleContact peopleContact = peopleContactEdit.GetModel(); Calendar calendar = await UserProfileCache.GetCalendar(Db, peopleContact.RegistrarId, this, cancellationToken); PeopleContact previousPeopleContact = PeopleContactCache.GetDetail(Db, peopleContact.PeopleContactId); CheckWorkflow(peopleContact, previousPeopleContact, calendar); bool success = PeopleContactCache.Update(Db, ref peopleContact); if (!success) { return RedirectToAccessDenied(); } return RedirectToAction("Index"); } PopulateRegistrarId(peopleContactEdit.RegistrarId); PopulateDistrictId(peopleContactEdit.DistrictId); PopulatePhoneNumberPrefix1Id(peopleContactEdit.PhoneNumberPrefix1Id); PopulatePhoneNumberPrefix2Id(peopleContactEdit.PhoneNumberPrefix2Id); return View(peopleContactEdit); }
private bool IsAccessEdit(PeopleContactEdit peopleContactEdit) { return peopleContactEdit.RegistrarId == UserId; }
public ActionResult Create(PeopleContactEdit peopleContactEdit) { ModelState.Merge(peopleContactEdit.Validate(Db, UserId)); if (ModelState.IsValid) { PeopleContact peopleContact = peopleContactEdit.GetModel(); PeopleContactCache.Insert(Db, UserId, ref peopleContact); return RedirectToAction("Index"); } PopulateDistrictId(peopleContactEdit.DistrictId); PopulatePhoneNumberPrefix1Id(peopleContactEdit.PhoneNumberPrefix1Id); PopulatePhoneNumberPrefix2Id(peopleContactEdit.PhoneNumberPrefix2Id); return View(peopleContactEdit); }
public static PeopleContactEdit GetModelView(PeopleContact peopleContact) { if (peopleContact == null) return null; var peopleContactEdit = new PeopleContactEdit(peopleContact); return peopleContactEdit; }