Ejemplo n.º 1
0
        public IActionResult Create()
        {
            var cars = new List <SelectListItem>();

            cars.Add(new SelectListItem
            {
                Text  = "Välj en",
                Value = ""
            });
            List <Car> carsInDatabase = _carRepo.AllCarsNotBooked();

            foreach (var item in carsInDatabase)
            {
                cars.Add(new SelectListItem {
                    Text = item.LicensePlate, Value = item.LicensePlate
                });
            }

            var customer = new List <SelectListItem>();

            customer.Add(new SelectListItem
            {
                Text  = "Välj en",
                Value = ""
            });
            List <Customer> customersInDatabase = _customerRepo.AllCustomers();

            foreach (var item in customersInDatabase)
            {
                customer.Add(new SelectListItem {
                    Text = item.SSN, Value = item.SSN
                });
            }
            ViewBag.customer   = customer;
            ViewBag.carSizeOne = cars;
            return(View());
        }
Ejemplo n.º 2
0
        public IActionResult Create([Bind("SSN, FirstName, LastName")] Customer customer)
        {
            foreach (var item in _customerRepo.AllCustomers())
            {
                if (item.SSN == customer.SSN)
                {
                    ViewBag.error = $"Kunden {customer.SSN} finns redan i databasen";
                    return(View("~/Views/Customer/CreateNewCustomer.cshtml"));
                }
            }
            if (ModelState.IsValid)
            {
                _customerRepo.Add(customer);
                ViewBag.ok = $"Kunden {customer.FirstName} är tillagd";
                return(View("~/Views/Home/Index.cshtml"));
            }

            return(View("~/Views/Customer/CreateNewCustomer.cshtml"));
        }