private ActionResult AddBudgetReturnEditBudgetView(EditBudgetViewModel vm) { var username = User.Identity.Name; var budget = BudgetService.AddBudget(vm, username); ModelState.Clear(); vm.Id = budget.Id; return(PartialView("EditBudget", vm)); }
public ActionResult Index(string name, string formAction) { var model = new HomeViewModel() { Name = name, ErrorMessage = new List <string>() }; if (formAction != null) { if (formAction.Equals(HomeViewModel.FormActions.CreateNew, StringComparison.OrdinalIgnoreCase)) { //save new budget var errors = new List <string>(); var existing = BudgetService.GetBudgetByName(name); if (existing == null) { var budget = new Budget() { Name = name }; BudgetService.AddBudget(budget); return(RedirectToBudget(budget.BudgetID)); } else { model.ErrorMessage.Add($"Budget {name} already exists, please try again"); } } else if (formAction.Equals(HomeViewModel.FormActions.GetExisting, StringComparison.OrdinalIgnoreCase)) { //redirect to existing budget var budget = BudgetService.GetBudgetByName(name); if (budget != null) { return(RedirectToBudget(budget.BudgetID)); } else { model.ErrorMessage.Add($"Budget '{name}' was not found"); } } else { throw new HttpException(400, "bad request"); } } return(View(model)); }
public async Task <IHttpActionResult> AddBudget(string name, int householdId) { try { return(Ok(await _budgetService.AddBudget(name, householdId))); } catch (Exception ex) { _logService.AddErrorWinEventLog(ex); _securityService.HideErrorTime(); return(StatusCode(HttpStatusCode.InternalServerError)); } }
private ActionResult AddBudgetReturnEditBudgetView(EditBudgetViewModel vm, bool isDone = false) { var username = User.Identity.Name; var budget = BudgetService.AddBudget(vm, username); ModelState.Clear(); vm.Id = budget.Id; if (isDone) { return(RedirectToAction("Index", new { budgetId = budget.Id })); } return(PartialView("EditBudget", vm)); }
public async Task <IActionResult> CreateBudget(Budget budget) { var user = await GetCurrentUser(); budget.AppUserId = user.Id; ViewBag.CategoryList = _expenseCategoryService.GetCategories(user.Id); ViewBag.Years = CalculateYears(); if (!ModelState.IsValid) { return(View(budget)); } if (_budgetService.BudgetExists(budget)) { ModelState.AddModelError("", "A budget has already been created for this month. Consider editing it "); return(View(budget)); } _budgetService.AddBudget(budget); TempData["Message"] = $"Budget for \"{budget?.Category?.Name} category\" was created successfully!"; return(RedirectToAction("Index", new { month = budget?.Month, year = budget?.Year })); }
public void Post([FromBody] Budget budget) => _budgetService.AddBudget(budget);