コード例 #1
0
        public async Task <IActionResult> Post([FromBody] GarmentShippingCreditNoteViewModel viewModel)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(viewModel);
                var result = await _service.Create(viewModel);

                return(Created("/", result));
            }
            catch (ServiceValidationException ex)
            {
                var Result = new
                {
                    error      = ResultFormatter.Fail(ex),
                    apiVersion = "1.0.0",
                    statusCode = HttpStatusCode.BadRequest,
                    message    = "Data does not pass validation"
                };

                return(new BadRequestObjectResult(Result));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
コード例 #2
0
        public void Validate_DefaultValue()
        {
            GarmentShippingCreditNoteViewModel viewModel = new GarmentShippingCreditNoteViewModel();

            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }
コード例 #3
0
        public void Validate_ItemsDefaultValue()
        {
            GarmentShippingCreditNoteViewModel viewModel = new GarmentShippingCreditNoteViewModel();

            viewModel.items = new List <GarmentShippingNoteItemViewModel>
            {
                new GarmentShippingNoteItemViewModel()
            };

            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }
コード例 #4
0
        public void Validate_EmptyValue()
        {
            GarmentShippingCreditNoteViewModel viewModel = new GarmentShippingCreditNoteViewModel
            {
                date  = DateTimeOffset.MinValue,
                buyer = new Buyer {
                    Id = 0
                }
            };

            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }