public ActionResult ChangeEmail(ChangeEmailViewModel model) { if (TravelExpertsData.IsUniqueEmail(model.NewEmail, out string error)) { Customer curr = GetCurrentCustomer(); // make sure we found customer if (curr == null) { ModelState.AddModelError(String.Empty, "Sorry an error occured while trying to find you. Please try log in again."); return(View()); } curr.CustEmail = model.NewEmail; if (model.Update(curr)) { return(RedirectToAction("Index", new { Message = ManageMessageId.EditEmailSuccess })); } // something went wrong return(RedirectToAction("Index", new { Message = ManageMessageId.Error })); } // an account is already linked if (!string.IsNullOrEmpty(error)) { ModelState.AddModelError(string.Empty, "An account is already linked to this email."); } return(View()); }
// GET: /Manage/BookingDetails /// <summary> /// Serve booking details page /// </summary> /// @author - Harry public ActionResult BookingDetails(string bookingNo) { // make sure we have a booking number if (bookingNo == null) { return(RedirectToAction("Index")); } // put booking number in bag ViewBag.BookingNo = bookingNo; // get customer Customer curr = GetCurrentCustomer(); List <BookingDetail> details = TravelExpertsData.GetBookingDetails(curr, bookingNo); List <Fee> fees = new List <Fee>(); // get each booking details fee foreach (BookingDetail detail in details) { fees.Add(TravelExpertsData.GetFee(curr, detail.BookingDetailId)); } // set up model var model = new BookingDetailsViewModel { Details = details, Fees = fees }; return(View(model)); }
/// <summary> /// get current customer /// </summary> /// @author Harry private Customer GetCurrentCustomer() { var userId = User.Identity.GetUserId(); // get current customer email string email = TravelExpertsData.GetEmailInAccount(userId); if (email == null) { return(null); } // get current customer by email return(TravelExpertsData.GetCustomer(email)); }
// // GET: /Manage/Index public ActionResult Index(ManageMessageId?message) { ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set." : message == ManageMessageId.Error ? "An error has occurred. Unable to perform change." : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added." : message == ManageMessageId.EditPhoneSuccess ? "Phone number changed." : message == ManageMessageId.EditAddressSuccess ? "Address changed." : message == ManageMessageId.EditUserNameSuccess ? "User name changed." : message == ManageMessageId.EditEmailSuccess ? "Email changed." : message == ManageMessageId.EditAddressSuccess ? "Address changed." : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed." : ""; // get current customer by email Customer curr = GetCurrentCustomer(); if (curr == null) // couldn't find account or user { ViewBag.ErrorMsg = "We're sorry, an error has occured while trying to get your information."; return(View()); } // get customer bookings List <Booking> bookings = TravelExpertsData.GetBookings(curr); var model = new IndexViewModel { HasPassword = HasPassword(), UserName = curr.UserName, FirstName = curr.CustFirstName, LastName = curr.CustLastName, Address = curr.CustAddress, City = curr.CustCity, Prov = curr.CustProv, Postal = curr.CustPostal, Country = curr.CustCountry, HomePhone = curr.CustHomePhone, BusPhone = curr.CustBusPhone, Email = curr.CustEmail, Bookings = bookings }; return(View(model)); }
public ActionResult ChangeBusPhone(ChangeBusPhoneViewModel model) { string notUnique = ""; if (Validator.IsCanadianPhoneNumber(model.NewBusPhoneNumber, out string invalid) && TravelExpertsData.IsUniquePhone(model.NewBusPhoneNumber, out notUnique)) { Customer curr = GetCurrentCustomer(); // make sure we found customer if (curr == null) { ModelState.AddModelError(String.Empty, "Sorry an error occured while trying to find you. Please try log in again."); return(View()); } curr.CustBusPhone = model.NewBusPhoneNumber; if (model.Update(curr)) { return(RedirectToAction("Index", new { Message = ManageMessageId.EditPhoneSuccess })); } // something went wrong return(RedirectToAction("Index", new { Message = ManageMessageId.Error })); } // made it here, something went wrong if (!string.IsNullOrEmpty(invalid)) { ModelState.AddModelError(String.Empty, "Invalid phone number."); } if (!string.IsNullOrEmpty(notUnique)) { ModelState.AddModelError(String.Empty, "An account is already linked to this number."); } return(View()); }
public ActionResult ChangeUserName(ChangeUserNameViewModel model) { if (TravelExpertsData.IsUniqueUserName(model.NewUserName)) { Customer curr = GetCurrentCustomer(); // make sure we found customer if (curr == null) { ModelState.AddModelError(String.Empty, "Sorry an error occured while trying to find you. Please try log in again."); return(View()); } curr.UserName = model.NewUserName; if (TravelExpertsData.UpdateCustomerUserName(curr) && TravelExpertsData.UpdateAccountUserName(curr)) { return(RedirectToAction("Index", new { Message = ManageMessageId.EditUserNameSuccess })); } // something went wrong return(RedirectToAction("Index", new { Message = ManageMessageId.Error })); } ModelState.AddModelError(String.Empty, "Account is already linked to this user name."); return(View()); }
public async Task <ActionResult> Register(RegisterViewModel model) { // error message assignments string postalError = ""; string homePhoneError = ""; string busPhoneError = ""; string emailError = ""; // some further validation if (ModelState.IsValid && Validator.IsCanadianPostal(model.CustPostal, out postalError) && (string.IsNullOrEmpty(model.CustHomePhone) || Validator.IsCanadianPhoneNumber(model.CustHomePhone, out homePhoneError)) && // databse allows null for home phone number Validator.IsCanadianPhoneNumber(model.CustBusPhone, out busPhoneError) && TravelExpertsData.IsUniqueEmail(model.CustEmail, out emailError) && TravelExpertsData.IsUniquePhone(model.CustBusPhone, out busPhoneError)) { // transform form data to customer object Customer newCustomer = new Customer { CustomerId = model.CustomerId, CustFirstName = model.CustFirstName, CustLastName = model.CustLastName, CustAddress = model.CustAddress, CustCity = model.CustCity, CustProv = model.CustProv, CustPostal = model.CustPostal, CustCountry = model.CustCountry, CustHomePhone = model.CustHomePhone, CustBusPhone = model.CustBusPhone, CustEmail = model.CustEmail, UserName = model.UserName }; // is customer in database and just needs account? if (!TravelExpertsData.CustomerExists(newCustomer)) // customer is not in Customer table, so add (account can't exist if customer is not in customer table) { TravelExpertsData.InsertCustomer(newCustomer); } else if (!TravelExpertsData.AccountExists(newCustomer)) // customer does not have an account { // Customer exists in Customer table but not in Accounts table TravelExpertsData.UpdateCustomerUserName(newCustomer); // add user name to Customer Table and AspNetUsers table TravelExpertsData.UpdateCustomerEmail(newCustomer); // lots of empty string emails in Customer table, may as well update here } // auto-generated - create User var user = new ApplicationUser { UserName = model.UserName, Email = model.CustEmail, PhoneNumber = model.CustBusPhone }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) // registration in Accounts tables success { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // format phone number errors to be more informative if (!string.IsNullOrEmpty(homePhoneError)) { homePhoneError = $"{homePhoneError} (home phone number)\n\teg. 4031234567"; ModelState.AddModelError(string.Empty, homePhoneError); } if (!string.IsNullOrEmpty(busPhoneError)) { busPhoneError = $"{busPhoneError} (business phone number)\n\teg. 4031234567"; ModelState.AddModelError(string.Empty, busPhoneError); } // email already taken if (!string.IsNullOrEmpty(emailError)) { ModelState.AddModelError(string.Empty, emailError); } // add error messages to model if (!string.IsNullOrEmpty(postalError)) { ModelState.AddModelError(string.Empty, postalError); } // If we got this far, something failed, redisplay form return(View(model)); }