public ActionResult Report(ReportNoteModel Rm)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Authentication", new { ReturnUrl = @"/RegisteredUser/Downloads" }));
            }

            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }

            int UserID = Convert.ToInt32(User.Identity.Name);

            if (NotesRepository.SubmitNoteReport(Rm, UserID))
            {
                ViewBag.SellerName = Rm.SellerName;
                ViewBag.NoteName   = Rm.NoteTitle;
                ViewBag.BuyerName  = Session["FullName"];
                SendMail.SendEmail(new EmailModel()
                {
                    EmailTo      = SystemConfigData.GetSystemConfigData("AdminEmails").DataValue.Split(';'),
                    EmailSubject = Session["FullName"].ToString() + " reported an issue for " + Rm.NoteTitle,
                    EmailBody    = this.getHTMLViewAsString("~/Views/Email/ReportedNote.cshtml")
                });

                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK));
            }
            else
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden));
            }
        }
Пример #2
0
        /* Submits Note Report
         * Returns false if fails or not allowed to report or already reported
         * Return True if successfully submitted
         * */
        public static bool SubmitNoteReport(ReportNoteModel Rm, int UserID)
        {
            using (var context = new NotesMarketPlaceEntities())
            {
                var IsAllowedToRate = context.Downloads.FirstOrDefault(dwn => dwn.NoteID == Rm.NoteID && dwn.BuyerID == UserID && dwn.IsAllowed && dwn.IsDownloaded);
                if (IsAllowedToRate == null)
                {
                    return(false); //Not allowed
                }
                else
                {
                    NotesReport NR = context.NotesReports.FirstOrDefault(nr => nr.NoteID == Rm.NoteID && nr.BuyerID == UserID);
                    if (NR != null)
                    {
                        return(false); // cause one can not change report
                    }
                    else
                    {
                        context.NotesReports.Add(new NotesReport()
                        {
                            NoteID       = Rm.NoteID,
                            BuyerID      = UserID,
                            Remarks      = Rm.Remarks,
                            CreatedBy    = UserID,
                            CreatedDate  = System.DateTime.Now,
                            ModifiedBy   = UserID,
                            ModifiedDate = System.DateTime.Now,
                            DownloadID   = IsAllowedToRate.DownloadID
                        });

                        var Seller = context.Users.FirstOrDefault(u => u.UserID == IsAllowedToRate.SellerID);

                        Rm.SellerName = Seller.FirstName + " " + Seller.LastName;

                        Rm.NoteTitle = IsAllowedToRate.NoteTitle;
                    }
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                        return(false);
                    }
                    return(true);
                }
            }
        }
        public ActionResult Report(int NoteID)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Authentication", new { ReturnUrl = @"/RegisteredUser/Downloads" }));
            }

            int UserID = Convert.ToInt32(User.Identity.Name);

            ReportNoteModel Report = NotesRepository.GetNoteReport(NoteID, UserID);

            if (Report.NoteID == -1)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden));
            }
            else
            {
                if (Report.Remarks != null)
                {
                    ModelState.AddModelError("Remarks", "You already reported this note once.");
                }
                return(PartialView("~/Views/RegisteredUser/_ReportNotePopupModal.cshtml", Report));
            }
        }