public ContactModel Create(Contact contact, bool includeSelectableGroup = false) { var result = new ContactModel { FirstName = contact.FirstName, LastName = contact.LastName, Pin = contact.Pin != null ? Convert.ToInt32(contact.Pin): 0, Phones = contact.ContactPhones.Select(c => Create(c)), EmailAddresses = contact.ContactEmails.Select(c => Create(c)), ContactGroupId = contact.ContactGroupId }; if (includeSelectableGroup) { result.SelectableGroups = _repo.GetContactGroupForUser(_identityService.CurrentUser).Select(c => Create(c,false)); } return result; }
public Contact Parse(ContactModel model, string username) { try { var contact = new Contact(); contact.FirstName = model.FirstName; contact.LastName = model.LastName; contact.Pin = model.Pin; contact.ContactPhones = model.Phones.Select(c => Parse(c)).ToList(); contact.ContactEmails = model.EmailAddresses.Select(c => Parse(c)).ToList(); contact.ContactGroup = _repo.GetContactGroup(username, model.ContactGroupId); return contact; } catch (Exception) { return null; } }
public ActionResult Add(ContactModel model,int groupid = 0) { try { // TODO: Add insert logic here var contact = TheModelFactory.Parse(model, TheIdentityService.CurrentUser); if (contact == null) { return RedirectToAction("Index", "Error", new { errorMsg = "Invalid contact data." }); } if (TheRepository.AddContact(TheIdentityService.CurrentUser, contact)) { return RedirectToAction("Index"); } return RedirectToAction("Index", "Error", new { errorMsg = "Error adding new contact." }); } catch (Exception ex) { return RedirectToAction("Index", "Error", new { errorMsg = ex.Message }); } }
public ActionResult Edit(int id, ContactModel model, int groupid = 0) { // TODO: Add update logic here try { var contact = TheModelFactory.Parse(model, TheIdentityService.CurrentUser); if (contact == null) { return RedirectToAction("Index", "Error", new {errorMsg = "Error retrieving contact data"}); } if (TheRepository.EditContact(id, contact)) { return RedirectToAction("Index"); } return RedirectToAction("Index", "Error", new {errorMsg = "Error updating contact"}); } catch (Exception ex) { return RedirectToAction("Index", "Error", new {errorMsg = ex.Message}); } }