コード例 #1
0
        public OperationResponse <ProductBridgeInsertCommandOutputDTO> Execute(ProductBridgeInsertCommandInputDTO input)
        {
            var result = new OperationResponse <ProductBridgeInsertCommandOutputDTO>();

            using (var dbContextScope = this.DbContextScopeFactory.Create())
            {
                var entity = new DomainModel.Product.CompositionProductBridge
                {
                    CompositionProductId  = input.ProductId,
                    CompositionItemId     = input.RelatedProductId,
                    ColorTypeId           = input.ColorTypeId,
                    CompositionItemAmount = input.RelatedProductAmount,
                    ProductCategorySizeId = input.RelatedProductSizeId
                };

                try
                {
                    var insertResult = this.Repository.Insert(entity);
                    result.AddResponse(insertResult);
                    if (result.IsSucceed)
                    {
                        dbContextScope.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    result.AddError("Error Adding Product", ex);
                }

                if (result.IsSucceed)
                {
                    //this.Repository.Detach(entity.Id);
                    var getByIdResult = this.Repository.GetById(entity.Id, true);
                    result.AddResponse(getByIdResult);
                    if (result.IsSucceed)
                    {
                        result.Bag = new ProductBridgeInsertCommandOutputDTO
                        {
                            Id                            = getByIdResult.Bag.Id,
                            ProductId                     = getByIdResult.Bag.CompositionProductId,
                            RelatedProductId              = getByIdResult.Bag.CompositionItemId,
                            ColorTypeId                   = getByIdResult.Bag.ColorTypeId,
                            RelatedProductAmount          = getByIdResult.Bag.CompositionItemAmount,
                            RelatedProductSizeId          = getByIdResult.Bag.ProductCategorySizeId,
                            RelatedProductName            = getByIdResult.Bag.CompositionItem.Name,
                            RelatedProductTypeName        = getByIdResult.Bag.CompositionItem.ProductType.Name,
                            RelatedProductTypeDescription = getByIdResult.Bag.CompositionItem.ProductType.Description,
                            RelatedProductPictureId       = getByIdResult.Bag.CompositionItem.ProductMedias.Where(m => m.IsDeleted == null || m.IsDeleted == false).Select(media => media.FileRepositoryId).FirstOrDefault(),
                            RelatedProductTypeId          = getByIdResult.Bag.CompositionItem.ProductTypeId,
                        };
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        public IActionResult Post([FromBody] ProductBridgeInsertCommandInputDTO model)
        {
            var appResult = this.InsertCommand.Execute(model);

            return(appResult.IsSucceed ? (IActionResult)this.Ok(appResult) : (IActionResult)this.BadRequest(appResult));
        }