public bool DeleteBooking(string bookingId) { try { int bId = int.Parse(bookingId); BookingEntities ctx = new BookingEntities(); BoatBooking b = ctx.BoatBooking.Where(x => x.Id == bId).First(); BookingCancelledModel cm = new BookingCancelledModel { UserEmail = b.Member.Email, UserName = b.Member.Name, SailingClub = ConfigurationManager.AppSettings["SailingClub"], Signature = ConfigurationManager.AppSettings["Signature"], BookingReference = b.BookingMemberId.ToString() + "/" + b.Id.ToString(), BookingDate = b.BookingDate }; ctx.BoatBooking.Remove(b); ctx.SaveChanges(); UserMailer um = new UserMailer(); MvcMailMessage msg = um.BoatCancelledTreasurer(cm); msg.Send(); return(true); } catch (Exception) { return(false); } }
public ActionResult Register(CoupleUser CoupleUser) { if (ModelState.IsValid) { CoupleUser.Couple.User = CoupleUser.User; db.Couple.Add(CoupleUser.Couple); db.SaveChanges(); var email = new MvcMailMessage { Subject = "Confirmação de Email" }; email.To.Add(CoupleUser.User.Email); email.ViewName = "Welcome"; email.Send(); return(RedirectToAction("SignIn", "User", CoupleUser.User)); } else { return(View("Create", CoupleUser.User)); } }
public void TestSend() { _mailMessage.Send(_smtpClient); Assert.Pass("Mail Send working since no exception wast thrown"); }
public bool BookBoat(string bookingDate, string boatId) { BoatBooking b = null; BookingEntities ctx = null;; try { ctx = new BookingEntities(); int bId = int.Parse(boatId); Member booker = (Member)ctx.Member.Where(m => m.UserProfileId == WebSecurity.CurrentUserId).First(); Boat boat = (Boat)ctx.Boat.Find(bId); DateTime bd = DateTime.Parse(bookingDate); decimal cost = booker.Age < 18 ? 0.0m : boat.RentalCost; b = new BoatBooking { BookingDate = bd, BoatId = boat.Id, BookingMemberId = booker.Id, Units = 1, UnitCost = cost, TotalCost = cost }; ctx.BoatBooking.Add(b); ctx.SaveChanges(); b = ctx.BoatBooking.Where((bb) => bb.BookingMemberId == b.BookingMemberId && bb.BookingDate == b.BookingDate && bb.BoatId == b.BoatId).First(); BoatBookedModel mailModel = new BoatBookedModel { BoatName = boat.Make + " " + boat.Class + " " + boat.SailNumber, BookingDate = bd, Cost = cost, UserEmail = booker.Email, UserName = booker.Name, SailingClub = ConfigurationManager.AppSettings["SailingClub"], Signature = ConfigurationManager.AppSettings["Signature"], BookingReference = b.BookingMemberId.ToString() + "/" + b.Id.ToString() }; UserMailer um = new UserMailer(); MvcMailMessage msgUser = um.BoatBookedUser(mailModel); MvcMailMessage msgTreasurer = um.BoatBookedTreasurer(mailModel); msgUser.Send(); msgTreasurer.Send(); return(true); } catch { if (b != null && b.Id > 0) { if (ctx != null) { ctx.BoatBooking.Remove(b); ctx.SaveChanges(); } } return(false); } finally { if (ctx != null) { ctx.Dispose(); } } }
public ActionResult EmailToUser(EmailViewModel viewModel) { // Check model state if (!ModelState.IsValid) { ViewBag.Result = false; ViewBag.ResultMessage = "Lütfen belirtilen alanları doldurunuz!"; return(PartialView("_EmailToUser", viewModel)); } try { var fromUserName = WebSecurity.CurrentUserName; var toUser = _context.UserProfiles.FirstOrDefault(p => p.UserId == viewModel.ToUserId); const string view = "EmailTemplate"; var header = string.Format("{0}", viewModel.Subject); var content = viewModel.Body; //... // Check to user email info if (toUser == null) { ViewBag.Result = false; ViewBag.ResultMessage = "Kullanıcı bilgisi bulunamadı!"; return(PartialView("_EmailToUser", viewModel)); } if (string.IsNullOrWhiteSpace(toUser.Email)) { ViewBag.Result = false; ViewBag.ResultMessage = "Kullanıcı email bilgisi bulunamadı!"; return(PartialView("_EmailToUser", viewModel)); } //... // Log sent email var emailLog = new EmailLog { EmailTypeId = 2, FromUserId = WebSecurity.GetUserId(fromUserName), ToUserId = toUser.UserId, Header = header, Content = content, CreateDate = DateTime.Now }; _context.EmailLogs.Add(emailLog); _context.SaveChanges(); //... // Send email header = string.Format("{0} kullanıcısı size bir mesaj gönderdi!", fromUserName); content = string.Format( @"{0} kullanıcısı size {1} başlıklı mesaj gönderdi.<br/> Mesajı okumak için lütfen <a href='http://estudybase.com/Email/EmailBox?EmailId={2}'>tıklayınız.</a>", fromUserName, viewModel.Subject, emailLog.EmailId); MvcMailMessage mvcMailMessage = UserMailer.SendEmail(view, header, content, toUser.Email); mvcMailMessage.Send(); ViewBag.Result = true; ViewBag.ResultMessage = "Email başarıyla gönderildi!"; return(PartialView("_EmailToUser", viewModel)); } catch (Exception exception) { throw new Exception("Error in EmailController.EmailToUser [Post]", exception); } }
public ActionResult ResetPassword(string un, string rt) { //... // Get userid of received username var userId = (from i in _context.UserProfiles where i.UserName == un select i.UserId).FirstOrDefault(); //... // Check UserId and token matches bool any = (from j in _context.WebpagesMemberships where (j.UserId == userId) && (j.PasswordVerificationToken == rt) //&& (j.PasswordVerificationTokenExpirationDate < DateTime.Now) select j).Any(); if (!any) { ViewBag.Result = false; ViewBag.ResultMessage = "Kullanıcı adı ve kod uyuşmuyor!"; return(View()); } // ... // Generate random password string newpassword = GenerateRandomPassword(6); //... // Reset password bool response = WebSecurity.ResetPassword(rt, newpassword); if (response) { //... // Get user email address to send password var email = (from i in _context.UserProfiles where i.UserName == un select i.Email).FirstOrDefault(); //... //Send email const string view = "EmailTemplate"; const string header = "Şifreniz değiştirildi!"; var content = string.Format("Yeni şifreniz <b>{0}</b>", newpassword); try { //... // Send email MvcMailMessage mvcMailMessage = UserMailer.SendEmail(view, header, content, email); mvcMailMessage.Send(); //... // Log sent email var emailLog = new EmailLog { EmailTypeId = 1, ToUserId = userId, Header = header, Content = content, CreateDate = DateTime.Now }; _context.EmailLogs.Add(emailLog); _context.SaveChanges(); ViewBag.Result = true; ViewBag.ResultMessage = string.Format("Şifreniz değiştirildi! Yeni şifreniz <b>{0}</b>", newpassword); return(View()); } catch (Exception ex) { ViewBag.Result = false; ViewBag.ResultMessage = string.Format("Email gönderilirken hata oluştu, lütfen tekrar deneyiniz."); return(View()); } } else { ViewBag.Result = false; ViewBag.ResultMessage = "Yanlış kullanıcı adı girdiniz!"; return(View()); } }
//[ValidateAntiForgeryToken] public ActionResult ForgotPassword(string userName) { //... // Check user existance var user = Membership.GetUser(userName); if (user == null) { ViewBag.Result = false; ViewBag.ResultMessage = "Kullanıcı bilgisi bulunamadı!"; return(PartialView()); } else { //... // Generate password token var token = WebSecurity.GeneratePasswordResetToken(userName); //... // Create url with above token var resetLink = string.Format("<a href='{0}'>Şifre Sıfırla</a>", Url.Action("ResetPassword", "Account", new { un = userName, rt = token }, "http")); //... // Get user email address var userEmail = (from i in _context.UserProfiles where i.UserName == userName select i.Email).FirstOrDefault(); //... // Send mail const string view = "EmailTemplate"; const string header = "Şifre Tanımlama"; var body = string.Format("Şifrenizi yeniden tanımlamak için lütfen linke tıklayınız <br/>{0}", resetLink); try { //... // Send email MvcMailMessage mvcMailMessage = UserMailer.SendEmail(view, header, body, userEmail); mvcMailMessage.Send(); //... // Log sent email var emailLog = new EmailLog { EmailTypeId = 1, ToUserId = WebSecurity.GetUserId(user.UserName), Header = header, Content = body, CreateDate = DateTime.Now }; _context.EmailLogs.Add(emailLog); _context.SaveChanges(); ViewBag.Result = true; ViewBag.ResultMessage = "Şifrenizi tanımlamak için emailinize gönderilen linki tıklayınız."; return(PartialView()); } catch (Exception ex) { ViewBag.Result = false; ViewBag.ResultMessage = string.Format("Email gönderilirken hata oluştu, lütfen tekrar deneyiniz."); return(PartialView()); } } }