Пример #1
0
        public ActionResult DeleteContactPersonConfirmed(int id, DeleteContactPersonViewModel model)
        {
            try
            {
                ContactPerson cp = contactRepo.FindById(id);
                if (cp == null)
                {
                    TempData["error"] = "There was e problem deleting the contact person. Please contact the IT department.";
                    RedirectToAction("Index");
                }

                //Changing the contactperson to a new one before deleting it.
                ContactPerson newContact = contactRepo.FindById(model.SelectedContactId);
                cp.Hotels.ToList().ForEach(t =>
                {
                    t.ContactPerson = newContact;
                });

                contactRepo.RemoveContactPerson(cp);
                contactRepo.SaveChanges();
                TempData["message"] = String.Format("The contact {0} is succesfully deleted", cp.LastName + cp.FirstName);
                RedirectToAction("Index");
            }catch (Exception ex)
            {
                TempData["error"] = "There was a problem deleting the contact person. Please contact the IT department.";
            }

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult DeleteContactPerson(int id)
        {
            ContactPerson cp = contactRepo.FindById(id);

            if (cp == null)
            {
                TempData["error"] = "There was a problem finding the contact person.";
                return(RedirectToAction("Index"));
            }
            List <ContactPerson> list = contactRepo.FindAll().Where(t => t.Email != cp.Email).OrderBy(t => t.LastName).ToList();

            if (list.Count() > 0)
            {
                DeleteContactPersonViewModel dcpvm = new DeleteContactPersonViewModel(cp)
                {
                    SelectedContactId = list.FirstOrDefault().ContactPersonId,
                    List = list.Select(t => new SelectListItem
                    {
                        Value = t.ContactPersonId.ToString(),
                        Text  = t.LastName + " " + t.FirstName
                    })
                };

                return(View(dcpvm));
            }
            else
            {
                DeleteContactPersonViewModel dcpvm = new DeleteContactPersonViewModel(cp)
                {
                    SelectedContactId = 0,
                    List = new List <SelectListItem>()
                };

                return(View(dcpvm));
            }
        }