public ActionResult Contact([Bind(Include = "ID,Name,Email,PhoneNumber,Subject,Message,ViewStatus,DateSent")] ContactMessageModel contactsModel) { if (ModelState.IsValid) { try { contactsModel.ViewStatus = 0; db.ContactMessages.Add(contactsModel); db.SaveChanges(); TempData["SuccessMessage"] = "Thank you for getting in touch!"; //Send email to Gambia Review string to_name = GMailer.GetGambiaReviewName(); string h1_text = contactsModel.Subject; string h2_text = null; string p1_text = contactsModel.Message; string p2_text = null; AppEmailer.SendEmail(contactsModel.Email, contactsModel.Name, GMailer.GetGambiaReviewEmail(), to_name, contactsModel.Subject, h1_text, h2_text, p1_text, p2_text, null, null, null, null, null); return(RedirectToAction("Contact")); } catch (Exception ex) { TempData["ErrorMessage"] = "Failed to send message, please try again. If you continue to get this error, please send an email to [email protected]."; SecurityFunctions.LogError(ex, contactsModel.Email, "Contact", null); } } return(View(contactsModel)); }
public ActionResult Register(AccountsModel accountmodel) { var returnController = "Home"; var returnAction = "Index"; if (!string.IsNullOrEmpty(Request.Form["returnController"]) && !string.IsNullOrEmpty(Request.Form["returnAction"])) { returnController = Request.Form["returnController"]; returnAction = Request.Form["returnAction"]; } if (ModelState.IsValid) { //Set default values for account var confirm_password = Request.Form["RepeatPassword"]; //If passwords do not match if (accountmodel.Password != confirm_password) { TempData["ProcessRegisterFailureMessage"] = "Passwords do not match."; TempData["displayModal"] = "registerModal"; return(RedirectToAction(returnAction, returnController)); } //Check if email exist already if (db.Accounts.Where(s => s.Email == accountmodel.Email).Any()) { TempData["ProcessRegisterFailureMessage"] = "The email provided already exist, please try again with a different email."; TempData["displayModal"] = "registerModal"; return(RedirectToAction(returnAction, returnController)); } //Add registration if (SecurityFunctions.AddNewRegistration(accountmodel.Email, accountmodel.Password, false)) { string to_name = AppFunctions.FirstLetterToUpper(AppFunctions.GetUsernameFromEmail(accountmodel.Email)); string h1_text = "Welcome to Gambia Review."; string h2_text = null; string p1_text = "You've successfully registered in Gambia Review application system."; string p2_text = "You can contact us by phone +7 (495) 280-14- 81 (ext. 3397) or by using the feedback form, which is presented on the questionnaire page. Our staff will promptly provide answers to your questions. You can fill in the questionnaire sections in any order convenient for you."; //Send email to registerer AppEmailer.SendEmail(GMailer.GetGambiaReviewEmail(), "Gambia Review", accountmodel.Email, to_name, "Welcome to Gambia Review", h1_text, h2_text, p1_text, p2_text, null, null, null, null, null); //Send email to Gambia Review to_name = "Gambia Review Team"; h1_text = "New User Registered"; h2_text = null; p1_text = "User with email :" + accountmodel.Email + " has registered."; p2_text = null; AppEmailer.SendEmail(GMailer.GetGambiaReviewEmail(), "Gambia Review", "*****@*****.**", to_name, "Welcome to Gambia Review", h1_text, h2_text, p1_text, p2_text, null, null, null, null, null); //Add Login data var SessionID = SecurityFunctions.ComputeSha256Hash(AppFunctions.RandomString(12).ToString()); if (!SecurityFunctions.AddLoginInfo(accountmodel.Email, DateTime.Now, 0, 0, null, 0, SessionID, DateTime.Now)) { //Think of what to do here //Log Error } TempData["ProcessSuccessMessage"] = "Registration successfull."; SecurityFunctions Security = new SecurityFunctions(); Session["sessionID"] = SessionID; Session["sessionEmail"] = accountmodel.Email; Session["sessionFullName"] = Security.ReturnAccountData(accountmodel.Email, "FirstName") + " " + Security.ReturnAccountData(accountmodel.Email, "LastName"); if (string.IsNullOrEmpty(Security.ReturnAccountData(accountmodel.Email, "FirstName"))) { Session["sessionFullName"] = accountmodel.Email; } Session["sessionProfilePic"] = Security.ReturnAccountData(accountmodel.Email, "DirectoryName") + "/" + Security.ReturnAccountProfilePic(accountmodel.Email); if (string.IsNullOrEmpty(Security.ReturnAccountData(accountmodel.Email, "DirectoryName"))) { Session["sessionProfilePic"] = AppFunctions.GetDefaultProfileLink(); } return(RedirectToAction("Index", "Home")); } else { TempData["ProcessFailureMessage"] = "Registration failed, please try again."; return(RedirectToAction(returnAction, returnController)); } } else { StringBuilder result = new StringBuilder(); foreach (var item in ModelState) { string key = item.Key; var errors = item.Value.Errors; foreach (var error in errors) { result.Append(key + " " + error.ErrorMessage + "#"); } } TempData["ProcessRegisterFailureMessage"] = result.ToString(); TempData["displayModal"] = "registerModal"; } return(RedirectToAction(returnAction, returnController)); }