public ActionResult Edit(int id)
        {
            // var service = new ConsoleService();
            var detail = _consoleService.GetConsoleById(id);
            var model  = new ConsoleEdit()
            {
                ConsoleId   = detail.Id,
                Name        = detail.Name,
                Description = detail.Description,
                Brand       = detail.Brand,
                Price       = detail.Price,
                ReleaseDate = detail.ReleaseDate
            };

            return(View(model));
        }
 public ActionResult Edit(int id, ConsoleEdit model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (model.ConsoleId != id)
     {
         ModelState.AddModelError("", "Id Mismatch");
         return(View(model));
     }
     // var service = new ConsoleService();
     if (_consoleService.UpdateConsole(model))
     {
         TempData["SaveResult"] = "The console was updated.";
         return(RedirectToAction("Index"));
     }
     ModelState.AddModelError("", "Console could not be updated.");
     return(View(model));
 }
Beispiel #3
0
 public bool UpdateConsole(ConsoleEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         try
         {
             var entity = ctx.Consoles.Single(e => e.Id == model.ConsoleId);
             entity.Name        = model.Name;
             entity.Description = model.Description;
             entity.Brand       = model.Brand;
             entity.Price       = model.Price;
             entity.ReleaseDate = model.ReleaseDate;
             entity.ModifiedUtc = DateTimeOffset.Now;
             return(ctx.SaveChanges() >= 1);
         }
         catch (Exception e)
         {
             Debug.Print("Exception thrown while looking for console");
             Debug.Print(e.Message);
             return(false);
         }
     }
 }