public IActionResult Reject(int TableHeaderId) { // Add Quantity back to Table - if Available if (!UpdateQuantity(TableHeaderId)) { return(NotFound()); // Or Can Return Error Message } TableBookingHeader tableHeader = _db.TableBookingHeader.Find(TableHeaderId); tableHeader.BookStatus = SD.BookTableStatusRejected; tableHeader.TimeRejected = DateTime.Now; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var StaffName = _db.ApplicationUser.Where(a => a.Id == claim.Value).SingleOrDefault().Name; tableHeader.RejectedBy = StaffName; _db.SaveChanges(); // Send Email To Customer that their Booking was rejected //To Get Email: var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == tableHeader.UserId).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + TableHeaderId + " - Rejected", "You Table Booking has been rejected", "Your table booking details are as follows:", tableHeader); // var Email = _db.ApplicationUser.Find(tableHeader.UserId).Email; // End of Get Email (Please check if this code works first return(RedirectToAction(nameof(ARBooking), new { message = "Table Booking Rejected" })); }
public IActionResult CancelBooking(int TableHeaderId) { // Add Quantity back to Table Available if (!UpdateQuantity(TableHeaderId)) { return(NotFound()); // Or Can Return Error Message } TableBookingHeader tableHeader = _db.TableBookingHeader.Find(TableHeaderId); tableHeader.Status = SD.TableStatusCancelled; tableHeader.TimeRejected = DateTime.Now; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var StaffName = _db.ApplicationUser.Where(a => a.Id == claim.Value).SingleOrDefault().Name; tableHeader.RejectedBy = StaffName; _db.SaveChanges(); var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == tableHeader.UserId).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + TableHeaderId + " - Cancelled", "Your Table Booking has been cancelled", "We apologise for the inconvenience.", tableHeader); return(RedirectToAction(nameof(ManageBooking))); }
public IActionResult Approve(int TableHeaderId) { TableBookingHeader tableHeader = _db.TableBookingHeader.Find(TableHeaderId); tableHeader.BookStatus = SD.BookTableStatusApproved; tableHeader.TimeApproved = DateTime.Now; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var StaffName = _db.ApplicationUser.Where(a => a.Id == claim.Value).SingleOrDefault().Name; tableHeader.ApprovedBy = StaffName; _db.SaveChanges(); // Send Email To Customer that their Booking was approved //To Get Email: var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == tableHeader.UserId).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + TableHeaderId + " - Approved", "Your Table Booking has been approved", "Your table booking details are as follows:", tableHeader); // var Email = _db.ApplicationUser.Find(tableHeader.UserId).Email; // End of Get Email (Please check if this code works first string Message = "Table Booking Approved"; return(RedirectToAction(nameof(ARBooking), new { message = Message })); }
public IActionResult CusCancelBooking(int TableHeaderId) { // Add Quantity back to Table Available if (!UpdateQuantity(TableHeaderId)) { return(NotFound()); // Or Can Return Error Message } TableBookingHeader tableHeader = _db.TableBookingHeader.Find(TableHeaderId); tableHeader.Status = SD.TableStatusCancelled; tableHeader.TimeRejected = DateTime.Now; tableHeader.RejectedBy = "Customer"; _db.SaveChanges(); var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == tableHeader.UserId).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + TableHeaderId + " - Cancelled", "Your Table Booking has been cancelled", "Your table booking details are as follows:", tableHeader); if (tableHeader.BookStatus != SD.BookTableStatusPending) { SendEmail("Rendezvous Restaurant", "*****@*****.**", "Table Booking : " + TableHeaderId + " - Customer Cancelled", string.Empty, "System message:<br />Customer Name: " + CustomerName + "<br />Customer Email: " + CustomerEmail + "<br />The above customer decided to cancel their table booking.<br /><br />", tableHeader); } return(RedirectToAction("Index", "TableBookingHistory")); }
public IActionResult CompleteSitIn(int TableHeaderId) { // Add Quantity back to Table Available if (!UpdateQuantity(TableHeaderId)) { return(NotFound()); // Or Can Return Error Message } TableBookingHeader tableHeader = _db.TableBookingHeader.Find(TableHeaderId); tableHeader.Status = SD.TableStatusCompleted; tableHeader.TimeCheckOut = DateTime.Now; TimeSpan SubtractQuan = tableHeader.TimeCheckOut.Value.Subtract(tableHeader.TimeSitIn.Value); double Hours = Math.Abs(SubtractQuan.Hours); double Min = Math.Abs(SubtractQuan.Minutes); double Secs = Math.Abs(SubtractQuan.Seconds); if (Hours > 0) { if (Min == 0) { tableHeader.Duration = Hours.ToString() + "hours"; } else { tableHeader.Duration = Hours.ToString() + " h " + Min.ToString(); } } else if (Min > 0) { tableHeader.Duration = Min.ToString() + " mins"; } else { tableHeader.Duration = Secs.ToString() + " secs"; } _db.SaveChanges(); //Email Logic to thank user for eating with us var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == tableHeader.UserId).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + TableHeaderId + " - Reservation Complete", "Your Table Booking reservation is completed", "We see that you have left at <p style= \"color:#FFFFFF\">" + tableHeader.TimeCheckOut.Value.ToString("MM/dd/yyyy HH:mm") + "</p>We hope that you enjoyed your time with us.<br />Have a safe journey to your destination.<br />We hope you eat with us again.", tableHeader); return(RedirectToAction(nameof(ManageBooking))); }
public IActionResult StartSitIn(int TableHeaderId) { TableBookingHeader tableHeader = _db.TableBookingHeader.Find(TableHeaderId); tableHeader.Status = SD.TableStatusStart; tableHeader.TimeSitIn = DateTime.Now; _db.SaveChanges(); var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == tableHeader.UserId).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + TableHeaderId + " - Reservation Started", "Your Table Booking reservation has started", "We see that your booking has started at <p style= \"color:#FFFFFF\">" + tableHeader.TimeSitIn.Value.ToString("MM/dd/yyyy HH:mm") + "</p>We hope that you enjoy your meal and that you are pleased with our service.", tableHeader); return(RedirectToAction(nameof(ManageBooking))); }
public void SendEmail(string Name, string Email, string Sub, string Body, TableBookingHeader objDetails) { try { var BusEmail = new MailAddress("*****@*****.**", "Rendezvous Restaurant"); var email = new MailAddress(Email, Name); var pass = "******"; var subject = Sub; var body = "Good day, <strong>" + Name + "</strong>.<br /><br />" + Body; body += "<br /><br /><table border =" + 1 + " cellpadding=" + 0 + " cellspacing=" + 0 + " width = " + 100 + "%><tr><th>Table Name</th><th>Number of Tables Booked</th><th>Date</th><th>Time</th></tr>"; body += "<tr><td>" + objDetails.TableName + "</td><td>" + objDetails.TableBooked + "</td><td>" + objDetails.SitInDate.ToString("MM/dd/yyyy") + "</td><td>"; body += objDetails.SitInTime.ToString(@"hh\:mm") + "</td></tr></table>"; body += "<br /><br />Have A Lovely day.<br/>The Rendezvous-Restaurant Team."; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(BusEmail.Address, pass) }; using (var message = new MailMessage(BusEmail, email) { Subject = subject, Body = body, IsBodyHtml = true }) { smtp.Send(message); } } catch (Exception ex) { } }
public void SendEmail(string Name, string Email, string Sub, string Heading, string Body, TableBookingHeader objDetails) { try { var BusEmail = new MailAddress("*****@*****.**", "Rendezvous Restaurant"); var email = new MailAddress(Email, Name); var pass = "******"; var subject = Sub; // var body = "Good day, <strong>" + Name // + "</strong>.<br /><br />" + Body; var PathToFile = _hostEnviroment.WebRootPath + Path.DirectorySeparatorChar.ToString() + "Templates" + Path.DirectorySeparatorChar.ToString() + "EmailTemplates" + Path.DirectorySeparatorChar.ToString() + "TableTemplate.htm"; string HtmlBody = ""; using (StreamReader streamReader = System.IO.File.OpenText(PathToFile)) { HtmlBody = streamReader.ReadToEnd(); } string Details = ""; if (objDetails != null) { Details += "<br /><br /><table border =" + 1 + " cellpadding=" + 0 + " cellspacing=" + 0 + " width = " + 100 + "%><tr><th>Table Name</th><th>Number of Tables Booked</th><th>Date</th><th>Time</th></tr>"; Details += "<tr><td>" + objDetails.TableName + "</td><td>" + objDetails.TableBooked + "</td><td>" + objDetails.SitInDate.ToString("MM/dd/yyyy") + "</td><td>"; Details += objDetails.SitInTime.ToString(@"hh\:mm") + "</td></tr></table>"; } HtmlBody = HtmlBody.Replace("#heading#", Heading); HtmlBody = HtmlBody.Replace("#details#", Body); HtmlBody = HtmlBody.Replace("#torder#", Details); if (Email.ToUpper() != "*****@*****.**") { HtmlBody = HtmlBody.Replace("#final#", "<br /><br />Have A Lovely day.<br/>The Rendezvous-Restaurant Team."); } else { HtmlBody = HtmlBody.Replace("#final#", "<br /><br />System Message."); } // body += "<br /><br />Have A Lovely day.<br/>The Rendezvous-Restaurant Team."; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(BusEmail.Address, pass) }; using (var message = new MailMessage(BusEmail, email) { Subject = subject, Body = HtmlBody, IsBodyHtml = true }) { smtp.Send(message); } } catch (Exception ex) { } }
public async Task <IActionResult> AddToTable(int?Quantity, int?TableTrackId) { if (Quantity.HasValue) { if (Quantity.Value <= 0) { return(RedirectToAction(nameof(Index))); } } if (!Quantity.HasValue || !TableTrackId.HasValue) { return(RedirectToAction(nameof(Index))); } var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var tableTrack = await _db.TableTrack.Include(t => t.Table).Where(t => t.Id == TableTrackId.Value).FirstOrDefaultAsync(); if (tableTrack == null) { return(RedirectToAction(nameof(Index))); } TableBookingHeader objTBH = new TableBookingHeader { UserId = claim.Value, DateBookingMade = SharedMethods.GetDateTime(), SitInDate = tableTrack.DateTable, SitInTime = tableTrack.TimeTable, TableName = tableTrack.Table.SeatingName, TableBooked = Quantity.Value, Status = SD.TableStatusSubmitted, BookStatus = SD.BookTableStatusPending, ApprovedBy = "", RejectedBy = "", TimeApproved = null, TimeCheckOut = null, TimeRejected = null, TimeSitIn = null, Duration = "" }; await _db.TableBookingHeader.AddAsync(objTBH); TableTrack objTT = await _db.TableTrack.FindAsync(tableTrack.Id); objTT.AmtAva -= Quantity.Value; await _db.SaveChangesAsync(); //Send Email var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == claim.Value).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + objTBH.Id + " - Received", "Your Table Booking has been received", "Thank you for your table booking, it is awaiting approval from the Admin.", objTBH); //End Send Email return(View("Confirm", objTBH)); }
public async Task <IActionResult> DeleteConfirmed(int?id) { var table = await _db.Table.FindAsync(id); if (table == null) { return(View()); } // Delete Image string webRootPath = _hostingEnvironment.WebRootPath; var imagePath = Path.Combine(webRootPath, table.Image.TrimStart('\\')); if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } //End Delete Image // Send Email to All pending and approved bookings for specific item that is being deleted // Inform Customers that the table is no longer available etc. /* * Following code is to remove all table tracks in TableTrack that is linked to the table being * deleted. */ var CheckTableTrack = await _db.TableTrack.Where(t => t.TableId == id).ToListAsync(); if (CheckTableTrack.Any()) { foreach (var item in CheckTableTrack) { TableTrack tableTrack = await _db.TableTrack.FindAsync(item.Id); _db.TableTrack.Remove(tableTrack); } } /* * Following code is to cancel/reject all bookings that have the soon to be deleted table name */ //Reject Pending Ones: var CheckTableHeaderPending = await _db.TableBookingHeader.Where(t => t.TableName == table.SeatingName && t.Status != SD.TableStatusCancelled && t.BookStatus == SD.BookTableStatusPending && t.SitInDate.Date >= DateTime.Now.Date).ToListAsync(); if (CheckTableHeaderPending.Any()) { foreach (var item in CheckTableHeaderPending) { TableBookingHeader tableHeader = _db.TableBookingHeader.Find(item.Id); tableHeader.BookStatus = SD.BookTableStatusRejected; tableHeader.TimeRejected = DateTime.Now; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var StaffName = _db.ApplicationUser.Where(a => a.Id == claim.Value).SingleOrDefault().Name; tableHeader.RejectedBy = StaffName; // Send Email saying their booking was rejected because table is unavailable var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == tableHeader.UserId).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + item.Id + " - Rejected", "The following table booking has been rejected:", tableHeader); } } //Cancel Approved Ones: var CheckTableHeaderApproved = await _db.TableBookingHeader.Where(t => t.TableName == table.SeatingName && t.BookStatus == SD.BookTableStatusApproved && t.Status == SD.TableStatusSubmitted && t.SitInDate.Date > DateTime.Now.Date).ToListAsync(); if (CheckTableHeaderApproved.Any()) { foreach (var item in CheckTableHeaderApproved) { TableBookingHeader tableHeader = _db.TableBookingHeader.Find(item.Id); tableHeader.Status = SD.TableStatusCancelled; tableHeader.TimeRejected = DateTime.Now; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var StaffName = _db.ApplicationUser.Where(a => a.Id == claim.Value).SingleOrDefault().Name; tableHeader.RejectedBy = StaffName; // Send Email saying their booking was cancelled because table is unavailable var CustomerInfo = _db.ApplicationUser.Where(u => u.Id == tableHeader.UserId).FirstOrDefault(); var CustomerEmail = CustomerInfo.Email; var CustomerName = CustomerInfo.Name; SendEmail(CustomerName, CustomerEmail, "Table Booking : " + item.Id + " - Cancelled", "The following table booking has been cancelled, we apologise for the inconvenience:", tableHeader); } } _db.Table.Remove(table); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }