public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiProductSubcategoryRequestModel model)
 {
     this.ModifiedDateRules();
     this.NameRules();
     this.ProductCategoryIDRules();
     this.RowguidRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiProductSubcategoryResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiProductSubcategoryRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Example #3
0
        public virtual async Task <IActionResult> Create([FromBody] ApiProductSubcategoryRequestModel model)
        {
            CreateResponse <ApiProductSubcategoryResponseModel> result = await this.ProductSubcategoryService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ProductSubcategories/{result.Record.ProductSubcategoryID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void MapModelToBO()
        {
            var mapper = new BOLProductSubcategoryMapper();
            ApiProductSubcategoryRequestModel model = new ApiProductSubcategoryRequestModel();

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

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.ProductCategoryID.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
Example #5
0
        private async Task <ApiProductSubcategoryRequestModel> PatchModel(int id, JsonPatchDocument <ApiProductSubcategoryRequestModel> patch)
        {
            var record = await this.ProductSubcategoryService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiProductSubcategoryRequestModel request = this.ProductSubcategoryModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Example #6
0
        public virtual BOProductSubcategory MapModelToBO(
            int productSubcategoryID,
            ApiProductSubcategoryRequestModel model
            )
        {
            BOProductSubcategory boProductSubcategory = new BOProductSubcategory();

            boProductSubcategory.SetProperties(
                productSubcategoryID,
                model.ModifiedDate,
                model.Name,
                model.ProductCategoryID,
                model.Rowguid);
            return(boProductSubcategory);
        }
        public virtual async Task <CreateResponse <ApiProductSubcategoryResponseModel> > Create(
            ApiProductSubcategoryRequestModel model)
        {
            CreateResponse <ApiProductSubcategoryResponseModel> response = new CreateResponse <ApiProductSubcategoryResponseModel>(await this.ProductSubcategoryModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolProductSubcategoryMapper.MapModelToBO(default(int), model);
                var record = await this.ProductSubcategoryRepository.Create(this.DalProductSubcategoryMapper.MapBOToEF(bo));

                response.SetRecord(this.BolProductSubcategoryMapper.MapBOToModel(this.DalProductSubcategoryMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public void CreatePatch()
        {
            var mapper = new ApiProductSubcategoryModelMapper();
            var model  = new ApiProductSubcategoryRequestModel();

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

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

            patch.ApplyTo(response);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.ProductCategoryID.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
        public virtual async Task <UpdateResponse <ApiProductSubcategoryResponseModel> > Update(
            int productSubcategoryID,
            ApiProductSubcategoryRequestModel model)
        {
            var validationResult = await this.ProductSubcategoryModelValidator.ValidateUpdateAsync(productSubcategoryID, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolProductSubcategoryMapper.MapModelToBO(productSubcategoryID, model);
                await this.ProductSubcategoryRepository.Update(this.DalProductSubcategoryMapper.MapBOToEF(bo));

                var record = await this.ProductSubcategoryRepository.Get(productSubcategoryID);

                return(new UpdateResponse <ApiProductSubcategoryResponseModel>(this.BolProductSubcategoryMapper.MapBOToModel(this.DalProductSubcategoryMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiProductSubcategoryResponseModel>(validationResult));
            }
        }
Example #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IProductSubcategoryRepository>();
            var model = new ApiProductSubcategoryRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductSubcategory>())).Returns(Task.FromResult(new ProductSubcategory()));
            var service = new ProductSubcategoryService(mock.LoggerMock.Object,
                                                        mock.RepositoryMock.Object,
                                                        mock.ModelValidatorMockFactory.ProductSubcategoryModelValidatorMock.Object,
                                                        mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock,
                                                        mock.DALMapperMockFactory.DALProductSubcategoryMapperMock,
                                                        mock.BOLMapperMockFactory.BOLProductMapperMock,
                                                        mock.DALMapperMockFactory.DALProductMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ProductSubcategoryModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductSubcategoryRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductSubcategory>()));
        }
Example #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IProductSubcategoryRepository>();
            var model = new ApiProductSubcategoryRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new ProductSubcategoryService(mock.LoggerMock.Object,
                                                        mock.RepositoryMock.Object,
                                                        mock.ModelValidatorMockFactory.ProductSubcategoryModelValidatorMock.Object,
                                                        mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock,
                                                        mock.DALMapperMockFactory.DALProductSubcategoryMapperMock,
                                                        mock.BOLMapperMockFactory.BOLProductMapperMock,
                                                        mock.DALMapperMockFactory.DALProductMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.ProductSubcategoryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Example #12
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiProductSubcategoryRequestModel model)
        {
            ApiProductSubcategoryRequestModel request = await this.PatchModel(id, this.ProductSubcategoryModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #13
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiProductSubcategoryRequestModel> patch)
        {
            ApiProductSubcategoryResponseModel record = await this.ProductSubcategoryService.Get(id);

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

                UpdateResponse <ApiProductSubcategoryResponseModel> result = await this.ProductSubcategoryService.Update(id, model);

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