public ActionResult CreateCategory(GLCategoryViewModel generalLedgerCategoryViewModel) { if (!ModelState.IsValid) { var GLCategory = _context.Categories.ToList(); var viewModel = new GLCategoryViewModel { GlCategory = new GLCategory(), Categories = GLCategory }; return(View("GLCategory", viewModel)); } var generalLedgerCategory = new GLCategory { CategoriesId = generalLedgerCategoryViewModel.GlCategory.CategoriesId, Description = generalLedgerCategoryViewModel.GlCategory.Description, Name = generalLedgerCategoryViewModel.GlCategory.Name, Id = generalLedgerCategoryViewModel.GlCategory.Id }; //Mapper.Map(generalLedgerCategoryViewModel, generalLedgerCategory); _context.GlCategories.Add(generalLedgerCategory); _context.SaveChanges(); return(RedirectToAction("Index", "GeneralLedgers")); }
public ActionResult Edit(GLCategoryViewModel model) { if (ModelState.IsValid) { GLCategory glCategory = context.GLCategories.Find(model.Id); glCategory.Name = model.Name; glCategory.Description = model.Description; glCategory.MainCategory = (MainCategory)model.MainCategoryID; context.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
// GET: GeneralLedgers public ActionResult Index() { ViewBag.Message = RoleName.USER_NAME; var categories = _context.Categories.ToList(); var count = _context.GlCategories.Count(); var viewModel = new GLCategoryViewModel { GlCategory = new GLCategory(), Categories = categories, count = count }; if (User.IsInRole(RoleName.ADMIN_ROLE)) { return(View("GLCategory", viewModel)); } return(View("CategoryReadOnly", viewModel)); }
// GET: GLCategory/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GLCategory glCategory = context.GLCategories.Find(id); if (glCategory == null) { return(HttpNotFound()); } GLCategoryViewModel model = new GLCategoryViewModel(); model.Id = glCategory.Id; model.Name = glCategory.Name; model.Description = glCategory.Description; model.MainCategoryID = (int)glCategory.MainCategory; return(View(model)); }