Esempio n. 1
0
        public async Task <IHttpActionResult> ReportPost(int Post_Id, int ReportType, string Text)
        {
            try
            {
                var userId = Convert.ToInt32(User.GetClaimValue("userid"));

                using (RiscoContext ctx = new RiscoContext())
                {
                    ReportPost reportPost = new ReportPost
                    {
                        User_Id     = userId,
                        Post_Id     = Post_Id,
                        ReportType  = ReportType,
                        Text        = Text,
                        CreatedDate = DateTime.UtcNow
                    };

                    ctx.ReportPosts.Add(reportPost);
                    ctx.SaveChanges();

                    CustomResponse <ReportPost> response = new CustomResponse <ReportPost>
                    {
                        Message    = Global.ResponseMessages.Success,
                        StatusCode = (int)HttpStatusCode.OK,
                        Result     = reportPost
                    };
                    return(Ok(response));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(Utility.LogError(ex)));
            }
        }
Esempio n. 2
0
        public RedirectToRouteResult DeleteConfirmed(int id, int?page)
        {
            if (Session[User.Identity.GetUserId()] == null)
            {
                return(RedirectToAction("ConfirmationContinue", "Account", new { area = "", Url = Request.Url, UrlReferrer = Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : Url.Action("Index", "Home") }));
            }
            ReportPost report = db.ReportPosts.Find(id);

            db.ReportPosts.Remove(report);
            db.SaveChanges();
            return(RedirectToAction("Index", new { page = page ?? 1 }));
        }
Esempio n. 3
0
        public void CreateReport(string reason, string postId, string reportedUserId, string reporterId)
        {
            var report = new ReportPost
            {
                Reason     = reason,
                PostId     = postId,
                UploaderId = reportedUserId,
                ReporterId = reporterId,
                CreatedOn  = DateTime.Now,
            };

            this.context.ReportPosts.Add(report);
            this.context.SaveChanges();
        }
Esempio n. 4
0
        public void Handle(ReportPost command)
        {
            if (string.IsNullOrEmpty(command.Reason))
            {
                return;
            }
            if (command.Reason.Length > 200)
            {
                command.Reason = command.Reason.Substring(0, 200);
            }

            var user = _membershipService.GetUserById(command.ReportBy);

            if (user == null)
            {
                return;
            }

            var post = _postService.GetPostById(command.PostId);

            if (post == null)
            {
                return;
            }

            // did a mod/admin configure this post to ignore any reports?
            if (post.IgnoreReports)
            {
                return;
            }

            // the user can't report things in a sub they are banned from
            if (_subUserBanService.IsUserBannedFromSub(post.SubId, user.Id))
            {
                return;
            }

            // make sure the user hasn't already report the comment
            var currentReports = _reportService.GetReportsForPost(post.Id);

            if (currentReports.Any(x => x.ReportedBy == user.Id))
            {
                return;
            }

            _reportService.ReportPost(post.Id, user.Id, command.Reason);

            _postService.UpdateNumberOfReportsForPost(post.Id, currentReports.Count + 1);
        }
Esempio n. 5
0
        public ActionResult Delete(int?id, int?page)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }
            if (Session[User.Identity.GetUserId()] == null)
            {
                return(RedirectToAction("ConfirmationContinue", "Account", new { area = "", Url = Request.Url, UrlReferrer = Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : Url.Action("Index", "Home") }));
            }
            ReportPost report = db.ReportPosts.Find(id);

            if (report == null)
            {
                return(RedirectToAction("PageNotFound", "StaticContent", new { area = "" }));
            }
            return(View());
        }
Esempio n. 6
0
 public ActionResult <List <Report> > PostReport([FromBody] ReportPost report)
 {
     try
     {
         var ReportList = _webAddressVerification.ReportRequestGet(report.Status, report.FromDate, report.ToDate, report.CallerId, report.Street);
         if (ReportList?.Count > 0)
         {
             return(Ok(ReportList));
         }
         else
         {
             return(NotFound());
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message, e.StackTrace);
         return(StatusCode(500));
     }
 }
