public async Task <ActionResult> Post([FromBody] GarmentInvoicePaymentViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); GarmentInvoicePaymentModel model = Mapper.Map <GarmentInvoicePaymentModel>(viewModel); await Service.CreateAsync(model); Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] GarmentInvoicePaymentViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); GarmentInvoicePaymentModel model = Mapper.Map <GarmentInvoicePaymentModel>(viewModel); await Service.UpdateAsync(id, model); return(NoContent()); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public async Task <IActionResult> GetById([FromRoute] int id) { try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); var model = await Service.ReadByIdAsync(id); GarmentInvoicePaymentViewModel viewModel = Mapper.Map <GarmentInvoicePaymentViewModel>(model); if (model == null) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.NOT_FOUND_STATUS_CODE, General.NOT_FOUND_MESSAGE) .Fail(); return(NotFound(Result)); } return(Ok(new { apiVersion = ApiVersion, data = viewModel, message = General.OK_MESSAGE, statusCode = General.OK_STATUS_CODE })); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public void Should_Success_Validate_Null_Invoice_Data() { GarmentInvoicePaymentViewModel vm = new GarmentInvoicePaymentViewModel(); vm.Items = new List <GarmentInvoicePaymentItemViewModel> { new GarmentInvoicePaymentItemViewModel() { InvoiceId = 0, InvoiceNo = " " } }; Assert.True(vm.Validate(null).Count() > 0); }
public void Should_Success_Validate_All_Null_Data() { GarmentInvoicePaymentViewModel vm = new GarmentInvoicePaymentViewModel(); Assert.True(vm.Validate(null).Count() > 0); }