Пример #1
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));
     }
 }
Пример #2
0
        public ActionResult ChangeUserIsAdmin(string roleAction, string userName)
        {
            using (var db = new CopiosisEntities())
            {
                var user  = db.users.Where(p => p.username == userName).FirstOrDefault();
                var roles = db.webpages_Roles.Where(r => r.RoleName == "ADMIN").FirstOrDefault();

                if (user == null)
                {
                    throw new ArgumentException(string.Format("No user found with that username: {0}", userName));
                }

                if (user.userID == WebSecurity.CurrentUserId)
                {
                    throw new ArgumentException(string.Format("Sorry, you can't demote yourself!: {0}", userName));
                }

                if (roles == null)
                {
                    throw new ArgumentException(string.Format("The role: {0} does not exist", "ADMIN"));
                }


                //we are adding
                if (roleAction.ToLower() == "promote")
                {
                    if (!roles.users.Contains(user))
                    {
                        roles.users.Add(user);
                    }
                }
                else
                {
                    if (roles.users.Contains(user))
                    {
                        roles.users.Remove(user);
                    }
                    else
                    {
                        throw new ArgumentException(string.Format("{0} is not currently an admin.", user.username));
                    }
                }
                db.SaveChanges();
            }
            return(Json(new { success = true }));
        }
Пример #3
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));
     }
 }
Пример #4
0
        public ActionResult ChangeClass(string newClass, Guid itemGuid)
        {
            using (var db = new CopiosisEntities())
            {
                var item    = db.products.Where(p => p.guid == itemGuid).FirstOrDefault();
                var classID = db.itemClasses.Where(ic => ic.name == newClass).Select(ic => ic.classID).FirstOrDefault();
                ADMINERROR.ErrorSubject = "Error while trying to change an item's class";
                if (item == null)
                {
                    throw new ArgumentException(string.Format("No product found with GUID: {0}", itemGuid));
                }
                if (classID == null)
                {
                    throw new ArgumentException(string.Format("No matching item class with name: {0}", itemGuid));
                }

                item.itemClass = classID;
                db.SaveChanges();
            }
            return(Json(new { success = true }));
        }