// POST: /DataManagement/ItemCategoryList public JsonResult ItemCategoryList() { try { JourListDMContainer dm = new JourListDMContainer(); List<ItemCategoryModel> list = new List<ItemCategoryModel>(); foreach (var a in dm.ItemCategories.Where(z => z.Active == true)) { ItemCategoryModel item = new ItemCategoryModel(); item.Id = a.Id; item.Description = a.Description; item.Active = a.Active; list.Add(item); } return Json(new { Result = "OK", Records = list }); } catch (Exception e) { return Json(new { Result = "ERROR", Message = e.Message }); } }
public JsonResult UpdateItemCategory(ItemCategoryModel model) { try { if (!ModelState.IsValid) { return Json(new { Result = "ERROR", Message = "Form is not valid! " + "Please correct it and try again." }); } if (!User.IsInRole("Officer")) { return Json(new { Result = "ERROR", Message = "You do not have the authority to update this item category." }); } JourListDMContainer dm = new JourListDMContainer(); ItemCategory item = dm.ItemCategories.Single(z => z.Id == model.Id); item.Description = model.Description; item.Active = model.Active; dm.SaveChanges(); return Json(new { Result = "OK" }); } catch (Exception e) { return Json(new { Result = "ERROR", Message = e.Message }); } }
public JsonResult CreateItemCategory(ItemCategoryModel model) { if (!ModelState.IsValid) { return Json(new { Result = "ERROR", Message = "Form is not valid! " + "Please correct it and try again." }); } if (!User.IsInRole("Officer")) { return Json(new { Result = "ERROR", Message = "You do not have the authority to create a new item category." }); } try { JourListDMContainer dm = new JourListDMContainer(); ItemCategory item = new ItemCategory(); item.Description = model.Description; dm.AddToItemCategories(item); dm.SaveChanges(); model.Id = item.Id; return Json(new { Result = "OK", Record = model }); } catch (Exception e) { return Json(new { Result = "ERROR", Message = e.Message }); } }