public async Task <IActionResult> Create([Bind("Id,StatusBookingId,VehicleTypeId,TypeOfBookingId,VehicleLicense,VehicleEngine,Comments,DateTime, VehicleStyle, Engine, Cost", "VehicleId", "MechanicsId", "Mechanics", "VehicleParts", "MechanicsIds", "VehiclePartsIds")] Booking booking) { if (ModelState.IsValid) { User user = new User(); user = _context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault(); booking.Customer = user; //MechanicBooking mb = new MechanicBooking(); //mb.BookingId = booking.Id; //mb.MechanicId = 1; //booking.Mechanics = new List<MechanicBooking>(); //booking.Mechanics.Add(mb); booking.StatusBookingId = booking.StatusBookingId == 0 ? 1 : booking.StatusBookingId; booking.Mechanics = new List <MechanicBooking>(); booking.VehicleParts = new List <VehiclePartBooking>(); if (booking.MechanicsIds != null) { foreach (int mechanicId in booking.MechanicsIds) { booking.Mechanics.Add(new MechanicBooking() { MechanicId = mechanicId }); } } if (booking.VehiclePartsIds != null) { foreach (int vehiclePartId in booking.VehiclePartsIds) { booking.VehicleParts.Add(new VehiclePartBooking() { VehiclePartId = vehiclePartId }); } } if (OverDailyLimit(booking.DateTime)) { return(RedirectToAction(nameof(Create), new { dailyLimit = true })); } else if (IsSunday(booking.DateTime)) { return(RedirectToAction(nameof(Create), new { sunday = true })); } else { _context.Add(booking); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,Name,Mobile")] Mechanic mechanic) { if (ModelState.IsValid) { _context.Add(mechanic); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mechanic)); }
public async Task <IActionResult> Create([Bind("Id,Part,Cost")] VehiclePart vehiclePart) { if (ModelState.IsValid) { _context.Add(vehiclePart); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehiclePart)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,Password,ConfirmPassword,MobilePhone")] User user) { if (ModelState.IsValid) { user.Level = Models.Enum.UserLevel.Normal; _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }