public CreateNewCommentResponse CreateNewComment(CreateNewCommentRequest request) { var response = new CreateNewCommentResponse(); try { Guard.ArgNotNull(_unitOfWork.CommentRepository, "CommentRepository"); var comment = new Comment { Id = 0, LastModified = request.DateLastModified, Snippet_Id = request.SnippetId, User_Id = request.UserId, User_FormsAuthId = request.UserFormsAuthId, Text = request.Text }; _unitOfWork.CommentRepository.Insert(comment); _unitOfWork.Save(); int newId = comment.Id; if (newId > 0) { response.Success = true; response.Id = newId; response.SnippetId = request.SnippetId; response.UserFormsAuthId = request.UserFormsAuthId; response.UserId = request.UserId; response.Text = request.Text; response.DateLastModified = request.DateLastModified; Logger.LogInfo("Successfully created Comment Id: " + newId.ToString(), LogType.General); } } catch (Exception ex) { response.Success = false; response.FailureInformation = ex.Message; Logger.LogError("CreateNewComment Method Failed", ex); } return response; }
/// <summary> /// Create a new Comment object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="text">Initial value of the Text property.</param> /// <param name="lastModified">Initial value of the LastModified property.</param> /// <param name="snippet_Id">Initial value of the Snippet_Id property.</param> /// <param name="user_Id">Initial value of the User_Id property.</param> /// <param name="user_FormsAuthId">Initial value of the User_FormsAuthId property.</param> public static Comment CreateComment(global::System.Int32 id, global::System.String text, global::System.DateTime lastModified, global::System.Int32 snippet_Id, global::System.Int32 user_Id, global::System.Guid user_FormsAuthId) { Comment comment = new Comment(); comment.Id = id; comment.Text = text; comment.LastModified = lastModified; comment.Snippet_Id = snippet_Id; comment.User_Id = user_Id; comment.User_FormsAuthId = user_FormsAuthId; return comment; }
/// <summary> /// Deprecated Method for adding a new object to the Comments EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToComments(Comment comment) { base.AddObject("Comments", comment); }