public OperationResponse <SampleBoxUpdateCommandOutputDTO> Execute(SampleBoxUpdateCommandInputDTO input)
        {
            var result = new OperationResponse <SampleBoxUpdateCommandOutputDTO>();

            using (var dbContextScope = this.DbContextScopeFactory.Create())
            {
                var getByIdResult = this.Repository.GetById(input.Id);
                result.AddResponse(getByIdResult);
                if (result.IsSucceed)
                {
                    getByIdResult.Bag.Name = input.Name;

                    try
                    {
                        dbContextScope.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        result.AddError("Error updating Sample Box", ex);
                    }

                    getByIdResult = this.Repository.GetById(input.Id);
                    result.AddResponse(getByIdResult);
                    if (result.IsSucceed)
                    {
                        result.Bag = new SampleBoxUpdateCommandOutputDTO
                        {
                            Id    = getByIdResult.Bag.Id,
                            Name  = getByIdResult.Bag.Name,
                            Order = getByIdResult.Bag.Order,
                        };
                    }
                }
            }

            return(result);
        }
Пример #2
0
        public IActionResult Put([FromBody] SampleBoxUpdateCommandInputDTO model)
        {
            var appResult = this.UpdateCommand.Execute(model);

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