public void Should_Success_Validate_Data()
        {
            GarmentSupplierBalanceDebtViewModel nullViewModel = new GarmentSupplierBalanceDebtViewModel
            {
                dOCurrencyRate = 0,
            };

            Assert.True(nullViewModel.Validate(null).Count() > 0);

            GarmentSupplierBalanceDebtViewModel viewModel = new GarmentSupplierBalanceDebtViewModel
            {
                supplier = new SupplierViewModel
                {
                    Id     = 1,
                    Code   = "test",
                    Import = true,
                    Name   = "test"
                },

                items = new List <GarmentSupplierBalanceDebtItemViewModel> {
                }
            };

            Assert.True(viewModel.Validate(null).Count() > 0);
        }
Beispiel #2
0
        public async Task <IActionResult> Post([FromBody] GarmentSupplierBalanceDebtViewModel ViewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

                IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));

                validateService.Validate(ViewModel);

                var model = mapper.Map <GarmentSupplierBalanceDebt>(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));
            }
        }