示例#1
0
        public async Task <IActionResult> Create([Bind("GateId,Vieta")] Gate gate, [Bind("TransportType")] int transportType, [Bind("WareHouse")] int wareHouse)
        {
            if (ModelState.IsValid && gate.Vieta.Length != 0 && wareHouse != 0)
            {
                gate.WareHouse     = _context.WareHouse.Where(x => x.WareHouseId == wareHouse).FirstOrDefault();
                gate.TransportType = new List <GateTransportType>();
                gate.TransportType.Add(new GateTransportType {
                    PriimamoMasinosTipas = (CarType)transportType
                });


                _context.Add(gate);
                await _context.SaveChangesAsync();

                for (int d = 1; d <= 7; d++)
                {
                    for (int i = 8; i <= 17; i++)
                    {
                        _context.Add(new GateTime {
                            Diena = DateTime.Today.AddDays(d).AddHours(i), Gate = gate
                        });
                    }
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gate));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Busena")] Shipment shipment)
        {
            var oldShipment = _context.Shipments.Include(x => x.driver).FirstOrDefault(x => x.ShipmentId == id);

            if (oldShipment != null)
            {
                try
                {
                    oldShipment.driver.MasinosBusena = (CarStatus)shipment.Busena;
                    if (oldShipment.driver.MasinosBusena == CarStatus.Arrived)
                    {
                        oldShipment.driver.AtvykimoLaikas = DateTime.Now;
                    }
                    if (oldShipment.driver.MasinosBusena == CarStatus.Left)
                    {
                        oldShipment.driver.IsvykimoLaikas = DateTime.Now;
                    }
                    _context.Update(oldShipment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShipmentExists(shipment.ShipmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(shipment));
        }
示例#3
0
        public async Task <IActionResult> RegisterArrival(int id, int gateTimeId)
        {
            var oldShipment = _context.Shipments.Include(x => x.driver).FirstOrDefault(x => x.ShipmentId == id);

            if (oldShipment != null)
            {
                try
                {
                    oldShipment.gateTime        = _context.GateTime.FirstOrDefault(x => x.GateTimeId == gateTimeId);
                    oldShipment.gateTime.IsUsed = true;
                    _context.Update(oldShipment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                }
            }
            return(RedirectToAction(nameof(RegisterArrival)));
        }