public async Task <IActionResult> DriveMe(Reservation data) { string currentUserId = _userManager.GetUserId(HttpContext.User);//Get UserId var WebSiteName = Request.Host.Value; //need to update vaicalecurrentlocaion VehicleCurrentLocation _VehicleCurrentLocation = await _context.VehicleCurrentLocations .FirstOrDefaultAsync(u => u.VehicleId == data.VehicleId); _VehicleCurrentLocation.Latitue = data.ReturnLocationLatitue; _VehicleCurrentLocation.Longitute = data.ReturnLocationLongitute; _VehicleCurrentLocation.UpdateTime = DateTime.Now; _VehicleCurrentLocation.UserId = currentUserId; _context.VehicleCurrentLocations.Update(_VehicleCurrentLocation); await _context.SaveChangesAsync(); //sending email to the user to give feedback about the journ var _User = await _context.Users.FindAsync(currentUserId); string _Feedbacklink = HtmlEncoder.Default.Encode($"//{WebSiteName}/Vehicle/VehicleDetails/{data.VehicleId}"); string _EmailReciptsBody = $"Dear {_User.FirstName} , thank you for using our service," + $" Please, give ur your feedback about the service on the follwing link " + $" <a href={_Feedbacklink}> Feedback </a>"; await _emailSender.SendEmailAsync(_User.Email, "Car Share Service", _EmailReciptsBody); return(RedirectToAction("Index", "Home")); }
//To guide the user to the car location public async Task <IActionResult> WalkMe(int Id) { string currentUserId = _userManager.GetUserId(HttpContext.User);//Get UserId Reservation _Reservation = await _context.Reservations.FindAsync(Id); VehicleCurrentLocation _VehicleCurrentLocation = await _context.VehicleCurrentLocations.FirstOrDefaultAsync(ca => ca.VehicleId == _Reservation.VehicleId); return(View(_VehicleCurrentLocation)); }
//Set the Vehicle Location (id= VehicleId public async Task <IActionResult> VehicleLocation(int id) { VehicleCurrentLocation _VehicleCurrentLocation = await _context.VehicleCurrentLocations.FirstOrDefaultAsync(m => m.VehicleId == id); if (_VehicleCurrentLocation == null) { VehicleCurrentLocation model = new VehicleCurrentLocation { Id = 0, VehicleId = id }; return(View(model)); } return(View(_VehicleCurrentLocation)); }
//Add or update Location public async Task <IActionResult> VehicleLocationAddUpdate(VehicleCurrentLocation data) { string currentUserId = _userManager.GetUserId(HttpContext.User);//Get UserId if (ModelState.IsValid) { if (data.Id.Equals(0))//add new record { data.UpdateTime = DateTime.Now; data.CreateTime = DateTime.Now; data.UserId = currentUserId; await _context.VehicleCurrentLocations.AddAsync(data); ViewBag.Msg = "Your Vehicle Current Location has been Added...."; } else//update { VehicleCurrentLocation _VehicleCurrentLocation = await _context.VehicleCurrentLocations.FindAsync(data.Id); _VehicleCurrentLocation.Latitue = data.Latitue; _VehicleCurrentLocation.Longitute = data.Longitute; _VehicleCurrentLocation.UpdateTime = data.UpdateTime; _VehicleCurrentLocation.UserId = currentUserId; _context.VehicleCurrentLocations.Update(_VehicleCurrentLocation); ViewBag.Msg = "Your Vehicle Current Location has been Updated...."; } await _context.SaveChangesAsync(); return(View("VehicleLocation", data)); } return(View("VehicleLocation", data)); }