Exemple #1
0
        public ActionResult Edit(int id, PSUEdit model)
        {
            if (model.PsuId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = new PSUService();

            if (service.UpdatePSU(model))
            {
                TempData["SaveResult"] = "Your PSU information was updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your PSU information could not be updated.");
            return(View());
        }
Exemple #2
0
        // GET: PSU/Edit/5
        public ActionResult Edit(int id)
        {
            var service = new PSUService();
            var detail  = service.GetPSUById(id);
            var model   = new PSUEdit
            {
                PsuId            = detail.PsuId,
                Name             = detail.Name,
                Manufacturer     = detail.Manufacturer,
                Type             = detail.Type,
                EffeciencyRating = detail.EffeciencyRating,
                TypeOfModular    = detail.TypeOfModular,
                Color            = detail.Color,
                Fanless          = detail.Fanless,
                ATXConnectors    = detail.ATXConnectors,
                IsAvailable      = detail.IsAvailable
            };

            return(View(model));
        }
        public bool UpdatePSU(PSUEdit model)
        {
            using (_db)
            {
                var PSUEntity =
                    _db
                    .PowerSupplyUnits
                    .SingleOrDefault(e => e.PsuId == model.PsuId);
                PSUEntity.Name             = model.Name;
                PSUEntity.Manufacturer     = model.Manufacturer;
                PSUEntity.Type             = model.Type;
                PSUEntity.EffeciencyRating = model.EffeciencyRating;
                PSUEntity.TypeOfModular    = model.TypeOfModular;
                PSUEntity.Color            = model.Color;
                PSUEntity.Fanless          = model.Fanless;
                PSUEntity.ATXConnectors    = model.ATXConnectors;
                PSUEntity.IsAvailable      = model.IsAvailable;

                return(_db.SaveChanges() == 1);
            }
        }