コード例 #1
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSalesTaxRateRequestModel model)
 {
     this.ModifiedDateRules();
     this.NameRules();
     this.RowguidRules();
     this.StateProvinceIDRules();
     this.TaxRateRules();
     this.TaxTypeRules();
     return(await this.ValidateAsync(model, id));
 }
コード例 #2
0
        private async Task <ApiSalesTaxRateResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiSalesTaxRateRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), 2, 2m, 2);
            CreateResponse <ApiSalesTaxRateResponseModel> result = await client.SalesTaxRateCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
コード例 #3
0
        public virtual async Task <IActionResult> Create([FromBody] ApiSalesTaxRateRequestModel model)
        {
            CreateResponse <ApiSalesTaxRateResponseModel> result = await this.SalesTaxRateService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/SalesTaxRates/{result.Record.SalesTaxRateID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
コード例 #4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiSalesTaxRateModelMapper();
            var model  = new ApiSalesTaxRateResponseModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, 1m, 1);
            ApiSalesTaxRateRequestModel response = mapper.MapResponseToRequest(model);

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.StateProvinceID.Should().Be(1);
            response.TaxRate.Should().Be(1m);
            response.TaxType.Should().Be(1);
        }
コード例 #5
0
        private async Task <ApiSalesTaxRateRequestModel> PatchModel(int id, JsonPatchDocument <ApiSalesTaxRateRequestModel> patch)
        {
            var record = await this.SalesTaxRateService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiSalesTaxRateRequestModel request = this.SalesTaxRateModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
コード例 #6
0
        public virtual async Task <CreateResponse <ApiSalesTaxRateResponseModel> > Create(
            ApiSalesTaxRateRequestModel model)
        {
            CreateResponse <ApiSalesTaxRateResponseModel> response = new CreateResponse <ApiSalesTaxRateResponseModel>(await this.SalesTaxRateModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolSalesTaxRateMapper.MapModelToBO(default(int), model);
                var record = await this.SalesTaxRateRepository.Create(this.DalSalesTaxRateMapper.MapBOToEF(bo));

                response.SetRecord(this.BolSalesTaxRateMapper.MapBOToModel(this.DalSalesTaxRateMapper.MapEFToBO(record)));
            }

            return(response);
        }
コード例 #7
0
        public virtual BOSalesTaxRate MapModelToBO(
            int salesTaxRateID,
            ApiSalesTaxRateRequestModel model
            )
        {
            BOSalesTaxRate boSalesTaxRate = new BOSalesTaxRate();

            boSalesTaxRate.SetProperties(
                salesTaxRateID,
                model.ModifiedDate,
                model.Name,
                model.Rowguid,
                model.StateProvinceID,
                model.TaxRate,
                model.TaxType);
            return(boSalesTaxRate);
        }
コード例 #8
0
        public void CreatePatch()
        {
            var mapper = new ApiSalesTaxRateModelMapper();
            var model  = new ApiSalesTaxRateRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, 1m, 1);

            JsonPatchDocument <ApiSalesTaxRateRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiSalesTaxRateRequestModel();

            patch.ApplyTo(response);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.StateProvinceID.Should().Be(1);
            response.TaxRate.Should().Be(1m);
            response.TaxType.Should().Be(1);
        }
コード例 #9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISalesTaxRateRepository>();
            var model = new ApiSalesTaxRateRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SalesTaxRate>())).Returns(Task.FromResult(new SalesTaxRate()));
            var service = new SalesTaxRateService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.SalesTaxRateModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLSalesTaxRateMapperMock,
                                                  mock.DALMapperMockFactory.DALSalesTaxRateMapperMock);

            CreateResponse <ApiSalesTaxRateResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SalesTaxRateModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSalesTaxRateRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SalesTaxRate>()));
        }
コード例 #10
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ISalesTaxRateRepository>();
            var model = new ApiSalesTaxRateRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SalesTaxRateService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.SalesTaxRateModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLSalesTaxRateMapperMock,
                                                  mock.DALMapperMockFactory.DALSalesTaxRateMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.SalesTaxRateModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
コード例 #11
0
        public virtual async Task <UpdateResponse <ApiSalesTaxRateResponseModel> > Update(
            int salesTaxRateID,
            ApiSalesTaxRateRequestModel model)
        {
            var validationResult = await this.SalesTaxRateModelValidator.ValidateUpdateAsync(salesTaxRateID, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolSalesTaxRateMapper.MapModelToBO(salesTaxRateID, model);
                await this.SalesTaxRateRepository.Update(this.DalSalesTaxRateMapper.MapBOToEF(bo));

                var record = await this.SalesTaxRateRepository.Get(salesTaxRateID);

                return(new UpdateResponse <ApiSalesTaxRateResponseModel>(this.BolSalesTaxRateMapper.MapBOToModel(this.DalSalesTaxRateMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiSalesTaxRateResponseModel>(validationResult));
            }
        }
コード例 #12
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSalesTaxRateRequestModel model)
        {
            ApiSalesTaxRateRequestModel request = await this.PatchModel(id, this.SalesTaxRateModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiSalesTaxRateResponseModel> result = await this.SalesTaxRateService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #13
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiSalesTaxRateRequestModel> patch)
        {
            ApiSalesTaxRateResponseModel record = await this.SalesTaxRateService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiSalesTaxRateRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiSalesTaxRateResponseModel> result = await this.SalesTaxRateService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }