Exemple #1
0
        public ActionResult Edit(int id, ExternalEdit model)
        {
            if (model.Id != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = new ExternalService();

            if (service.UpdateExternal(model))
            {
                TempData["SaveResult"] = "Your External drive information was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your External drive information could not be updated.");
            return(View());
        }
Exemple #2
0
        // GET: External/Edit/5
        public ActionResult Edit(int id)
        {
            var service = new ExternalService();
            var detail  = service.GetExternalById(id);
            var model   = new ExternalEdit
            {
                Id           = detail.Id,
                Name         = detail.Name,
                Manufacturer = detail.Manufacturer,
                Capacity     = detail.Capacity,
                Interface    = detail.Interface,
                Type         = detail.Type,
                Color        = detail.Color,
                IsPortiable  = detail.IsPortiable,
                IsAvailable  = detail.IsAvailable
            };

            return(View(model));
        }
        public bool UpdateExternal(ExternalEdit model)
        {
            using (var _db = new ApplicationDbContext())
            {
                var ExternalEntity =
                    _db
                    .ExternalStorages
                    .SingleOrDefault(e => e.StorageId == model.Id);

                ExternalEntity.StorageId    = model.Id;
                ExternalEntity.Name         = model.Name;
                ExternalEntity.Manufacturer = model.Manufacturer;
                ExternalEntity.Interface    = model.Interface;
                ExternalEntity.Capacity     = model.Capacity;
                ExternalEntity.Type         = model.Type;
                ExternalEntity.Color        = model.Color;
                ExternalEntity.IsPortiable  = model.IsPortiable;
                ExternalEntity.IsAvailable  = model.IsAvailable;
                return(_db.SaveChanges() == 1);
            }
        }