Example #1
0
        public async Task <IActionResult> CreateCategory(AdminAccountCategoryViewModel model)
        {
            var acctCtx = await GetAccountContext(model.AccountId);

            if (ModelState.IsValid)
            {
                //Transform ViewModel into Entity Model
                var category = Mapper.Map <ViolationCategory>(model);
                category.CreateUserId = LoggedInUser.Id;
                category.UpdateUserId = LoggedInUser.Id;

                acctCtx.ViolationCategorys.Add(category);

                try
                {
                    await acctCtx.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }

                //Save and redirect to Violation List

                return(RedirectToAction("Categories", new { accountId = model.AccountId }));
            }

            model.Types = await GetViolationTypes(acctCtx, model.AccountId);

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> EditCategory(AdminAccountCategoryViewModel model)
        {
            var acctContext = await GetAccountContext(model.AccountId);

            if (ModelState.IsValid)
            {
                var violation = await acctContext.ViolationCategorys.Where(m => m.AccountId == model.AccountId && m.Id == model.Id).SingleAsync();

                //Transform ViewModel into Entity Model
                Mapper.Map(model, violation);
                violation.UpdateUserId = LoggedInUser.Id;
                violation.UpdateUtc    = DateTime.UtcNow;

                try
                {
                    await acctContext.SaveChangesAsync();

                    return(RedirectToAction("Categories", new { accountId = model.AccountId }));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            model.Types = await GetViolationTypes(acctContext, model.AccountId);

            return(View(model));
        }
Example #3
0
        public async Task <IActionResult> CreateCategory(Guid accountId)
        {
            var vm = new AdminAccountCategoryViewModel {
                AccountId = accountId
            };

            var acctContext = await GetAccountContext(accountId);

            vm.Types = await GetViolationTypes(acctContext, accountId);

            return(View(vm));
        }