Wojilu comments code analysis

Source: Internet
Author: User

Recently, a brief look at the wojilu comment function implementation, the author introduces the article (http://www.wojilu.com/Common/Page/52)

FileComment: ObjectBase <FileComment>, IComment

FileComment implements the IComment interface, which defines the behavior of a comment object.

In addition, FileCommentController: CommentController <FileComment>.

 

Public class CommentController <T>: ControllerBase where T: ObjectBase <T>, IComment

{
Public ICommentService <T> commentService {get; set ;}

}

CommentController combines CommentService <T> objects to manage comments.

Read the Create method in CommentController and Create comments.

[HttpPost, DbTransaction]
Public virtual void Create (int postId ){
......
IComment comment = Validate (postId); // verify and get a comment object
......
Result result = commentService. Insert (comment, lnkTarget); // Save the comment object to the database.
......
}

Public IComment Validate (int postId ){

IComment comment = Entity. New (typeof (T). FullName) as IComment; // generate a comment object
......
Comment. RootId = postId;
Comment. ParentId = ctx. PostInt ("ParentId ");
Comment. AppId = ctx. app. Id;
Comment. Author = userName;
Comment. Content = content;
Comment. Ip = ctx. Ip;
Comment. Created = DateTime. Now;

If (ctx. viewer. IsLogin ){
Comment. Member = (User) ctx. viewer. obj;
}
Return comment;
}

I learned a lot from this code, deepened my understanding of interface usage, and understood the concept of generic constraints.

IComment comment = Entity. New (typeof (T). FullName) as IComment; // generate a comment object

Now, you have time to learn more.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.