public async Task <IActionResult> Post([FromBody] GarmentShippingVBPaymentViewModel 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)); } }
public void Validate_ItemsEmptyValue() { GarmentShippingVBPaymentViewModel viewModel = new GarmentShippingVBPaymentViewModel(); viewModel.invoices = new List <GarmentShippingVBPaymentInvoiceViewModel> { new GarmentShippingVBPaymentInvoiceViewModel { invoiceId = 0, } }; viewModel.units = new List <GarmentShippingVBPaymentUnitViewModel> { new GarmentShippingVBPaymentUnitViewModel { unit = new Unit { Id = 0, }, billValue = 0 } }; var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }
public void Validate_DefaultValue() { GarmentShippingVBPaymentViewModel viewModel = new GarmentShippingVBPaymentViewModel(); var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }
public void Validate_EmptyValue() { GarmentShippingVBPaymentViewModel viewModel = new GarmentShippingVBPaymentViewModel { paymentType = "EMKL", emkl = new EMKL { Id = 0 }, buyer = new Buyer { Id = 0 } }; var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); GarmentShippingVBPaymentViewModel viewModel2 = new GarmentShippingVBPaymentViewModel { paymentType = "Forwarder", forwarder = new Forwarder { id = 0 }, buyer = new Buyer { Id = 0 }, incomeTax = new IncomeTax { id = 0 } }; var result2 = viewModel2.Validate(null); Assert.NotEmpty(result2.ToList()); GarmentShippingVBPaymentViewModel viewModel3 = new GarmentShippingVBPaymentViewModel { paymentType = "EMKL", buyer = new Buyer { Id = 0 } }; var result3 = viewModel3.Validate(null); Assert.NotEmpty(result3.ToList()); }
public void Validate_ItemsDefaultValue() { GarmentShippingVBPaymentViewModel viewModel = new GarmentShippingVBPaymentViewModel(); viewModel.units = new List <GarmentShippingVBPaymentUnitViewModel> { new GarmentShippingVBPaymentUnitViewModel() }; viewModel.invoices = new List <GarmentShippingVBPaymentInvoiceViewModel> { new GarmentShippingVBPaymentInvoiceViewModel() }; var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }