Ejemplo n.º 1
0
        public ActionResult Edit()
        {
            UnitOfWork    unit         = new UnitOfWork();
            PhonesService phoneService = new PhonesService(unit);
            PhoneEditVM   model        = new PhoneEditVM();

            TryUpdateModel(model);
            Phone p;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.ID != 0)
            {
                p = phoneService.GetByID(model.ID);
            }
            else
            {
                p = new Phone();
            }


            Mapper.Map(model, p);

            phoneService.Save(p);
            return(this.RedirectToAction(c => c.List(), new { contactID = model.ContactID }));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int?id)
        {
            PhonesService phonesService = new PhonesService();
            PhoneEditVM   model         = new PhoneEditVM();

            TryUpdateModel(model);

            Phone phone;

            if (!id.HasValue)
            {
                phone = new Phone();
            }
            else
            {
                phone = phonesService.GetByID(id.Value);
                if (phone == null)
                {
                    if (phonesService.GetContact(model.ContactID) == null)
                    {
                        return(this.RedirectToAction <ContactsController>(c => c.List()));
                    }

                    return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID }));
                }
                model.ContactID = phone.ContactID;
            }

            Mapper.Map(model, phone);

            return(View(model));
        }