Пример #1
0
        public async Task SetOrderShipping(LogisticViewModel model)
        {
            foreach (var route in model.Routes)
            {
                var transRoute = new TransactRoute {Date = DateTime.Now, TransactValue = (decimal)route.RouteTariff };
                _db.Entry(transRoute).State = EntityState.Added;
                await _db.SaveChangesAsync();
                foreach (var order in route.Orders)
                {
                    var receipt = await _db.Receipts.FindAsync(int.Parse(order.Id));
                    if (receipt == null) continue;
                    receipt.Status = ReceiptStatus.Shipping;
                    _db.Entry(receipt).State = EntityState.Modified;
                    var recRoute = new TransactRouteReceipt {ReceiptId = receipt.Id, RouteId = transRoute.Id};
                    _db.Entry(recRoute).State = EntityState.Added;
                    await _db.SaveChangesAsync();
                }
            }

            
            
        }
Пример #2
0
        public async Task<ActionResult> Logistic(LogisticViewModel model)
        {
            await OrderManager.SetOrderShipping(model);

            return RedirectToAction("ReceiptsView");
        }
Пример #3
0
 public async Task<JsonResult> Calqulate(LogisticViewModel model)
 {
     return await OrderManager.CalqulateTariff(model.Routes);
 }
Пример #4
0
        public async Task<ActionResult> Logistic()
        {
            var shop = await AdressManager.GetShop();
            var basereceipts = (await OrderManager.GetReceiptsListAsync());

            var receipts = new List<ReceiptViewModel>();
            foreach (var rec in basereceipts.Where(o => o.Status == ReceiptStatus.Created))
            {
                var recModel = new ReceiptViewModel(rec)
                {
                    Products = await ProductManager.GetProducsInOrderAsync(rec.Order.Id),
                    User = rec.Order.User.ToString(),
                    Date = rec.Date,
                    PaymentType = rec.Order.PaymentType,
                    TariffModel = await GetTariffModel(rec.Order),
                };
                recModel.Products.ForEach(o => o.ReadOnly = true);
                receipts.Add(recModel);
            }

            var model = new LogisticViewModel { ShopAdress = shop.Adress.FullAdress, Routes = new List<RouteViewModel>() };
            var routeId = 1;
            if (receipts.Any())
                foreach (var tariffcoeff in await OrderManager.GetTariffCoefficients())
                {
                    var recs = receipts.Where(o => o.ShippingType.SortId < 2 && o.TariffModel.TariffKoefficient == tariffcoeff);
                    if (recs.Any())
                    {
                        var routeHouse = new RouteViewModel
                        {
                            Id = routeId++,
                            UrbanId = tariffcoeff.UrbanCategoryId,
                            Orders = recs.ToList(),
                            ShippingTypeId = 1,
                            ShippingType = "за адресою",
                            SummOrderTariff = recs.Sum(o => o.ShippingCost),
                            OrderDistance = 2 * recs.Sum(o => o.Distance),
                            ListAdress = new List<string>()
                        };
                        if (routeHouse.Orders != null)
                            foreach (var order in routeHouse.Orders)
                            {
                                if (!routeHouse.ListAdress.Contains(order.Adress)) routeHouse.ListAdress.Add(order.Adress);
                            }
                        model.Routes.Add(routeHouse);
                    }
                    recs = receipts.Where(o => o.ShippingType.SortId == 2 && o.TariffModel.TariffKoefficient == tariffcoeff);
                    if (recs.Any())
                    {
                        var routePost = new RouteViewModel
                        {
                            Id = routeId++,
                            UrbanId = tariffcoeff.UrbanCategoryId,
                            Orders = recs.ToList(),
                            ShippingTypeId = 2,
                            ShippingType = "до пункту видачі",
                            SummOrderTariff = recs.Sum(o => o.ShippingCost),
                            OrderDistance = 2 * recs.Sum(o => o.Distance),
                            ListAdress = new List<string>()
                        };
                        if (routePost.Orders != null)
                            foreach (var order in routePost.Orders)
                            {
                                if (!routePost.ListAdress.Contains(order.Adress)) routePost.ListAdress.Add(order.Adress);
                            }
                        model.Routes.Add(routePost);
                    }
                }
            model.CountRoute = model.Routes.Count;
            return View(model);
        }