public async Task <ServiceResponse <bool> > AllocateBuses(VehicleAllocationDTO queryDto) { return(await HandleApiOperationAsync(async() => { var result = await _vehicleService.AllocateBuses(queryDto); return new ServiceResponse <bool> { Object = result }; })); }
public async Task <bool> SendAllocateMessage(VehicleAllocationDTO queryDto) { string ComposedDetail = ""; string joined = ""; string DRegNumber = ""; string NewL = HttpUtility.HtmlEncode("<br />"); IQueryable <VehicleAllocationDTO> Terminal = null; // Reset All assigned Vehicle location to Benin if (queryDto.Type == 3) { var vehicleinfo = from vvehicle in _vehicleRepo.GetAll() select new VehicleAllocationDTO { RegistrationNumber = vvehicle.RegistrationNumber, LocationId = vvehicle.LocationId, DriverId = vvehicle.DriverId, Id = vvehicle.Id }; foreach (var detail in vehicleinfo) { int id = Convert.ToInt32("25"); var vehicle = await _vehicleRepo.GetAsync(detail.Id); vehicle.LocationId = id; vehicle.Status = VehicleStatus.Idle; await _unitOfWork.SaveChangesAsync(); } } else { //send sms to a specified terminal after assigning of vehicles if (queryDto.Type == 2) { Terminal = from terminal in _terminalRepo.GetAll().Where(x => x.Id == queryDto.LocationId) select new VehicleAllocationDTO { TerminalId = terminal.Id, ContactPersonNo = terminal.ContactPersonNo, TerminalName = terminal.Name }; } //send sms to all terminals after assigning of vehicles else if (queryDto.Type == 1) { //var newInClause = new string[] { "26", "16", "30" }.Where(x => x.LocationId == 26 || x.LocationId == 16 || x.LocationId == 30 ); Terminal = from terminal in _terminalRepo.GetAll().Where(x => x.TerminalType == TerminalType.Physical) select new VehicleAllocationDTO { TerminalId = terminal.Id, ContactPersonNo = terminal.ContactPersonNo, TerminalName = terminal.Name }; } foreach (var item in Terminal) { if (!string.IsNullOrEmpty(item.ContactPersonNo)) { var vehicleinfo = from vehicle in _vehicleRepo.GetAll() //join driverinfo in _driversvc.GetAll() on vehicle.DriverId equals driverinfo.Id where (vehicle.LocationId == item.TerminalId) select new VehicleAllocationDTO { RegistrationNumber = vehicle.RegistrationNumber, //Details = vehicle.RegistrationNumber + " - " + driverinfo.Name, DriverId = vehicle.DriverId }; StringBuilder AllDetails = new StringBuilder(); foreach (var detail in vehicleinfo) { DRegNumber = detail.RegistrationNumber.ToString(); var Dname = await _driversvc.GetDriverById(detail.DriverId); string ShortDname = ""; if (detail.DriverId == 497) { ShortDname = "N/A"; } else { ShortDname = Dname.Name.ToString(); } ComposedDetail = " " + DRegNumber + " - " + ShortDname; AllDetails.Append(string.Format("{0};", ComposedDetail)); AllDetails.Append("\r\n").Replace(System.Environment.NewLine, "\r\n"); //joined = string.Join(",", ComposedDetail); } string smsMessageb = $"Vehicles allocated are \r\n" + AllDetails.ToString(); await SendSMS(item.ContactPersonNo, smsMessageb); } } } return(true); }
public async Task <bool> AllocateBuses(VehicleAllocationDTO queryDto) { if (!string.IsNullOrEmpty(queryDto.Type.ToString()) && queryDto.Type.ToString() != "0") { await SendAllocateMessage(queryDto); } else { string AllRegs = queryDto.RegistrationNumber; string[] AllRegsvalues = AllRegs.Split(','); dynamic test = AllRegsvalues; foreach (var item in AllRegsvalues) { if (item == "") { continue; } else if (item != null) { int id = Convert.ToInt32(item.ToString()); var vehicle = await _vehicleRepo.GetAsync(id); vehicle.VehicleModel = await _vehicleModelRepo.GetAsync(vehicle.VehicleModelId); var email = await _userSvc.FindByNameAsync(_serviceHelper.GetCurrentUserEmail()); queryDto.Email = email.Email; vehicle.LocationId = queryDto.LocationId; vehicle.Status = VehicleStatus.Idle; //new var check = _vehicleAlloRepo.GetAll().Where(s => s.VehicleId == vehicle.Id && s.TransactionDate.Date == DateTime.UtcNow.Date); if (check.Count() != 0) { check.FirstOrDefault().TransactionDate = DateTime.Now; check.FirstOrDefault().DestinationTerminal = vehicle.LocationId; await _unitOfWork.SaveChangesAsync(); } else if (check.Count() == 0) { _vehicleAlloRepo.Insert(new VehicleAllocationDetailModel { VehicleId = vehicle.Id, DriverId = vehicle.DriverId, VehicleName = vehicle.VehicleModel.Name, DestinationTerminal = vehicle.LocationId, UserEmail = queryDto.Email, TransactionDate = DateTime.Now, CreatorUserId = _serviceHelper.GetCurrentUserId(), }); } await _unitOfWork.SaveChangesAsync(); } ; } } return(true); }