示例#1
0
        public IActionResult Post([FromBody] SaleOpportunityTargetPriceInsertCommandInputDTO 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), nameof(SaleOpportunityTargetPrice), appResult.Bag);
                this.SignalRHubContext.Clients.All.DataChanged(signalArgs);
            }

            return(appResult.IsSucceed ? (IActionResult)this.Ok(appResult) : (IActionResult)this.BadRequest(appResult));
        }
示例#2
0
        public OperationResponse <SaleOpportunityTargetPriceInsertCommandOutputDTO> Execute(SaleOpportunityTargetPriceInsertCommandInputDTO input)
        {
            var result = new OperationResponse <SaleOpportunityTargetPriceInsertCommandOutputDTO>();

            using (var dbContextScope = this.DbContextScopeFactory.Create())
            {
                var entity = new DomainModel.SaleOpportunity.SaleOpportunityTargetPrice
                {
                    Name = input.Name,
                    SaleOpportunityId  = input.SaleOpportunityId,
                    AlternativesAmount = input.AlterenativesAmount,
                    TargetPrice        = input.TargetPrice,
                    SaleSeasonTypeId   = input.SaleSeasonTypeId,
                };

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

                if (result.IsSucceed)
                {
                    //this.Repository.Detach(entity.Id);
                    var getByIdResult = this.Repository.GetById(entity.Id, forceRefresh: true);
                    result.AddResponse(getByIdResult);
                    if (result.IsSucceed)
                    {
                        result.Bag = new SaleOpportunityTargetPriceInsertCommandOutputDTO
                        {
                            Id                 = getByIdResult.Bag.Id,
                            Name               = getByIdResult.Bag.Name,
                            TargetPrice        = getByIdResult.Bag.TargetPrice,
                            SaleSeasonTypeId   = getByIdResult.Bag.SaleSeasonTypeId,
                            SeasonName         = getByIdResult.Bag.SaleSeasonType.Name,
                            AlternativesAmount = getByIdResult.Bag.AlternativesAmount,
                            SaleOpportunityId  = getByIdResult.Bag.SaleOpportunityId,
                        };
                    }
                }
            }

            return(result);
        }