Example #1
0
        public OperationResponse <CustomerFreightoutUpdateCommandOutputDTO> Execute(CustomerFreightoutUpdateCommandInputDTO input)
        {
            var result = new OperationResponse <CustomerFreightoutUpdateCommandOutputDTO>();

            using (var dbContextScope = this.DbContextScopeFactory.Create())
            {
                var getByIdResult = this.Repository.GetById(input.Id);
                result.AddResponse(getByIdResult);
                if (result.IsSucceed)
                {
                    getByIdResult.Bag.Cost = input.Cost;
                    getByIdResult.Bag.CustomerFreightoutRateTypeId = input.CustomerFreightoutRateTypeId;
                    getByIdResult.Bag.CustomerId      = input.CustomerId;
                    getByIdResult.Bag.DateFrom        = input.DateFrom;
                    getByIdResult.Bag.DateTo          = input.DateTo;
                    getByIdResult.Bag.SecondLeg       = input.SecondLeg;
                    getByIdResult.Bag.SurchargeHourly = input.SurchargeHourly;
                    getByIdResult.Bag.SurchargeYearly = input.SurchargeYearly;
                    getByIdResult.Bag.WProtect        = input.WProtect;

                    try
                    {
                        dbContextScope.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        result.AddError("Error updating Product Color Type", ex);
                    }

                    getByIdResult = this.Repository.GetById(input.Id);
                    result.AddResponse(getByIdResult);
                    if (result.IsSucceed)
                    {
                        result.Bag = new CustomerFreightoutUpdateCommandOutputDTO
                        {
                            Id           = getByIdResult.Bag.Id,
                            CustomerId   = getByIdResult.Bag.CustomerId,
                            CustomerName = getByIdResult.Bag.Customer.Name,
                            Cost         = getByIdResult.Bag.Cost,
                            CustomerFreightoutRateTypeId = getByIdResult.Bag.CustomerFreightoutRateTypeId,
                            DateFrom        = getByIdResult.Bag.DateFrom,
                            DateTo          = getByIdResult.Bag.DateTo,
                            SecondLeg       = getByIdResult.Bag.SecondLeg,
                            SurchargeHourly = getByIdResult.Bag.SurchargeHourly,
                            SurchargeYearly = getByIdResult.Bag.SurchargeYearly,
                            WProtect        = getByIdResult.Bag.WProtect,
                        };
                    }
                }
            }

            return(result);
        }
Example #2
0
        public OperationResponse <CustomerFreightoutUpdateCommandOutputDTO> Update(CustomerFreightoutUpdateCommandInputDTO input)
        {
            var result = new OperationResponse <CustomerFreightoutUpdateCommandOutputDTO>();

            try
            {
                var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>();
                {
                    var entity = dbLocator.Set <CustomerFreightout>().FirstOrDefault(o => o.Id == input.Id);
                    if (entity != null)
                    {
                        entity.Cost = input.Cost;
                        entity.CustomerFreightoutRateTypeId = input.CustomerFreightoutRateTypeId;
                        entity.CustomerId      = input.CustomerId;
                        entity.DateFrom        = input.DateFrom;
                        entity.DateTo          = input.DateTo;
                        entity.SecondLeg       = input.SecondLeg;
                        entity.SurchargeHourly = input.SurchargeHourly;
                        entity.SurchargeYearly = input.SurchargeYearly;
                        entity.WProtect        = input.WProtect;
                    }

                    dbLocator.SaveChanges();


                    var dbResult = dbLocator.Set <CustomerFreightout>().Where(o => o.Id == entity.Id).Select(o => new CustomerFreightoutUpdateCommandOutputDTO
                    {
                        Id           = o.Id,
                        CustomerId   = o.CustomerId,
                        CustomerName = o.Customer.Name,
                        Cost         = o.Cost,
                        CustomerFreightoutRateTypeId = o.CustomerFreightoutRateTypeId,
                        DateFrom        = o.DateFrom,
                        DateTo          = o.DateTo,
                        SecondLeg       = o.SecondLeg,
                        SurchargeHourly = o.SurchargeHourly,
                        SurchargeYearly = o.SurchargeYearly,
                        WProtect        = o.WProtect,
                    }).FirstOrDefault();
                    result.Bag = dbResult;

                    return(result);
                }
            }
            catch (Exception ex)
            {
            }

            return(result);
        }
Example #3
0
        public IActionResult Put([FromBody] CustomerFreightoutUpdateCommandInputDTO model)
        {
            var appResult = this.UpdateCommand.Execute(model);

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