public IActionResult EditSubItemType(SubItemType ItemType, int mid)
        {
            ViewBag.User = HasAccess();
            if (ViewBag.User == null)
            {
                return(RedirectToAction("Index", "Home", new { area = "Account" }));
            }
            SubItemType original = context.GetOneSubItemType(mid);

            if (original == null)
            {
                TempData["AdminMessage"] = $"Sub Item Type with the requested id {mid} not found!";
                return(RedirectToAction("AllSubItemTypes"));
            }

            ViewBag.SubItemType = original;
            if (ModelState.IsValid)
            {
                SubItemType existing = context.GetOneSubItemType(ItemType.Name);
                if (existing != null && existing.SubItemTypeId != mid)
                {
                    ViewBag.NameError = "A Sub Item Type with that name already exists!";
                    return(View("EditSubItemType"));
                }
                original.Name        = ItemType.Name;
                original.Description = ItemType.Description;
                context.SaveChanges();
                TempData["AdminMessage"] = $"Sub Item Type #{mid} successfully edited!";
                return(RedirectToAction("AllSubItemTypes"));
            }
            return(View());
        }
 public bool ValidateSubItemTypes(List <string> stringIds, List <int> intIds, out string errorMessage)
 {
     errorMessage = "";
     if (stringIds.Count == 0)
     {
         errorMessage = "Please specify at least one Sub Item Type for the item.";
         return(false);
     }
     else
     {
         foreach (string stringId in stringIds)
         {
             int intId = -1;
             if (!Int32.TryParse(stringId, out intId))
             {
                 errorMessage = "At least one of the given Sub Item Type Ids couldn't be parsed.";
                 return(false);
             }
             SubItemType existingSubType = context.GetOneSubItemType(intId);
             if (existingSubType == null)
             {
                 errorMessage = "At least one of the given Sub Item Type Ids didn't match any Sub Item Type in the database.";
                 return(false);
             }
             intIds.Add(intId);
         }
     }
     return(true);
 }
 public IActionResult CreateSubItemType(SubItemType NewType)
 {
     ViewBag.User = HasAccess();
     if (ViewBag.User == null)
     {
         return(RedirectToAction("Index", "Home", new { area = "Account" }));
     }
     if (ModelState.IsValid)
     {
         SubItemType existing = context.GetOneSubItemType(NewType.Name);
         if (existing != null && existing.SubItemTypeId != NewType.SubItemTypeId)
         {
             ViewBag.NameError = "A Sub Item Type with that name already exists!";
             return(View("NewSubItemType"));
         }
         context.Add(NewType);
         context.SaveChanges();
         TempData["AdminMessage"] = $"{NewType.Name} successfully added to the database!";
         return(RedirectToAction("AllSubItemTypes"));
     }
     return(View("NewSubItemType"));
 }