public ActionResult ReportSpam(FormCollection form) { var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault(); SellerNotesReportedIssues spamnote = new SellerNotesReportedIssues(); int NoteID = Convert.ToInt32(form["noteid"]); if (!db.SellerNotesReportedIssues.Any(x => x.NoteID == NoteID && x.ReportedByID == user.ID)) { spamnote.NoteID = Convert.ToInt32(form["noteid"]); spamnote.AgainstDownloadID = Convert.ToInt32(form["downloadid"]); spamnote.ReportedByID = user.ID; spamnote.Remarks = form["spamreport"]; spamnote.CreatedDate = DateTime.Now; spamnote.CreatedBy = user.ID; db.SellerNotesReportedIssues.Add(spamnote); db.SaveChanges(); } else { var spamreport = db.SellerNotesReportedIssues.FirstOrDefault(x => x.NoteID == NoteID && x.ReportedByID == user.ID); spamreport.AgainstDownloadID = Convert.ToInt32(form["downloadid"]); spamreport.Remarks = form["spamreport"]; spamreport.ModifiedDate = DateTime.Now; spamreport.ModifiedBy = user.ID; db.SaveChanges(); } return(RedirectToAction("MyDownloads")); }
public ActionResult DeleteSpamReport(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SellerNotesReportedIssues report = objNotesEntities.SellerNotesReportedIssues.Find(id); if (report == null) { return(RedirectToAction("Error", "HomePage")); } objNotesEntities.SellerNotesReportedIssues.Remove(report); objNotesEntities.SaveChanges(); var Emailid = User.Identity.Name.ToString(); Users user = objNotesEntities.Users.Where(x => x.EmailId == Emailid).FirstOrDefault(); TempData["SpamReport"] = user.FirstName + " " + user.LastName; TempData["Message"] = ",Deleted Successfully !"; return(RedirectToAction("SpamReports", "Admin")); }
// intializing the template that we want to send to admin for marking note as inappropriate private void SpamReportTemplate(SellerNotesReportedIssues spam, string membername) { // take from, to, subject, body string from, to, body, subject; // get notes and user by using SellerNotesReportedIssue object var note = context.SellerNotes.Find(spam.NoteID); var seller = context.Users.Find(note.SellerID); // get support email var fromemail = context.SystemConfigurations.Where(x => x.Key == "supportemail").FirstOrDefault(); var fromEmailPassword = "******"; // Replace with original password //This mail goes to admin from system var tomail = context.SystemConfigurations.Where(x => x.Key == "adminemail").FirstOrDefault(); // set from, to, subject, body from = fromemail.Value.Trim(); to = tomail.Value.Trim(); subject = membername + " Reported an issue for " + note.Title; body = "Hello Admins" + "," + "<br/><br/>We want to inform you that, " + membername + " Reported an issue for " + seller.FirstName + " " + seller.LastName + "’s Note with " + "<br/>title " + note.Title + ". Please look at the notes and take required actions. " + "<br/><br/>Regards,<br/>Notes Marketplace"; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(from, fromEmailPassword) }; MailMessage mail = new MailMessage(); mail.From = new MailAddress(from, "NotesMarketplace"); mail.To.Add(new MailAddress(to)); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; smtp.Send(mail); }
// intializing the template that we want to send to admin for marking note as inappropriate private void SpamReportTemplate(SellerNotesReportedIssues spam, string membername) { string from, to, body, subject; // get all texts from SpamReport.cshtml from EmailTemplate body = System.IO.File.ReadAllText(HostingEnvironment.MapPath("~/EmailTemplate/") + "SpamReport" + ".cshtml"); // get notes and user by using SellerNotesReportedIssue object var note = context.SellerNotes.Find(spam.NoteID); var seller = context.Users.Find(note.SellerID); // replace some text with note title, seller name and user's name who mark this note as inappropriate body = body.Replace("ViewBag.SellerName", seller.FirstName + " " + seller.LastName); body = body.Replace("ViewBag.NoteTitle", note.Title); body = body.Replace("ViewBag.ReportedBy", membername); body = body.ToString(); // get support email var fromemail = context.SystemConfiguration.Where(x => x.Key == "supportemail").FirstOrDefault(); var tomail = context.SystemConfiguration.Where(x => x.Key == "notifyemail").FirstOrDefault(); // set from, to, subject, body from = fromemail.Value.Trim(); to = tomail.Value.Trim(); subject = membername + " Reported an issue for " + note.Title; StringBuilder sb = new StringBuilder(); sb.Append(body); body = sb.ToString(); // create object of MailMessage MailMessage mail = new MailMessage(); mail.From = new MailAddress(from, "NotesMarketplace"); mail.To.Add(new MailAddress(to)); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; // send mail (NotesMarketplace/SendMail/) SendingEmail.SendEmail(mail); }
public ActionResult SpamReport(FormCollection form) { // get download id by form int downloadid = Convert.ToInt32(form["downloadid"]); // get ReportedIssues object var alreadyreportedspam = context.SellerNotesReportedIssues.Where(x => x.AgainstDownloadsID == downloadid).FirstOrDefault(); // if user not slready reported spam if (alreadyreportedspam == null) { //get logged in user var user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault(); // store logged in user name into variable string membername = user.FirstName + " " + user.LastName; // create a spam report object SellerNotesReportedIssues spamnote = new SellerNotesReportedIssues(); spamnote.NoteID = Convert.ToInt32(form["noteid"]); spamnote.AgainstDownloadsID = downloadid; spamnote.ReportedByID = user.ID; spamnote.Remarks = form["spamreport"]; spamnote.CreatedDate = DateTime.Now; spamnote.CreatedBy = user.ID; // save spam report object into database context.SellerNotesReportedIssues.Add(spamnote); context.SaveChanges(); // send mail to admin that buyer reported the notes as inappropriate SpamReportTemplate(spamnote, membername); } return(RedirectToAction("MyDownloads")); }