Esempio n. 7
0
        public void DeleteReportShouldDeleteReportById()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteReportShouldDeleteReportById")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var reportService = new ReportService(dbContext);

            var report = new ReportPost();

            dbContext.ReportPosts.Add(report);
            dbContext.SaveChanges();

            reportService.DeleteReport(report.Id);

            var reports = dbContext.ReportPosts.ToList();

            Assert.Empty(reports);
        }
Esempio n. 8
0
        public async Task <ActionResult <ReportPost> > PostReportPost(ReportPost reportPost)
        {
            _context.ReportPosts.Add(reportPost);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (LikeReportPostExists(reportPost.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(reportPost);
        }
Esempio n. 9
0
        public async Task <ActionResult> AddReport(ReportPost reportPost, string alias)
        {
            try
            {
                reportPost.DateReport = DateTime.Now;
                if (ModelState.IsValid)
                {
                    db.ReportPosts.Add(reportPost);
                    await db.SaveChangesAsync();

                    string message = "Báo sai phạm thành công. Xin cảm ơn.";
                    return(RedirectToAction("Detail", new { id = reportPost.PostID, alias = alias, reportMessage = message }));
                }
                else
                {
                    return(RedirectToAction("Detail", new { id = reportPost.PostID, alias = alias, errorMessage = "Xảy ra lỗi khi báo sai phạm bài viết này" }));
                }
            }
            catch
            {
                return(RedirectToAction("Detail", new { id = reportPost.PostID, alias = alias, errorMessage = "Xảy ra lỗi khi báo sai phạm bài viết này" }));
            }
        }
        // POST: api/Report
        public string Post(ReportWrapper report)
        {
            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Headers["PayeBash"] != null)
            {
                PayeDBEntities db = new PayeDBEntities();
                if (report.ComplainantId != null &&
                    report.Type != null)
                {
                    var             complainantId = db.Users.FirstOrDefault(i => i.UserId.ToString() == report.ComplainantId).Id;
                    /*long*/ string userId        = "0";
                    long            postId        = 0;
                    int             cnt           = 0;
                    if (!string.IsNullOrEmpty(report.UserId))
                    {
                        userId = db.Users.FirstOrDefault(i => i.UserId.ToString() == report.UserId).Id;
                        cnt    = db.ReportPosts.Where(i => i.ComplainantId == complainantId && i.UserId == userId).Count();
                    }

                    else if (!string.IsNullOrEmpty(report.PostId))
                    {
                        postId = db.Posts.Where(r => r.postId.ToString() == report.PostId).FirstOrDefault().Id;
                        cnt    = db.ReportPosts.Where(i => i.ComplainantId == complainantId && i.PostId == postId).Count();
                    }


                    if (cnt > 0)
                    {
                        var record = db.ReportPosts.FirstOrDefault(i => i.ComplainantId == complainantId && (i.PostId == postId || i.UserId == userId));
                        record.Type            = report.Type;
                        record.Modifiedate     = DateTime.Now;
                        db.Entry(record).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        return("گزارش شما با موفقیت ثبت گردید");
                    }
                    else
                    {
                        try
                        {
                            ReportPost tb = new ReportPost();
                            tb.ComplainantId = complainantId;
                            tb.PostId        = postId;
                            tb.UserId        = userId;
                            tb.Type          = report.Type;
                            tb.Status        = false;
                            tb.Modifiedate   = DateTime.Now;
                            db.ReportPosts.Add(tb);
                            db.SaveChanges();

                            return("گزارش شما با موفقیت ثبت گردید");;
                        }
                        catch (Exception ex)
                        {
                            return("خطا در ارسال");
                        }
                    }
                }
                else
                {
                    return("خطا در ارسال");
                }
            }
            return(null);
        }