Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        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 });
            }
        }
Ejemplo n.º 4
0
        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});
            }
        }