public async Task <IActionResult> Create([Bind("DriverId,LastName,FirstName,Age,Email,PhoneNumber,DriversLicense")] Driver driver) { if (ModelState.IsValid) { _context.Add(driver); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(driver)); }
public async Task <IActionResult> Create([Bind("OwnerId,LastName,FirstName,Email,PhoneNumber")] Owner owner) { if (ModelState.IsValid) { _context.Add(owner); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(owner)); }
public async Task <IActionResult> Create(AddTaxiViewModel taxiViewModel) { if (ModelState.IsValid) { taxiViewModel.NewTaxi.IsWorking = true; var taxi = MapTaxiViewModelToTaxi(taxiViewModel.NewTaxi, new Taxi()); var currentTaxi = _context.Taxi.FirstOrDefault(x => x.Registration == taxiViewModel.NewTaxi.Registration); taxiViewModel.DisplayEdit = false; taxiViewModel.SearchModel = new SearchViewModel(); IEnumerable <Taxi> allTaxi = (from t in _context.Taxi join make in _context.CarMake on t.Make equals make.MakeId join mod in _context.CarModel on t.Model equals mod.ModelId select new Taxi() { TaxiId = t.TaxiId, ModelNavigation = mod, MakeNavigation = make, Registration = t.Registration, Comments = t.Comments, IsWorking = t.IsWorking }).ToList(); var taxis = new List <TaxiViewModel>(); taxiViewModel.NewTaxi = new TaxiViewModel(); taxiViewModel.SearchModel = new SearchViewModel(); taxiViewModel.Makes = _context.CarMake.ToList(); taxiViewModel.Models = _context.CarModel.ToList(); foreach (var taxi1 in allTaxi) { var viewModel = MapToTaxiViewModel(taxi1); taxis.Add(viewModel); } taxiViewModel.Taxis = taxis; if (currentTaxi != null) { taxiViewModel.NewTaxi = new TaxiViewModel(); taxiViewModel.Error = "The taxi with registration" + currentTaxi.Registration + " already exists."; return(View("Index", taxiViewModel)); } _context.Add(taxi); await _context.SaveChangesAsync(); taxiViewModel.NewTaxi = new TaxiViewModel(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Index", "Taxis", taxiViewModel)); }
public async Task <ActionResult> AddEarningsAsync(EarningsViewModel earningsViewModel) { earningsViewModel = validateEarning(earningsViewModel); if (earningsViewModel.Error != null) { return(RedirectToAction("MyEarnings", "Earnings", new { earningsViewModel.ShiftDate, earningsViewModel.EarningsOn, earningsViewModel.UserId, earningsViewModel.WeeklyEarnings, earningsViewModel.MonthlyEarnings, earningsViewModel.DriverId })); } var earning = MapViewModelToEarnings(earningsViewModel); var earningExists = _context.Earnings.FirstOrDefault( x => x.DriverId == earning.DriverId && x.ShiftDate == earning.ShiftDate); if (ModelState.IsValid && earningExists == null) { _context.Add(earning); await _context.SaveChangesAsync(); } else { earningExists.Earning = earning.Earning; earningExists.IncomeEarned = earning.IncomeEarned; earningExists.Expenditure = earning.Expenditure; earningExists.TaxiId = earning.TaxiId; _context.Update(earningExists); await _context.SaveChangesAsync(); } return(RedirectToAction("MyEarnings", "Earnings", new { earningsViewModel.ShiftDate, earningsViewModel.EarningsOn, earning.UserId, earningsViewModel.WeeklyEarnings, earningsViewModel.MonthlyEarnings, earningsViewModel.DriverId })); }
public async Task <IActionResult> AddShift(ScheduleViewModel scheduleViewModel) { if (scheduleViewModel.ScheduleId != 0) {//Edit if (ModelState.IsValid) { Schedule schedule = ConvertViewModeltoSchedule(scheduleViewModel); scheduleViewModel.DisplayEdit = false; try { _context.Update(schedule); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { scheduleViewModel.ScheduleId = 0; if (!ScheduleExists(schedule.ScheduleId)) { return(NotFound()); } else { throw; } } } } else {//Add if (ModelState.IsValid) { Schedule schedule = ConvertViewModeltoSchedule(scheduleViewModel); _context.Add(schedule); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { scheduleViewModel.Error = "Schedule could not be added"; } } scheduleViewModel = Load(scheduleViewModel); return(View("Index", scheduleViewModel)); }
public async Task <ActionResult> RegistrationAsync(RegistrationViewModel registrationViewModel) { registrationViewModel = validateRegistration(registrationViewModel); if (registrationViewModel.UserId != 0) { return(View(registrationViewModel)); } Users user = MapRegistrationModelToUser(registrationViewModel); Driver driver = MapRegistrationModelToDriver(registrationViewModel); Owner owner = MapRegistrationModelToOwner(registrationViewModel); if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); if (registrationViewModel.IsOwner) { owner.UserId = user.UserId; _context.Owner.Add(owner); } else { driver.UserId = user.UserId; _context.Driver.Add(driver); } await _context.SaveChangesAsync(); return(RedirectToAction("SuccessfullRegistration", "Users")); } return(View(registrationViewModel)); }