Example #1
0
        // GET: Warehouses/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var warehouse = await _warehouseService.GetAsync((Guid)id);

            var deliveryPoints = (await _deliveryPointService.GetAllAsync()).Where(x => x.WarehouseId == warehouse.Id).ToList();

            var vm = new WarehouseViewModel()
            {
                DeliveryPoints = deliveryPoints
            };

            if (warehouse == null)
            {
                return(NotFound());
            }

            return(View(vm));
        }
        // GET: Deliveries/Delete/5
        public async Task <IActionResult> Dispatch(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var delivery = await _deliveryService.GetAsync((Guid)id);

            var company = await _companyService.GetAsync((Guid)delivery?.DestinationCompanyId);

            try
            {
                var warehouse = (await _warehouseService.GetAllAsync())
                                .FirstOrDefault(x =>
                                                x.CompanyId == company.Id && x.MaxCode >= delivery.Code && x.MinCode <= delivery.Code);

                var deliveryPoints = (await _deliveryPointService.GetAllAsync())
                                     .Where(x => x.WarehouseId == warehouse?.Id)
                                     .ToList();

                var deliveryEvents = new List <Event>();

                deliveryPoints.ForEach((x) =>
                {
                    var deliveries = _deliveryService.GetAllAsync().GetAwaiter().GetResult()
                                     .Where(o => o.DeliveryPointId == x.Id).ToList();

                    deliveries.ForEach(d =>
                    {
                        if (d.DispatchTime != null && d.DeliveryTime != null)
                        {
                            deliveryEvents.Add(new Event()
                            {
                                title = "Dostava",
                                start = d.DispatchTime,
                                end   = d.DeliveryTime
                            });
                        }
                    });
                });

                var vm = new DeliveryViewModel()
                {
                    Id   = delivery.Id,
                    Code = delivery.Code,
                    DestinationCompanies = company,
                    DeliveryPoints       = deliveryPoints,
                    DeliveryEvents       = deliveryEvents
                };

                return(View(vm));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty,
                                         "Prosimo vnesite skladišča (tudi min in max vrednost posebej) in dostavne točke, ter nato poskusite ponovno.");

                return(View(new DeliveryViewModel()
                {
                    Id = delivery.Id,
                    Code = delivery.Code,
                    DestinationCompanies = company,
                    DeliveryPoints = new List <DeliveryPointDto>(),
                    DeliveryEvents = new List <Event>()
                }));
            }
        }
 // GET: DeliveryPoints
 public async Task <IActionResult> Index()
 {
     return(View(await _deliveryPointService.GetAllAsync()));
 }