Esempio n. 1
0
        public IActionResult Create(CreateOrderViewModel input)
        {
            if (!ModelState.IsValid)
            {
                var products = new CreateOrderViewModel();

                return(View(products));
            }
            var carrier = _carriersService.GetAllCarriers()
                          .FirstOrDefault(x => x.Name == input.Carrier.Name);

            input.Driver.Carrier    = carrier;
            input.Driver.CarrierId  = carrier.Id;
            input.Vehicle.Carrier   = carrier;
            input.Vehicle.CarrierId = carrier.Id;

            if (!ModelState.IsValid)
            {
                return(this.View(input));
            }

            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var order  = this._orderService.Create(userId,
                                                   input.Purpose.ToString(),
                                                   input.DeliveryAddress,
                                                   input.Receiver.Name,
                                                   input.Carrier.Name,
                                                   input.Driver.FullName,
                                                   input.Vehicle.RegNumber);

            return(Redirect($"/Orders/Edit?id={order.Id}"));
        }
Esempio n. 2
0
        public IActionResult CreateNewDriver()
        {
            List <SelectListItem> list = new List <SelectListItem>
            {
                new SelectListItem("Choose >>>", "Choose >>>")
            };

            var carrierNames = _carriersService.GetAllCarriers()
                               .Select(x => x.Name)
                               .ToList();

            foreach (var carrier in carrierNames)
            {
                list.Add(new SelectListItem(carrier, carrier));
            }

            ViewBag.Carriers = list;

            return(this.View());
        }