Example #1
0
        public void BugetRequestValidationPassesSuccessfully()
        {
            request.StartDate = new DateTime(2019, 09, 16);
            request.EndDate   = new DateTime(2020, 05, 20);
            request.Amount    = 1232.6;

            ValidationResult result = validator.Validate(request);

            Assert.Empty(result.Errors);
            Assert.True(result.IsValid);
        }
Example #2
0
        public ActionResult <object> Post([FromBody] BudgetRequest request)
        {
            string loggedUser = User.FindFirstValue("userId");

            if (loggedUser == null)
            {
                return(Unauthorized());
            }

            ValidationResult result = validator.Validate(request);

            if (!result.IsValid)
            {
                return(BadRequest(new ValidationSummary(result)));
            }

            try
            {
                Budget budget = budgetService.CreateBudget(request);

                if (budget == null)
                {
                    return(StatusCode(500));
                }

                return(CreatedAtAction(nameof(Post), null, budget));
            }
            catch (SkrillaApiException e)
            {
                if ("conflict".Equals(e.Code))
                {
                    return(new SkrillaGenericResponse(e.Code, e.Message));
                }
                else
                {
                    return(BadRequest(e.Message));
                }
            }
        }