public ActionResult Create(GLCategory glCategory) { if (ModelState.IsValid) { try { using (ISession session = NHibernateHelper.Session) { using (ITransaction transaction = session.BeginTransaction()) { glCategory.DateAdded = DateTime.Now; glCategory.DateUpdated = DateTime.Now; session.Save(glCategory); transaction.Commit(); } } return(RedirectToAction("Index")); } catch (Exception exception) { } } ViewBag.GlCategoryTypes = Enum.GetValues(typeof(GLCategoryType)); return(View(glCategory)); }
public async static Task SeedBankVaultAsync(ApplicationDbContext context) { if (!context.GLCategories.Any(category => category.Name.ToLower() == "cash assets")) { var cashAssets = new GLCategory { Name = "CASH ASSETS", Type = AccountType.Assets, IsEnabled = true, Description = "GL Category for Cash Assets Accounts" }; context.Add(cashAssets); await context.SaveChangesAsync(); } GLCategory category = await context.GLCategories.SingleOrDefaultAsync(c => c.Name.ToLower() == "cash assets"); if (!context.InternalAccounts.Any(account => account.AccountCode == "10000000000000")) { var vault = new InternalAccount { AccountName = "Vault", AccountBalance = 100000000, AccountCode = "10000000000000", IsActivated = true, GLCategory = category }; context.Add(vault); await context.SaveChangesAsync(); } }
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 DeleteConfirmed(int id) { GLCategory gLCategory = context.GLCategories.Find(id); context.GLCategories.Remove(gLCategory); context.SaveChanges(); return(RedirectToAction("Index")); }
public async Task AddGLCategoryAsync(GLCategory category) { if (await _context.GLCategories.AnyAsync(c => c.Name.ToLower() == category.Name)) { throw new Exception("A Category with this name already exists"); } _context.Add(category); await _context.SaveChangesAsync(); }
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: GLCategory/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GLCategory gLCategory = context.GLCategories.Find(id); if (gLCategory == null) { return(HttpNotFound()); } return(View(gLCategory)); }
public HttpResponseMessage CreateCategory(GLCategoryDto glCategoryDto) { ValidateCategory(glCategoryDto); if (!errorMessage.Equals("")) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } var generalLedgerCategory = new GLCategory { CategoriesId = glCategoryDto.CategoriesId, Description = glCategoryDto.Description, Name = glCategoryDto.Name, }; //Mapper.Map(generalLedgerCategoryViewModel, generalLedgerCategory); _context.GlCategories.Add(generalLedgerCategory); _context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Category Created Successfully")); }
public async Task <IActionResult> Create([Bind("Type,Name,IsEnabled,Description")] GLCategory gLCategory) { if (ModelState.IsValid) { try { await _gLCategoryService.AddGLCategoryAsync(gLCategory); } catch (Exception ex) { ViewBag.Message = new StatusMessage { Type = StatusType.Error, Message = ex.Message }; return(View(gLCategory)); } return(RedirectToAction(nameof(Index))); } return(View(gLCategory)); }
public ActionResult Edit(int id, GLCategory category) { if (ModelState.IsValid) { try { var glRepository = new Repository <GLCategory>(); var OldEntity = glRepository.GetById(id); category.DateAdded = OldEntity.DateAdded; category.DateUpdated = DateTime.Now; glRepository.Update(category, category.Id); return(RedirectToAction("Index")); } catch (Exception exception) { ViewBag.Exception = exception; } } ViewBag.GlCategoryTypes = Enum.GetValues(typeof(GLCategoryType)); return(View(category)); }
// 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)); }
public async Task <IActionResult> Edit(int id, [Bind("GLCategoryId,Name,IsEnabled,Description")] GLCategory gLCategory) { if (id != gLCategory.GLCategoryId) { return(NotFound()); } if (ModelState.IsValid) { try { await _gLCategoryService.EditGLCategoryAsync(gLCategory); } catch (DbUpdateConcurrencyException) { if (!await _gLCategoryService.GLCategoryExists(gLCategory.GLCategoryId)) { return(NotFound()); } else { throw; } } catch (Exception ex) { ViewBag.Message = new StatusMessage { Type = StatusType.Error, Message = ex.Message }; return(View(gLCategory)); } return(RedirectToAction(nameof(Index))); } return(View(gLCategory)); }
public async Task EditGLCategoryAsync(GLCategory category) { _context.Update(category); await _context.SaveChangesAsync(); }