Exemplo n.º 1
0
        public IActionResult Post([FromBody] ProductCategoryInsertCommandInputDTO model)
        {
            var appResult = this.InsertCommand.Execute(model);

            if (appResult.IsSucceed)
            {
                var signalArgs = new SignalREventArgs(SignalREvents.DATA_CHANGED.Identifier, nameof(SignalREvents.DATA_CHANGED.ActionEnum.ADDED_ITEM), "FlowerProductCategory", appResult.Bag);
                this.SignalRHubContext.Clients.All.DataChanged(signalArgs);
            }
            return(appResult.IsSucceed ? (IActionResult)this.Ok(appResult) : (IActionResult)this.BadRequest(appResult));
        }
Exemplo n.º 2
0
        public OperationResponse <ProductCategoryInsertCommandOutputDTO> Execute(ProductCategoryInsertCommandInputDTO input)
        {
            var result = new OperationResponse <ProductCategoryInsertCommandOutputDTO>();

            using (var dbContextScope = this.DbContextScopeFactory.Create())
            {
                var entity = new DomainModel.Product.ProductCategory
                {
                    Identifier = input.Identifier,
                    Name       = input.Name,
                };


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

                if (result.IsSucceed)
                {
                    var getByIdResult = this.Repository.GetById(entity.Id);
                    result.AddResponse(getByIdResult);
                    if (result.IsSucceed)
                    {
                        result.Bag = new ProductCategoryInsertCommandOutputDTO
                        {
                            Id         = getByIdResult.Bag.Id,
                            Identifier = getByIdResult.Bag.Identifier,
                            Name       = getByIdResult.Bag.Name
                        };
                    }
                }
            }

            return(result);
        }