Exemplo n.º 1
0
 public bool UpdateConsumer(ConsumerEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity =
             ctx
             .Consumers
             .Single(e => e.ConsumerID == model.ConsumerID);
         entity.Name        = model.Name;
         entity.Email       = model.Email;
         entity.Address     = model.Email;
         entity.PhoneNumber = model.PhoneNumber;
         return(ctx.SaveChanges() == 1);
     }
 }
Exemplo n.º 2
0
        public ActionResult ConsumerEdit(int id)
        {
            var svc    = new ConsumerService();
            var detail = svc.GetConsumerByID(id);
            var model  =
                new ConsumerEdit
            {
                ConsumerID  = detail.ConsumerID,
                Name        = detail.Name,
                Email       = detail.Email,
                Address     = detail.Address,
                PhoneNumber = detail.PhoneNumber,
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult ConsumerEdit(int id, ConsumerEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ConsumerID != id)
            {
                ModelState.AddModelError("", "ID Mismatch");
                return(View(model));
            }

            var svc = new ConsumerService();

            if (svc.UpdateConsumer(model))
            {
                TempData["SaveResult"] = "The Consumer was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "The Consumer could not be updated");
            return(View(model));
        }