示例#1
0
        // GET: Driver/Details/5


        // GET: Driver/Create
        public IActionResult checkIfDriverRegistered(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var shipment = _context.Shipments.Include(x => x.driver)
                           .Include(x => x.supplier)
                           .Include(x => x.delays)
                           .Include(x => x.gateTime)
                           .Include(x => x.gateTime.Gate)
                           .Include(x => x.gateTime.Gate.WareHouse)
                           .FirstOrDefault(x => x.ShipmentId == id);

            if (shipment == null)
            {
                var supplier = new Supplier()
                {
                    ImonesPavadinimas = "kainava", SupplierId = 0, TelefonoNr = "8612312312", VardasPavarde = "Jonas Jonaitis"
                };
                shipment = new Shipment()
                {
                    ShipmentId = 0, CreationDate = DateTime.Now, SupplierLink = "sss", Busena = ShipmentStatus.PendingApproval, supplier = supplier, delays = null, gateTime = null, driver = null, Products = null
                };
                _context.Shipments.Add(shipment);
                _context.SaveChanges();
            }
            if (shipment == null)
            {
                return(NotFound());
            }
            return(View(shipment));
        }
        public IActionResult register(int id)
        {
            if (id == 0)
            {
                return(NotFound());
            }
            bool     ship = _context.Shipments.Any(x => x.ShipmentId == id);
            Shipment shipment;

            if (!ship)
            {
                SendingProduct product = new SendingProduct()
                {
                    Amount = 2, Name = "am", SendingProductId = 0, Type = ProductType.ProdA, Weight = 15
                };
                List <SendingProduct> prod = new List <SendingProduct>();
                prod.Add(product);
                shipment = new Shipment()
                {
                    ShipmentId = id, CreationDate = DateTime.Now, SupplierLink = "sss", Busena = ShipmentStatus.PendingApproval, supplier = null, delays = null, gateTime = null, driver = null, Products = prod
                };
                _context.Shipments.Add(shipment);
                _context.SaveChanges();
            }
            else
            {
                shipment = _context.Shipments.Include(x => x.supplier).Include(x => x.Products).FirstOrDefault(x => x.ShipmentId == id);
            }
            if (shipment == null)
            {
                return(NotFound());
            }
            ViewBag.ShipmentId = shipment.ShipmentId;
            return(View(shipment));
        }