public virtual BOProduct MapModelToBO(
            int productID,
            ApiProductRequestModel model
            )
        {
            BOProduct boProduct = new BOProduct();

            boProduct.SetProperties(
                productID,
                model.@Class,
                model.Color,
                model.DaysToManufacture,
                model.DiscontinuedDate,
                model.FinishedGoodsFlag,
                model.ListPrice,
                model.MakeFlag,
                model.ModifiedDate,
                model.Name,
                model.ProductLine,
                model.ProductModelID,
                model.ProductNumber,
                model.ProductSubcategoryID,
                model.ReorderPoint,
                model.Rowguid,
                model.SafetyStockLevel,
                model.SellEndDate,
                model.SellStartDate,
                model.Size,
                model.SizeUnitMeasureCode,
                model.StandardCost,
                model.Style,
                model.Weight,
                model.WeightUnitMeasureCode);
            return(boProduct);
        }
		public async Task<ValidationResult> ValidateUpdateAsync(int id, ApiProductRequestModel model)
		{
			this.@ClassRules();
			this.ColorRules();
			this.DaysToManufactureRules();
			this.DiscontinuedDateRules();
			this.FinishedGoodsFlagRules();
			this.ListPriceRules();
			this.MakeFlagRules();
			this.ModifiedDateRules();
			this.NameRules();
			this.ProductLineRules();
			this.ProductModelIDRules();
			this.ProductNumberRules();
			this.ProductSubcategoryIDRules();
			this.ReorderPointRules();
			this.RowguidRules();
			this.SafetyStockLevelRules();
			this.SellEndDateRules();
			this.SellStartDateRules();
			this.SizeRules();
			this.SizeUnitMeasureCodeRules();
			this.StandardCostRules();
			this.StyleRules();
			this.WeightRules();
			this.WeightUnitMeasureCodeRules();
			return await this.ValidateAsync(model, id);
		}
Exemple #3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiProductModelMapper();
            var model  = new ApiProductResponseModel();

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

            [email protected]().Be("A");
            response.Color.Should().Be("A");
            response.DaysToManufacture.Should().Be(1);
            response.DiscontinuedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FinishedGoodsFlag.Should().Be(true);
            response.ListPrice.Should().Be(1m);
            response.MakeFlag.Should().Be(true);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.ProductLine.Should().Be("A");
            response.ProductModelID.Should().Be(1);
            response.ProductNumber.Should().Be("A");
            response.ProductSubcategoryID.Should().Be(1);
            response.ReorderPoint.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.SafetyStockLevel.Should().Be(1);
            response.SellEndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.SellStartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Size.Should().Be("A");
            response.SizeUnitMeasureCode.Should().Be("A");
            response.StandardCost.Should().Be(1m);
            response.Style.Should().Be("A");
            response.Weight.Should().Be(1);
            response.WeightUnitMeasureCode.Should().Be("A");
        }
Exemple #4
0
        private async Task <ApiProductResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiProductRequestModel();

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

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

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Products/{result.Record.ProductID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        private async Task <ApiProductRequestModel> PatchModel(int id, JsonPatchDocument <ApiProductRequestModel> patch)
        {
            var record = await this.ProductService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiProductRequestModel request = this.ProductModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Exemple #7
0
        public virtual async Task <CreateResponse <ApiProductResponseModel> > Create(
            ApiProductRequestModel model)
        {
            CreateResponse <ApiProductResponseModel> response = new CreateResponse <ApiProductResponseModel>(await this.productModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolProductMapper.MapModelToBO(default(int), model);
                var record = await this.productRepository.Create(this.dalProductMapper.MapBOToEF(bo));

                response.SetRecord(this.bolProductMapper.MapBOToModel(this.dalProductMapper.MapEFToBO(record)));
            }

            return(response);
        }
Exemple #8
0
        public virtual async Task <UpdateResponse <ApiProductResponseModel> > Update(
            int productID,
            ApiProductRequestModel model)
        {
            var validationResult = await this.productModelValidator.ValidateUpdateAsync(productID, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolProductMapper.MapModelToBO(productID, model);
                await this.productRepository.Update(this.dalProductMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiProductResponseModel>(this.bolProductMapper.MapBOToModel(this.dalProductMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiProductResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiProductRequestModel model)
        {
            ApiProductRequestModel request = await this.PatchModel(id, this.ProductModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiProductResponseModel> result = await this.ProductService.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 <ApiProductRequestModel> patch)
        {
            ApiProductResponseModel record = await this.ProductService.Get(id);

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

                UpdateResponse <ApiProductResponseModel> result = await this.ProductService.Update(id, model);

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