public async Task <IActionResult> Post([FromBody] GarmentReceiptCorrectionViewModel ViewModel) { try { identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; identityService.TimezoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService)); validateService.Validate(ViewModel); var model = mapper.Map <GarmentReceiptCorrection>(ViewModel); await facade.Create(model, identityService.Username); Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationExeption 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 void Should_Success_Validate_Data_Null_Items() { GarmentReceiptCorrectionViewModel viewModel = new GarmentReceiptCorrectionViewModel { CorrectionType = "Harga Satuan", URNNo = "test", }; Assert.True(viewModel.Validate(null).Count() > 0); }
public void Should_Success_Validate_Data_Retur() { GarmentReceiptCorrectionViewModel viewModel = new GarmentReceiptCorrectionViewModel { CorrectionType = "Jumlah", URNNo = "test", CorrectionDate = DateTimeOffset.Now, CorrectionNo = "test", Remark = It.IsAny <string>(), Unit = It.IsAny <UnitViewModel>(), Storage = It.IsAny <Lib.ViewModels.IntegrationViewModel.StorageViewModel>(), URNId = It.IsAny <long>(), Items = new List <GarmentReceiptCorrectionItemViewModel> { new GarmentReceiptCorrectionItemViewModel { QuantityCheck = 100, Quantity = 0, CorrectionQuantity = 0, Conversion = It.IsAny <double>(), CorrectionConversion = It.IsAny <double>(), DODetailId = It.IsAny <long>(), EPOItemId = It.IsAny <long>(), FabricType = It.IsAny <string>(), IsSave = true, PRItemId = It.IsAny <long>(), RONo = It.IsAny <string>(), POItemId = It.IsAny <long>(), DesignColor = It.IsAny <string>(), PricePerDealUnit = It.IsAny <double>(), POSerialNumber = It.IsAny <string>(), SmallQuantity = It.IsAny <double>(), URNItemId = It.IsAny <long>(), SmallUomId = It.IsAny <long>(), UomId = It.IsAny <long>(), UomUnit = It.IsAny <string>(), SmallUomUnit = It.IsAny <string>(), ProductRemark = It.IsAny <string>(), Product = It.IsAny <ProductViewModel>(), OrderQuantity = It.IsAny <double>(), }, } }; Assert.True(viewModel.Validate(null).Count() > 0); GarmentReceiptCorrectionViewModel viewModel2 = new GarmentReceiptCorrectionViewModel { CorrectionType = "Konversi", URNNo = "test", Items = new List <GarmentReceiptCorrectionItemViewModel> { new GarmentReceiptCorrectionItemViewModel { QuantityCheck = 100, Quantity = 500, CorrectionQuantity = 0, CorrectionConversion = 0, IsSave = true, OrderQuantity = 200 }, } }; Assert.True(viewModel2.Validate(null).Count() > 0); GarmentReceiptCorrectionViewModel viewModel3 = new GarmentReceiptCorrectionViewModel { CorrectionType = "Jumlah", URNNo = "test", Items = new List <GarmentReceiptCorrectionItemViewModel> { new GarmentReceiptCorrectionItemViewModel { QuantityCheck = 100, Quantity = 500, CorrectionQuantity = -200, IsSave = true, }, } }; Assert.True(viewModel3.Validate(null).Count() > 0); GarmentReceiptCorrectionViewModel viewModel4 = new GarmentReceiptCorrectionViewModel { CorrectionType = "Konversi", URNNo = "test", Items = new List <GarmentReceiptCorrectionItemViewModel> { new GarmentReceiptCorrectionItemViewModel { QuantityCheck = 100, Quantity = 500, CorrectionQuantity = 0, CorrectionConversion = 1, IsSave = true, OrderQuantity = 1000 }, } }; Assert.True(viewModel4.Validate(null).Count() > 0); }
public void Should_Success_Validate_Data() { GarmentReceiptCorrectionViewModel AllNullViewModel = new GarmentReceiptCorrectionViewModel(); Assert.True(AllNullViewModel.Validate(null).Count() > 0); }