Ejemplo n.º 1
0
        public ActionResult Create(CreateBudgetViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return JsonError("Cannot create new budget - invalid model received!");
            }

            var user = GetCurrentUser();
            if (user == null)
            {
                return JsonError("Error retrieving user");
            }

            var budget = new Budget(user.UserId, model.Name);

            var result = Repository.CreateBudget(budget);
            if (!result)
            {
                return JsonError("Error creating budget in repository");
            }

            if (model.ReturnBudgetList.HasValue && model.ReturnBudgetList.Value)
            {
                var budgets = Repository.GetBudgetsByUser(user.UserId);
                return Json(budgets);
            }

            return Json(new { Message = Messages.Ok });
        }
Ejemplo n.º 2
0
 public ActionResult Create()
 {
     var budget = new Budget()
                      {
                          UserId = CurrentUser.UserId,
                          StartAmount = 0,
                          Name = "New budget",
                          StartDate = DateTime.Now
                      };
     return View(budget);
 }
Ejemplo n.º 3
0
        public ActionResult Edit(Budget budget)
        {
            if (String.IsNullOrEmpty(budget.Name))
            {
                ViewData["ErrorMessage"] = "Please provide a name for the budget";
                return HandleViewRequest(budget.Id, true);
            }

            // TODO: Currently taking us to the url '/in/budget/edit' when we want 'in/budget/view/XXXXX'...

            ViewData["ErrorMessage"] = "All good";
            return HandleViewRequest(budget.Id, false);

            // return RedirectToAction("View", new { id = budget.Id });
        }
Ejemplo n.º 4
0
        public ActionResult Create(Budget budget)
        {
            // Save the budget
            if (budget.UserId == Guid.Empty)
            {
                budget.UserId = CurrentUser.UserId;
            }
            budget.DateCreated = DateTime.Now;

            if (Repository.CreateBudget(budget))
            {
                return RedirectToAction("Index", "Secure");
            }

            ViewData["ErrorMessage"] = "Error saving budget";
            return View(budget);
        }
Ejemplo n.º 5
0
 public bool SetBudget(Budget budget)
 {
     var result = Budgets.Save(budget, SafeMode.True);
     return result != null ? result.Ok : false;
 }
Ejemplo n.º 6
0
 public bool CreateBudget(Budget budget)
 {
     return Budgets.Insert(budget, SafeMode.True).Ok;
 }
Ejemplo n.º 7
0
 public bool SetBudget(Budget budget)
 {
     throw new NotImplementedException();
 }