예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,RegNr,Color,Brand,Model,NoWheels,MemberId,VehicleTypeClassId")] Vehicle vehicle)
        {
            if (RegNoIsParked(vehicle.RegNr))
            {
                ModelState.AddModelError("RegNr", "Det finns redan ett fordon med det här registreringsnumret i garaget");
            }

            if (ModelState.IsValid)
            {
                vehicle.ParkedIn = DateTime.Now;
                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.MemberSelectList = _context.Members.OrderBy(m => m.Name).Select(m => new SelectListItem {
                Selected = false,
                Text     = m.Name,
                Value    = m.Id.ToString()
            }).ToList();

            ViewBag.VehicleTypeSelectList = _context.VehicleTypeClass.Select(t => new SelectListItem {
                Selected = false,
                Text     = t.Type,
                Value    = t.Id.ToString()
            }).ToList();
            return(View(vehicle));
        }
        public async Task <IActionResult> Create([Bind("Id,Type,RegNr,Color,Brand,Model,NoWheels,FreeText,ParkedIn,ParkedOut")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                db.Add(vehicle);
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicle));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Type,Price")] VehicleTypeClass vehicleTypeClass)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicleTypeClass);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleTypeClass));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Member member)
        {
            if (ModelState.IsValid)
            {
                _context.Add(member);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(member));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("VehicleType,RegNum,Color,Brand,Model,Wheels,ArrivalTime")] Vehicle vehicle)
        {
            vehicle.ArrivalTime = DateTime.Now;

            if (ModelState.IsValid)
            {
                vehicle.RegNum = vehicle.RegNum.ToUpper();
                vehicle.Brand  = vehicle.Brand.ToUpper();
                vehicle.Model  = vehicle.Model.ToUpper();


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

                return(RedirectToAction(nameof(Parked), ToOverviewModel(vehicle)));
            }

            return(View(vehicle));
        }