/// <summary> /// Update the comment, if authorized /// </summary> /// <param name="user">Editing user</param> /// <param name="text">The new text. If the text is unchanged, provide /// the original text. This lets you take whatever is in the user text box</param> /// <param name="image">New image to use (null if no change, don't need to reupload orig) </param> /// <param name="removeImage">Flag to indicate the image was removed, since null image is no-op</param> /// <param name="level"></param> public void Update(User user, string text, byte[] image, bool removeImage, CommentAccessLevel level) { AssertModifyAuthorization(user); if (removeImage) { Image = new byte[0]; } // Only update the image if there was one passed and there is // no instruction to remove it. If the image edit was a no-op, // it won't have been submitted and will be null, otherwise it's new if (image != null && !removeImage) { Image = image; } Text = text; LastEditorId = user.UserName; Modified = DateTime.Now; AccessLevel = level; AssociatedOrgId = GetAssociatedOrgId(user, level); _dao.Save(this); }
public static Comment AddComment(string nlihcId, User user, CommentAccessLevel level, string text, byte[] image) { var imageVal = image ?? new byte[] {}; var created = DateTime.Now; var comment = new Comment { NlihcId = nlihcId, AccessLevel = level, AssociatedOrgId = GetAssociatedOrgId(user, level), Created = created, Modified = created, Username = user.UserName, Text = text, Image = imageVal }; _dao.Insert(comment, true); return(comment); }
/// <summary> /// Set the comment's associated organization if the access /// level is restricted to a users organization /// </summary> /// <param name="user">User modifying the comment</param> /// <param name="level">Access Level of comment</param> /// <returns></returns> private static int?GetAssociatedOrgId(User user, CommentAccessLevel level) { return(level == CommentAccessLevel.SameOrg ? user.Organization : null); }