public ActionResult Register(Customer user) { // Upload var file = Request.Files["UpPhoto"]; if (file.ContentLength > 0) { user.Photo = file.FileName; file.SaveAs(Server.MapPath("~/Images/Customers/" + user.Photo)); } else { user.Photo = "user.png"; } // Insert try { user.Activated = false; dbc.Customers.Add(user); dbc.SaveChanges(); // Gửi mail var url = Request.Url.AbsoluteUri.Replace("Register", "Activate/" + user.Id.ToBase64()); var body = "Vui lòng click vào liên kết sau để <a href='" + url + "'>kích hoạt</a>"; XMailer.Send(user.Email, "Welcome to EShop", body); ModelState.AddModelError("", "Đăng ký thành công!"); } catch { ModelState.AddModelError("", "Đăng ký thất bại!"); } return(View()); }
public ActionResult Send(int Id, String From, String To, String Subject, String Body) { var url = Request.Url.AbsoluteUri.Replace("Send", "Detail/" + Id); Body += "<hr><a href='" + url + "'>Chi tiết</a>"; XMailer.Send(To, Subject, Body, From); return(Content("Gửi mail thành công!")); }
public ActionResult Register(Customer model) { model.Activated = false; try { dbc.Customers.Add(model); dbc.SaveChanges(); ModelState.AddModelError("", "Dang ky thanh cong!"); //Gui mail var href = "http://localhost:54916/Account/Activate/" + model.Id; XMailer.Send(model.Email, "Welcome", "<a href='" + href + "'>Activate</a>"); } catch { ModelState.AddModelError("", "Dang ky that bai!"); } return(View()); }
public ActionResult Forgot(String Id, String Email) { var user = dbc.Customers.Find(Id); if (user == null) { ModelState.AddModelError("", "Sai tên đăng nhâp!"); } else if (user.Email != Email) { ModelState.AddModelError("", "Sai địa chỉ email!"); } else { XMailer.Send(Email, "Quên mật khẩu", user.Password); ModelState.AddModelError("", "Mật khẩu đã được gửi qua email!"); } return(View()); }
public ActionResult Forgot(String Id, String Email) { var user = dbc.Customers.Find(Id); if (user == null) { ModelState.AddModelError("", "Sai ten dang nhap!"); } else if (user.Email != Email) { ModelState.AddModelError("", "Sai email dang ky!"); } else { // Gui mail XMailer.Send(Email, "Forgot password", user.Password); ModelState.AddModelError("", "Mat khau da duoc gui qua email!"); } return(View()); }
public ActionResult Index(HttpPostedFileBase ImageUpload, HttpPostedFileBase ImageMagazineUpload, string Comment, DateTime SentDate, int SemesterId, bool Agree) { ViewBag.SemesterId = new SelectList(dbc.Semesters, "Id", "Name"); Magazine magazine2 = new Magazine(); magazine2.SentDate = DateTime.Now; var message = ""; var url = ""; var urlmagazine = ""; var studentId = Session["Student"] as Student; if (ImageUpload != null) { url = Guid.NewGuid() + ImageUpload.FileName.Substring(ImageUpload.FileName.LastIndexOf(".")); ImageUpload.SaveAs(Server.MapPath("~/images/products/" + url)); } else { url = "Product.png"; } if (ImageMagazineUpload != null) { urlmagazine = Guid.NewGuid() + ImageMagazineUpload.FileName.Substring(ImageMagazineUpload.FileName.LastIndexOf(".")); ImageMagazineUpload.SaveAs(Server.MapPath("~/images/magazine/" + urlmagazine)); } else { urlmagazine = "product.png"; } Magazine magazine = new Magazine { Comment = Comment, SemesterId = SemesterId, SentDate = SentDate, StudentId = studentId.Id, Url = url, MagazineUrl = urlmagazine }; try { var seme = dbc.Semesters.Find(SemesterId); var moderator = dbc.Students.AsNoTracking().SingleOrDefault(a => a.Id == studentId.Id); var deadlin = seme.EndDate; if (seme != null) { if (Agree == true) { if (DateTime.Compare(SentDate, deadlin) > 0) { message = "Hết hạn gửi bài"; } else { dbc.Magazines.Add(magazine); dbc.SaveChanges(); var cordinator = moderator.Coordinator.Email; XMailer.Send(cordinator, "Notication", "Student" + studentId.FullName + "Have upload new record "); message = "Submit Successfully"; } } else { message = "You have to agree with our policy"; } } ViewBag.message = message; } catch (Exception) { } return(View(magazine2)); }