public ActionResult Add(int earningID, bool earningIsAchievement, String text) { /* TODO: if(WebSecurity.CurrentUserId < 0) { return new HttpStatusCodeResult(401, "Custom Error Message 1"); // Unauthorized }*/ // Need text for a comment if (String.IsNullOrWhiteSpace(text)) { return new HttpStatusCodeResult(406, "Invalid comment text"); // Invalid text } UnitOfWork work = new UnitOfWork(); // Are comments enabled, and can we access the earning? user earningUser = null; object template = null; if (!CommentsEnabled(earningID, earningIsAchievement, work)) { return new HttpStatusCodeResult(403, "Comments currently disabled"); // Disabled comments } if (!UserCanAccessEarning(earningID, earningIsAchievement, work, out earningUser, out template)) { return new HttpStatusCodeResult(403, "Earning cannot be accessed"); // Invalid earning access } comment c = new comment() { date = DateTime.Now, deleted = false, last_modified_by_id = WebSecurity.CurrentUserId, last_modified_date = null, // Not being modified, just created, so this is null location_id = earningID, location_type = earningIsAchievement ? (int)JPPConstants.CommentLocation.Achievement : (int)JPPConstants.CommentLocation.Quest, text = text, user_id = WebSecurity.CurrentUserId }; // Access is validated, create comment work.EntityContext.comment.Add(c); // Get the current user's display name user u = work.EntityContext.user.Find(WebSecurity.CurrentUserId); //ID, Photo, Name, Text, PosterID, Deleted // Send a notification /*if (earningIsAchievement) { achievement_template a = template as achievement_template; work.SystemRepository.AddNotification( earningUser.id, WebSecurity.CurrentUserId, "[" + u.display_name + "] commented on [" + a.title + "]", u.image, new UrlHelper(Request.RequestContext).Action( "IndividualAchievement", "Achievements", new { id = a.id } ) + "#" + earningUser.id + "-" + earningID, false); } else { quest_template q = template as quest_template; work.SystemRepository.AddNotification( earningUser.id, WebSecurity.CurrentUserId, "[" + u.display_name + "] commented on [" + q.title + "]", u.image, new UrlHelper(Request.RequestContext).Action( "IndividualQuest", "Quests", new { id = q.id } ) + "#" + earningUser.id + "-" + earningID, false); }*/ // Success work.SaveChanges(); EarningComment response = new EarningComment() { Deleted = false, ID = c.id, Text = c.text, PlayerID = u.id, DisplayName = u.display_name, PlayerImage = u.image, CommentDate = c.date, CurrentUserCanEdit = true, CurrentUserCanDelete = true }; return Json(response); }