public OperationStatus ReportOffensiveCommunity(ReportEntityDetails offensiveCommunityDetails) { OperationStatus status = null; this.CheckNotNull(() => new { reportEntityDetails = offensiveCommunityDetails }); try { var offensiveCommunity = new OffensiveCommunities(); Mapper.Map(offensiveCommunityDetails, offensiveCommunity); offensiveCommunity.ReportedDatetime = DateTime.UtcNow; _offensiveCommunitiesRepository.Add(offensiveCommunity); _offensiveCommunitiesRepository.SaveChanges(); } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } // Status will be null if all sub communities and contents have been deleted. // If one them is not deleted then the status will have the exception details. status = status ?? OperationStatus.CreateSuccessStatus(); return(status); }
private void SendOffensiveEntityMail(ReportEntityDetails details, EntityType entityType) { //// TODO: Need to send mail asynchronously. try { // Send Mail. var request = new FlaggedRequest() { ID = details.ReportEntityID, EntityType = entityType, ParentID = details.ParentID, UserComments = details.Comment, FlaggedOn = DateTime.UtcNow, FlaggedAs = details.ReportEntityType.ToString(), UserID = details.ReportedByID, UserName = details.ReportedBy, UserLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", HttpContext.Request.Url.GetServerLink(), details.ReportedByID), }; switch (entityType) { case EntityType.Community: case EntityType.Folder: request.Link = string.Format(CultureInfo.InvariantCulture, "{0}Community/Index/{1}", HttpContext.Request.Url.GetServerLink(), details.ReportEntityID); break; default: request.Link = string.Format(CultureInfo.InvariantCulture, "{0}{1}/Index/{2}", HttpContext.Request.Url.GetServerLink(), entityType.ToString(), details.ReportEntityID); break; } _notificationService.NotifyFlagged(request); } catch (Exception) { // Ignore all exceptions. } }
[ValidateAntiForgeryToken]//http://stackoverflow.com/questions/10851283/antiforgerytoken-deprecated-in-asp-net-mvc-4-rc public string ReportEntity(long entityId, EntityType entityType, string comments, ReportEntityType offenceType) { var status = string.Empty; if (!string.IsNullOrWhiteSpace(comments)) { var report = new ReportEntityDetails() { Comment = comments, ReportEntityID = entityId, ParentID = entityId, Status = OffensiveStatusType.Flagged, ReportedByID = CurrentUserId, ReportEntityType = offenceType }; switch (entityType) { case EntityType.Community: case EntityType.Folder: _reportEntityService.ReportOffensiveCommunity(report); break; case EntityType.Content: _reportEntityService.ReportOffensiveContent(report); break; default: break; } // TODO: Only on succeeded we need to send the notification email. SendOffensiveEntityMail(report, entityType); } return(status); }