public async Task <ValidationResult> ValidateCreateAsync(ApiProductInventoryRequestModel model)
 {
     this.BinRules();
     this.LocationIDRules();
     this.ModifiedDateRules();
     this.QuantityRules();
     this.RowguidRules();
     this.ShelfRules();
     return(await this.ValidateAsync(model));
 }
        private async Task <ApiProductInventoryResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiProductInventoryRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiProductInventoryRequestModel model)
        {
            CreateResponse <ApiProductInventoryResponseModel> result = await this.ProductInventoryService.Create(model);

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

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

            response.Bin.Should().Be(1);
            response.LocationID.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Quantity.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.Shelf.Should().Be("A");
        }
        private async Task <ApiProductInventoryRequestModel> PatchModel(int id, JsonPatchDocument <ApiProductInventoryRequestModel> patch)
        {
            var record = await this.ProductInventoryService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiProductInventoryRequestModel request = this.ProductInventoryModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiProductInventoryResponseModel> > Create(
            ApiProductInventoryRequestModel model)
        {
            CreateResponse <ApiProductInventoryResponseModel> response = new CreateResponse <ApiProductInventoryResponseModel>(await this.productInventoryModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolProductInventoryMapper.MapModelToBO(default(int), model);
                var record = await this.productInventoryRepository.Create(this.dalProductInventoryMapper.MapBOToEF(bo));

                response.SetRecord(this.bolProductInventoryMapper.MapBOToModel(this.dalProductInventoryMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public virtual BOProductInventory MapModelToBO(
            int productID,
            ApiProductInventoryRequestModel model
            )
        {
            BOProductInventory boProductInventory = new BOProductInventory();

            boProductInventory.SetProperties(
                productID,
                model.Bin,
                model.LocationID,
                model.ModifiedDate,
                model.Quantity,
                model.Rowguid,
                model.Shelf);
            return(boProductInventory);
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IProductInventoryRepository>();
            var model = new ApiProductInventoryRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductInventory>())).Returns(Task.FromResult(new ProductInventory()));
            var service = new ProductInventoryService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.ProductInventoryModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLProductInventoryMapperMock,
                                                      mock.DALMapperMockFactory.DALProductInventoryMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ProductInventoryModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductInventoryRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductInventory>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IProductInventoryRepository>();
            var model = new ApiProductInventoryRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new ProductInventoryService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.ProductInventoryModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLProductInventoryMapperMock,
                                                      mock.DALMapperMockFactory.DALProductInventoryMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.ProductInventoryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public void CreatePatch()
        {
            var mapper = new ApiProductInventoryModelMapper();
            var model  = new ApiProductInventoryRequestModel();

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

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

            patch.ApplyTo(response);
            response.Bin.Should().Be(1);
            response.LocationID.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Quantity.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.Shelf.Should().Be("A");
        }
        public virtual async Task <UpdateResponse <ApiProductInventoryResponseModel> > Update(
            int productID,
            ApiProductInventoryRequestModel model)
        {
            var validationResult = await this.productInventoryModelValidator.ValidateUpdateAsync(productID, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolProductInventoryMapper.MapModelToBO(productID, model);
                await this.productInventoryRepository.Update(this.dalProductInventoryMapper.MapBOToEF(bo));

                var record = await this.productInventoryRepository.Get(productID);

                return(new UpdateResponse <ApiProductInventoryResponseModel>(this.bolProductInventoryMapper.MapBOToModel(this.dalProductInventoryMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiProductInventoryResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiProductInventoryRequestModel model)
        {
            ApiProductInventoryRequestModel request = await this.PatchModel(id, this.ProductInventoryModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiProductInventoryRequestModel> patch)
        {
            ApiProductInventoryResponseModel record = await this.ProductInventoryService.Get(id);

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

                UpdateResponse <ApiProductInventoryResponseModel> result = await this.ProductInventoryService.Update(id, model);

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