コード例 #1
0
        public async Task <IActionResult> Edit(OrderEditInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input = this.ordersService.LoadOrderEditInputModel(input.Id);
                return(this.View(input));
            }

            // var priceIn = this.financeService.GetAmount(input.OrderFromCurrencyId, input.OrderFromPriceNetIn);
            // var priceOut = this.financeService.GetAmount(input.OrderToCurrencyId, input.OrderToPriceNetOut);
            // var margin = priceIn - priceOut;
            // var fromCurrencyId = this.currencies.AllAsNoTracking().FirstOrDefault(c => c.Name == CurrencyCodes.EUR.ToString()).Id;
            //// if (priceIn < this.financeService.GetAmount(fromCurrencyId, GlobalConstants.SmallOrderMaxAmount) &&
            ////    margin < this.financeService.GetAmount(fromCurrencyId, GlobalConstants.SmallOrderMinMargin))
            //// {
            ////    this.ModelState.AddModelError(string.Empty, "The order margin for order under 500€ cannot be less than 25€.");
            ////    input = this.ordersService.LoadOrderEditInputModel(input.Id);
            ////    return this.View(input);
            //// }

            // var minMarginPer = priceIn * GlobalConstants.MinOrderMargin;

            // if (margin < minMarginPer)
            // {
            //    this.ModelState.AddModelError(string.Empty, "The order margin cannot be less than 5%.");
            //    input = this.ordersService.LoadOrderEditInputModel(input.Id);
            //    return this.View(input);
            // }
            await this.ordersService.EditAsync(input);

            // await this.SendContractToCompanyAsync(input.Id);
            this.notyfService.Success(this.localizer["Order contract sent."]);
            return(this.Redirect(@$ "/Orders/CorrectApplication/{input.Id}{(input.ReturnUrl is not null ? $"?returnUrl = { input.ReturnUrl } " : string.Empty)}"));
        }
コード例 #2
0
        public async Task <string> EditAsync(OrderEditInputModel input)
        {
            var order = this.orders.All().FirstOrDefault(o => o.Id == input.Id);

            order.OrderFrom.ReferenceNum = input.OrderFromReferenceNum;

            foreach (var orderTo in order.OrderTos)
            {
                var orderToInput = input.OrderTos.FirstOrDefault(o => o.Id == orderTo.Id);
                orderTo.CarrierOrder.CompanyId = orderToInput.CarrierOrderCompanyId;
                orderTo.PriceNetOut            = orderToInput.PriceNetOut;
                orderTo.CurrencyOutId          = orderToInput.CurrencyOutId;
                orderTo.PriceNetIn             = orderToInput.PriceNetIn;
                orderTo.CurrencyInId           = orderToInput.CurrencyInId;
                orderTo.ContactId = orderToInput.ContactId;
                orderTo.VehicleId = orderToInput.VehicleId;

                var actions       = orderTo.OrderActions;
                var notDeletedIds = new List <int>();
                foreach (var inputAction in orderToInput.OrderActions)
                {
                    var orderAction = actions.FirstOrDefault(a => a.Id == inputAction.Id);
                    if (orderAction is null)
                    {
                        orderAction                 = new OrderAction();
                        orderAction.Address         = new Address();
                        orderAction.AdminId         = order.AdminId;
                        orderAction.Address.AdminId = order.AdminId;
                        actions.Add(orderAction);
                    }

                    orderAction.TypeId             = inputAction.TypeId;
                    orderAction.Address.City       = inputAction.Address.City;
                    orderAction.Address.Postcode   = inputAction.Address.Postcode;
                    orderAction.Address.Area       = inputAction.Address.Area;
                    orderAction.Address.State      = inputAction.Address.State;
                    orderAction.Address.StreetLine = inputAction.Address.StreetLine;
                    orderAction.Until   = inputAction.Until;
                    orderAction.Details = inputAction.Details;
                    notDeletedIds.Add(orderAction.Id);
                }

                foreach (var action in actions)
                {
                    if (!notDeletedIds.Contains(action.Id))
                    {
                        action.IsDeleted = true;
                    }
                }

                var cargo = orderTo.Cargo;
                cargo.TypeId        = orderToInput.Cargo.TypeId;
                cargo.VehicleType   = this.vehicleTypes.All().FirstOrDefault(vt => vt.Name == VehicleTypeNames.Truck.ToString());
                cargo.LoadingBodyId = orderToInput.Cargo.LoadingBodyId;
                cargo.Name          = orderToInput.Cargo.Name;
                cargo.Lenght        = orderToInput.Cargo.Lenght;
                cargo.Width         = orderToInput.Cargo.Width;
                cargo.Height        = orderToInput.Cargo.Height;
                cargo.WeightGross   = orderToInput.Cargo.WeightGross;
                cargo.WeightNet     = orderToInput.Cargo.WeightNet;
                cargo.Cubature      = orderToInput.Cargo.Cubature;
                cargo.Quantity      = orderToInput.Cargo.Quantity;
                cargo.Details       = orderToInput.Cargo.Details;

                var inputDocumentation = orderToInput.Documentation;
                var documentation      = orderTo.Documentation;
                documentation.CMR          = inputDocumentation.CMR;
                documentation.BillOfLading = inputDocumentation.BillOfLading;
                documentation.AOA          = inputDocumentation.AOA;
                documentation.DeliveryNote = inputDocumentation.DeliveryNote;
                documentation.PackingList  = inputDocumentation.PackingList;
                documentation.ListItems    = inputDocumentation.ListItems;
                documentation.Invoice      = inputDocumentation.Invoice;
                documentation.BillOfGoods  = inputDocumentation.BillOfGoods;
            }

            await this.documentations.SaveChangesAsync();

            await this.orders.SaveChangesAsync();

            return(order.Id);
        }