Пример #1
0
 public ActionResult AddClass(AddClassModel m)
 {
     if (ModelState.IsValid)
     {
         itemClass newItemClass = new itemClass();
         using (var db = new CopiosisEntities())
         {
             itemClass conflictingItemClass = db.itemClasses.Where(ic => ic.name == m.name).FirstOrDefault();
             if (conflictingItemClass != null)
             {
                 ModelState.AddModelError("name", "There is already a class of this name");
                 return View(m);
             }
             else
             {
                 newItemClass.name = m.name;
                 newItemClass.suggestedGateway = m.suggestedGateway;
                 newItemClass.cPdb = m.cPdb;
                 newItemClass.a = m.a;
                 newItemClass.aMax = m.aMax;
                 newItemClass.d = m.d;
                 newItemClass.aPrime = m.aPrime;
                 newItemClass.cCb = m.cCb;
                 newItemClass.m1 = m.m1;
                 newItemClass.pO = m.pO;
                 newItemClass.m2 = m.m2;
                 newItemClass.cEb = m.cEb;
                 newItemClass.s = m.s;
                 newItemClass.m3 = m.m3;
                 newItemClass.sE = m.sE;
                 newItemClass.m4 = m.m4;
                 newItemClass.sH = m.sH;
                 newItemClass.m5 = m.m5;
                 //save changes
                 db.itemClasses.Add(newItemClass);
                 db.SaveChanges();
                 TempData["AddClass"] = newItemClass.name;
                 return RedirectToAction("ViewClasses");
             }
         }
     }
     else
     {
         return View(m);
     }
 }
Пример #2
0
        public ActionResult EditClass(AddClassModel model, string className)
        {
            if (ModelState.IsValid)
            {
                using (var db = new CopiosisEntities())
                {
                    var currentItemClass = db.itemClasses.Where(p => p.name == className).FirstOrDefault();
                    if (currentItemClass == null)
                    {
                        ADMINERROR.ErrorSubject = "Error while trying to edit an item";
                        throw new ArgumentException(string.Format("ItemClass with Name {0} not found", className));
                    }
                    else
                    {
                        if (model.name.Equals(currentItemClass.name) == false)
                        {
                            itemClass conflictingItemClass = db.itemClasses.Where(ic => ic.name == model.name).FirstOrDefault();
                            if (conflictingItemClass != null)
                            {
                                ModelState.AddModelError("name", "There is already a class of this name");
                                return View(model);
                            }
                        }
                        //Case when the are no changes to the current class
                        else if (model.Equals(currentItemClass) == true)
                        {
                            TempData["NoEdit"] = currentItemClass.name;
                            return RedirectToAction("ViewClasses");
                        }
                        currentItemClass.name = model.name;
                        currentItemClass.suggestedGateway = model.suggestedGateway;
                        currentItemClass.cPdb = model.cPdb;
                        currentItemClass.a = model.a;
                        currentItemClass.aMax = model.aMax;
                        currentItemClass.d = model.d;
                        currentItemClass.aPrime = model.aPrime;
                        currentItemClass.cCb = model.cCb;
                        currentItemClass.m1 = model.m1;
                        currentItemClass.pO = model.pO;
                        currentItemClass.m2 = model.m2;
                        currentItemClass.cEb = model.cEb;
                        currentItemClass.s = model.s;
                        currentItemClass.m3 = model.m3;
                        currentItemClass.sE = model.sE;
                        currentItemClass.m4 = model.m4;
                        currentItemClass.sH = model.sH;
                        currentItemClass.m5 = model.m5;
                        db.SaveChanges();
                        TempData["EditClass"] = currentItemClass.name;
                        return RedirectToAction("ViewClasses");

                    }
                }
            }
            else
            {
                return View(model);
            }
        }
Пример #3
0
 public ActionResult AddClass()
 {
     AddClassModel model = new AddClassModel();
      return View(model);
 }
Пример #4
0
        public ActionResult EditClass(string className)
        {
            AddClassModel model = new AddClassModel();

            using (var db = new CopiosisEntities())
            {
                var currentItemClass = db.itemClasses.Where(p => p.name == className).FirstOrDefault();
                if (currentItemClass == null)
                {
                    ADMINERROR.ErrorSubject = "Error while trying to edit an item";
                    throw new ArgumentException(string.Format("ItemClass with Name {0} not found", className));
                }
                else
                {
                    model.name = currentItemClass.name;
                    model.suggestedGateway = (int)currentItemClass.suggestedGateway;
                    model.cPdb = (float)currentItemClass.cPdb;
                    model.a = (float)currentItemClass.a;
                    model.aMax = (int)currentItemClass.aMax;
                    model.d = (int)currentItemClass.d;
                    model.aPrime = (int)currentItemClass.aPrime;
                    model.cCb = (float)currentItemClass.cCb;
                    model.m1 = (float)currentItemClass.m1;
                    model.pO = (int)currentItemClass.pO;
                    model.m2 = (float)currentItemClass.m2;
                    model.cEb = (float)currentItemClass.cEb;
                    model.s = (int)currentItemClass.s;
                    model.m3 = (float)currentItemClass.m3;
                    model.sE = (short)currentItemClass.sE;
                    model.m4 = (float)currentItemClass.m4;
                    model.sH = (short)currentItemClass.sH;
                    model.m5 = (float)currentItemClass.m5;
                }
            }
            return View(model);
        }