Пример #1
0
        public IHttpActionResult Add(BudgetParam param)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int      userId  = UserHelper.GetCurrentUserId();
                    DateTime getDate = DateHelper.GetDateTime();

                    param.CreatedDate = getDate;
                    param.CreatedBy   = userId;

                    int id = _budgetService.Add(param);
                    return(Ok(id));
                }
                else
                {
                    string errorResult = string.Join(" ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
                    return(Content(HttpStatusCode.BadRequest, errorResult));
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    return(Content(HttpStatusCode.InternalServerError, ex.Message));
                }
                else
                {
                    return(Content(HttpStatusCode.InternalServerError, ex.InnerException.Message));
                }
            }
        }
Пример #2
0
        public IActionResult Add([FromBody] BudgetDto model)
        {
            try
            {
                if (model == null || !ModelState.IsValid)
                {
                    return(BadRequest("Invalid State"));
                }

                var result = _budgetService.Add(
                    model.Month,
                    model.Year,
                    model.Name,
                    model.Amount,
                    model.Notes
                    );

                if (result == null)
                {
                    return(BadRequest("Invalid budget data"));
                }

                return(Ok(new BudgetDto(result)));
            }
            catch (Exception)
            {
                return(BadRequest("Error while adding budget"));
            }
        }
Пример #3
0
        public ActionResult Add(string yearMonth, int amount)
        {
            var budget = new BudgetViewModel
            {
                YearMonth = yearMonth,
                Amount    = amount
            };

            _budgetViewModels.Add(budget);
            _budgetService.Add(budget);
            return(View(_budgetViewModels));
        }
        public async Task <ActionResult <UserBudget> > PostUserIncome(UserBudget budget)
        {
            if (Request.Cookies.Keys.Contains("token"))
            {
                this.service.cookie = Request.Cookies["token"];
            }
            else
            {
                this.service.cookie = null;
            }
            await service.Add(budget);

            return(NoContent());
        }
Пример #5
0
        public async Task <ActionResult <UserBudget> > PostUserIncome(UserBudget budget)
        {
            await service.Add(budget);

            return(NoContent());
        }
Пример #6
0
        public int Add(Budget budget)
        {
            int budgetId = budgetService.Add(budget);

            return(budgetId);
        }