Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            SetForeignKeysToNull(id);
            OPSystem oPSystem = db.OperatingSystems.Find(id);

            db.OperatingSystems.Remove(oPSystem);
            db.SaveChanges();
            TempData["OPSystemStatusMessage"] = "Operating system has been deleted successfully!";
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        // GET: OPSystems/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OPSystem oPSystem = db.OperatingSystems.Find(id);

            if (oPSystem == null)
            {
                return(HttpNotFound());
            }
            return(View(oPSystem));
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "OPSystemId,OpSystemName,Description")] OPSystem oPSystem)
 {
     if (ModelState.IsValid)
     {
         if (CanUpdateOPSystem(oPSystem))
         {
             db.Entry(oPSystem).State = EntityState.Modified;
             db.SaveChanges();
             TempData["OPSystemStatusMessage"] = "Operating system has been updated successfully!";
             return(RedirectToAction("Index"));
         }
         DisplayOPSystemExistsMessage(oPSystem);
     }
     return(View(oPSystem));
 }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "OPSystemId,OpSystemName,Description")] OPSystem oPSystem)
        {
            if (ModelState.IsValid)
            {
                if (CanAddOPSystem(oPSystem.OpSystemName))
                {
                    db.OperatingSystems.Add(oPSystem);
                    db.SaveChanges();
                    TempData["OPSystemStatusMessage"] = "Operating system has been added successfully!";
                    return(RedirectToAction("Index"));
                }
                DisplayOPSystemExistsMessage(oPSystem);
            }

            return(View(oPSystem));
        }
Ejemplo n.º 5
0
 private void DisplayOPSystemExistsMessage(OPSystem o)
 {
     ModelState.AddModelError("OpSystemName", $"Model {o.OpSystemName} already exists please choose another name.");
 }
Ejemplo n.º 6
0
        private bool CanUpdateOPSystem(OPSystem opS)
        {
            var query = db.OperatingSystems.Where(o => o.OPSystemId != opS.OPSystemId).Any(o => o.OpSystemName == opS.OpSystemName);

            return(!query);
        }