public ActionResult Create([Bind(Include = "PackageId,PkgName,PkgStartDate,PkgEndDate,PkgDesc,PkgBasePrice,PkgAgencyCommission")] Package package) { if (ModelState.IsValid) { string imageFile = package.PkgName + ".jpg"; db.Packages.Add(package); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(package)); }
public ActionResult Packages([Bind(Include = "BookingId,BookingDate,BookingNo,CustomerId,PackageId,TravelerCount,TripTypeId")] Booking bk) { if (ModelState.IsValid) //if all validation correct { //if a customer is interested in a package and logged in, it will display the package the customer already selected if (Session["SelectedPackageID"] != null) { int selectedPackageId = Convert.ToInt32(Session["SelectedPackageID"]); int customerId = Convert.ToInt32(Session["CustomerID"]); DateTime bookingDate = DateTime.Now; Booking booking = new Booking(); booking.PackageId = selectedPackageId; booking.CustomerId = customerId; booking.BookingDate = bookingDate; booking.BookingNo = RandomBookingNo().ToUpper() + selectedPackageId + bookingDate.Day + bk.TravelerCount; booking.TravelerCount = bk.TravelerCount; booking.TripTypeId = bk.TripTypeId; Package thisPackage = db.Packages.Find(selectedPackageId); Customer thisCustomer = db.Customers.Find(customerId); string summary = ((decimal)(booking.TravelerCount) * (thisPackage.PkgBasePrice)).ToString("C"); db.Bookings.Add(booking); db.SaveChanges(); ModelState.Clear(); ViewBag.SuccessMessage = "Booking Successful, Thank you for your purchase."; //After booking successfully, the page jump to the booking history of the customer string toEmail = thisCustomer.CustEmail; string subject = "Booking Confirmed"; string emailBody = $"<p>Hi {thisCustomer.CustFirstName},<br/>Thank you for your booking with Travel Experts.<br/>" + $"Your booking is: {thisPackage.PkgName}, start on {thisPackage.PkgStartDate} to {thisPackage.PkgEndDate}" + $" The travel count is {booking.TravelerCount}, the total charge is{summary} <br/> <br/>Travel Experts</p>"; var customercontroller = DependencyResolver.Current.GetService <CustomersController>(); var sendConfirmBookingEmail = customercontroller.SendEmail(toEmail, subject, emailBody); //string successMessage = "Booking Successful, Thank you for your purchase."; //ClientScript.RegisterOnSubmitStatement(this.GetType(), "ConfirmSubmit", successMessage); //System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('An booking email is sent to you.')</SCRIPT>"); return(RedirectToAction("Index", "Bookings")); } else { //if not booking correctly, the page return to the package list page. return(RedirectToAction("Index", "Packages")); } } //use DropDownList to select TripTypeId. display TTName, get TripTypeId. ViewBag.TripTypeId = new SelectList(db.TripTypes, "TripTypeId", "TTName", bk.TripTypeId); return(View(bk)); }
public ActionResult Registration(Customer customer) { try { using (var context = new TravelExpertsEntities3()) { var chkUser = (from s in context.Customers where s.CustUsername == customer.CustUsername select s).FirstOrDefault(); string name = customer.CustFirstName; //get the customer first name from the customer object string username = customer.CustUsername; //get the customer username from the customer object string userPassword = customer.CustPassword; //get the customer password from the customer object if (chkUser == null) { var password = Helper.HashEncrypt(customer.CustPassword); customer.CustPassword = password; customer.ConfirmPassword = password; context.Customers.Add(customer); context.SaveChanges(); SendEmail(customer.CustEmail, "Registration Confirmed", $"<p>Hi {name},<br/>Thank you for registering with Travel Experts where you explore, journey, discover and adventure.<br/>" + $"Your username: {username}<br/> Your password: {userPassword}<br/> <br/> Travel Experts</p>"); ModelState.Clear(); ModelState.Clear(); ViewBag.SuccessMessage = "Registration Successful"; //return RedirectToAction("LogIn", "Login"); } else { ViewBag.ErrorMessage = "Username Already Exists! Please enter a new username."; } return(View()); } } catch (Exception e) { ViewBag.ErrorMessage = "Some exception occured" + e; return(View()); } }
public ActionResult Update([Bind(Include = "CustomerId,CustFirstName,CustLastName,CustAddress,CustCity,CustProv,CustPostal,CustCountry,CustHomePhone,CustBusPhone,CustEmail,AgentId,CustUsername,CustPassword,ConfirmEmail,ConfirmPassword")] Customer customer) { try { if (ModelState.IsValid) { customer.CustPassword = Helper.HashEncrypt(customer.CustPassword); //hash the new password just before update into the database customer.ConfirmPassword = Helper.HashEncrypt(customer.ConfirmPassword); db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); Session.Clear(); Session.Abandon(); ViewBag.updateSuccessMessage = "Customer Update completed!!"; //ViewBag.AgentId = new SelectList(db.Agents, "AgentId", "AgtFirstName", customer.AgentId); return(RedirectToAction("Login")); } return(View(customer)); } catch (Exception e) { return(View(customer)); } }