예제 #1
0
        public async Task <IActionResult> AssignMoney(AssignMoneyViewModel model)
        {
            ApplicationUser user = await this.userRepository.FindByNameAsync(this.User.Identity.Name);

            if (model.Amount < 0)
            {
                this.ModelState.AddModelError(string.Empty, "The amount can not be negative");
            }

            if (this.ModelState.IsValid)
            {
                try
                {
                    if (model.Amount != 0)
                    {
                        await this.categoryRepository.AssignMoneyAsync(model.CategoryId, model.Amount, user.Id);
                    }

                    return(this.RedirectToAction("Index"));
                }
                catch (RepositoryException)
                {
                    this.ModelState.AddModelError(string.Empty, "Failed to assign money, an unexpected error occured.");
                }
            }

            model.Categories = await this.categoryRepository.GetAsync(user.Id);

            return(this.View(model));
        }
예제 #2
0
        public async Task <IActionResult> AssignMoney()
        {
            ApplicationUser user = await this.userRepository.FindByNameAsync(this.User.Identity.Name);

            var model = new AssignMoneyViewModel
            {
                Categories = await this.categoryRepository.GetAsync(user.Id)
            };

            return(this.View(model));
        }