コード例 #1
0
        public async Task <IActionResult> Add(BalanceEntryViewModel model)
        {
            ApplicationUser appUser = await _userManager.GetUserAsync(HttpContext.User);

            User user = _repository.GetUser(Guid.Parse(appUser.Id));

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.Value <= 0)
            {
                ModelState.AddModelError("Value", "Value must be greater than zero");
                return(View(model));
            }

            _repository.AddBalanceEntry(user.Id, user.ActiveGroup.Id, model.Value, model.Message);
            return(RedirectToAction("Index"));
        }