public async Task <IActionResult> Edit(string id, [Bind("Id,Name,DriverId,TaxiCabState,DriverPercent,ServiceType")] TaxiService taxiService) { if (id != taxiService.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(taxiService); if (taxiService.TaxiCabState == TaxiCabState.Ready) { var passengers = _context.TaxiServices.Include(c => c.Passnegers).FirstOrDefault(c => c.Id == taxiService.Id)?.Passnegers; foreach (var item in passengers) { item.RequsetState = RequsetSate.Servicing; _context.Update(item); } } await _context.SaveChangesWithHistoryAsync(HttpContext); } catch (DbUpdateConcurrencyException ex) { throw ex; } return(RedirectToAction(nameof(Index))); } ViewData["DriverId"] = new SelectList(_context.Drivers.Undelited().Where(c => c.ContractorId == User.GetContractor().Id), "Id", "Name", taxiService.DriverId); return(View(taxiService)); }
public async Task <IActionResult> Create([Bind("Id,Name,DriverId,DriverPercent")] TaxiService taxiCab) { if (ModelState.IsValid) { _context.Add(taxiCab); await _context.SaveChangesWithHistoryAsync(HttpContext); return(RedirectToAction(nameof(Index))); } ViewData["DriverId"] = new SelectList(_context.Drivers.Undelited(), "Id", "Name", taxiCab.DriverId); return(View(taxiCab)); }
public async Task <IActionResult> Create([Bind("Id,Name,DriverId,DriverPercent,ServiceType")] TaxiService taxiService) { if (ModelState.IsValid) { taxiService.TaxiCabState = TaxiCabState.wait; _context.Add(taxiService); await _context.SaveChangesWithHistoryAsync(HttpContext); return(RedirectToAction(nameof(Index))); } ViewData["DriverId"] = new SelectList(_context.Drivers.Undelited().Where(c => c.ContractorId == User.GetContractor().Id), "Id", "Name", taxiService.DriverId); return(View(taxiService)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Name,DriverId,TaxiSerivcestate,DriverPercent")] TaxiService taxiCab) { if (id != taxiCab.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(taxiCab); await _context.SaveChangesWithHistoryAsync(HttpContext); if (taxiCab.TaxiCabState == TaxiCabState.Ready) { var txn = await _context.TaxiServices .Include(c => c.Passnegers) .ThenInclude(p => p.StudentParent) .FirstOrDefaultAsync(c => c.Id == taxiCab.Id); if (txn != null) { foreach (var item in txn.Passnegers) { await _sms.SendNotifyWithTemplateAsync(item.StudentParent.PhoneNubmber, "https://20ro.net/Home/ActiveSerive", MessageTemplate.Bisrobreif); } } } } catch (DbUpdateConcurrencyException) { //if (!TaxiCabExists(taxiCab.Id)) //{ // return NotFound(); //} //else //{ // throw; //} } return(RedirectToAction(nameof(Index))); } ViewData["DriverId"] = new SelectList(_context.Drivers.Undelited(), "Id", "Name", taxiCab.DriverId); return(View(taxiCab)); }
public async Task <IActionResult> Servicification() { var contractorId = User.GetContractor().Id; var Drivers = _context.Drivers.Where(c => c.ContractorId == contractorId).ToList(); if (Drivers == null || Drivers.Count <= 0) { return(Json(new ResultContract <int>() { Data = 0, statuse = false, message = "هیچ راننده فعالی یافت نشد" })); } int Count = _context.TaxiServices.Undelited().Include(c => c.Driver).Where(c => c.Driver.ContractorId == contractorId).Count(); List <ServiceRequset> Requests = await _context.ServiceRequsets.Undelited() .Include(c => c.Academy) .Where(c => c.TaxiServiceId == null && c.RequsetState == RequsetSate.AwaitingContractor && c.Academy.ContractorId == contractorId) .OrderBy(c => c.Longtude).ThenBy(c => c.Latitue).ThenBy(c => c.Distance).ToListAsync(); if (Requests == null || Requests.Count() <= 0) { return(Json(new ResultContract <int>() { Data = 0, statuse = false, message = "هیچ درخواست سرویسی یافت نشد" })); } List <TaxiService> lst = new List <TaxiService>(); var taxineeds = Requests.Where(c => c.ServiceType == ServiceType.taxi); var vanneeds = Requests.Where(c => c.ServiceType == ServiceType.van); for (int i = 0; i <= taxineeds.Count(); i += 4) { var reqs = taxineeds.Skip(i).Take(4); int DriverId = GetRandomDriver(Drivers); if (DriverId == 0) { break; } TaxiService sr = new TaxiService() { DriverId = DriverId, DriverPercent = 75, IsDeleted = false, Name = $"سرویس شماره {(Count + 1)}", ServiceType = ServiceType.taxi, TaxiCabState = TaxiCabState.wait }; foreach (var item in reqs) { sr.Passnegers.Add(item); } lst.Add(sr); Count += 1; } for (int i = 0; i <= vanneeds.Count(); i += 8) { var reqs = vanneeds.Skip(i).Take(8); int DriverId = GetRandomDriver(Drivers); if (DriverId == 0) { break; } TaxiService sr = new TaxiService() { DriverId = DriverId, DriverPercent = 75, IsDeleted = false, Name = $"سرویس شماره {(Count + 1)}", ServiceType = ServiceType.van, TaxiCabState = TaxiCabState.wait }; foreach (var item in reqs) { sr.Passnegers.Add(item); } lst.Add(sr); Count += 1; } await _context.TaxiServices.AddRangeAsync(lst); await _context.SaveChangesWithHistoryAsync(HttpContext); return(Json(new ResultContract <int>() { Data = 1, statuse = true, message = $"تعداد {lst.Count} سرویس با موفقیت تنظیم شد" })); }