MVC common controllers, interfaces, operations between data layers

Source: Internet
Author: User

User_books_info class

Namespace ciwong.learninglevel.mapping{public class User_books_info {//<summary>///Use Object ID,        The Personal Edition holds the member ID, the class edition holds the class ID, the campus edition holds the campus ID//</summary> public long user_id {get; set;} <summary>///Purchase type (1= personal version, 2 = Class Edition, 3 = School Edition)///</summary> public Int16 Purchase_type {get ; Set        }///<summary>//book ID///</summary> public long book_id {get; set;}        <summary>///Textbook name///</summary> public string Book_name {get; set;}        <summary>///Textbook cover///</summary> public string Book_cover {get; set;}        <summary>///Use object name///</summary> public string user_name {get; set;} <summary>///Use Type (0= trial, 1 = purchased, 2 = gift, 3 = school-based course)///</summary> public int Use_mode {get; Set }///<summary>//Add Time        </summary> public DateTime create_time {get; set;}        <summary>///First purchase time///</summary> public DateTime bourght_time {get; set;}         <summary>///Last Renewal time///</summary> public DateTime last_paid_time {get; set;}    <summary>///expiry time///</summary> public DateTime expire_date {get; set;} }}

  

1, data operation Layer (list<>)

<summary>///Receive books I have purchased///</summary>//<param name= "UserID" ></param> <param name= "PageIndex" > Page numbers </param>//<param name= "PageSize" > Number of Bars </param>/ <returns></returns> public list<user_books_info> userbookinfogetbyuserid (int userID, int pagei            ndex, int pageSize) {list<user_books_info> Booklist = new list<user_books_info> ();            String sql = @ "Call Learn_user_books_info_getbyuserid (@UserID, @pageIndex, @pageSize);"; Mysqlparameter[] para = new mysqlparameter[] {new MYSQLP Arameter ("@UserID", UserID), New Mysqlparameter ("@pageIndex", PageIndex), new Mysqlparamet            ER ("@pageSize", PageSize)};           using (var dr = Mysqlhelper.executereader (Databasemanager.retrieve ("Wc_learninglevel_read"), SQL, para)) {while (Dr.                    Read ()) {var bookInfo = new User_books_info (); bookinfo.user_id = Dr.                    GetInt32 ("user_id"); Bookinfo.purchase_type = Dr.                    GetInt16 ("Purchase_type"); bookinfo.book_id = Dr.                    GetInt64 ("book_id"); Bookinfo.book_name = Dr.                    GetString ("Book_name"); Bookinfo.book_cover = Dr.                    GetString ("Book_cover"); Bookinfo.user_name = Dr.                    GetString ("user_name"); Bookinfo.use_mode = Dr.                    GetInt32 ("Use_mode"); Bookinfo.create_time = Dr.                    GetDateTime ("Create_time"); Bookinfo.bourght_time = Dr.                    GetDateTime ("Bourght_time"); Bookinfo.last_paid_time = Dr.                    GetDateTime ("Last_paid_time"); Bookinfo.expire_date = Dr.                    GetDateTime ("Expire_date");                Booklist.add (BookInfo); } Dr.            Close (); } return BOOKLIst }

  

2, Data call interface layer (list<>)

        <summary>///        receive books I have purchased///</summary>//        <param name= "UserID" ></param> //        <param name= "pageIndex" > Page numbers </param>//        <param name= "PageSize" > Number of Bars </param>        <returns></returns>        list<user_books_info> userbookinfogetbyuserid (int userID, int PageIndex, int pageSize);    

  

3, CONTROLLER

Viewbag.userlearns = This._repository.userbookinfogetbyuserid (UserID, 1, 11);//Books purchased

A, data manipulation layer (ienumerable<>)

        <summary>///Get a list of articles//</summary>/<param name= "UserID" > User id</ param>//<param name= "Totalitem" > Total data Volume </param>//<param name= "PageIndex" > Current page </par am>//<param name= "pageSize" > Quantity per page </param>//<param name= "Isdelete" > Delete status &LT;/PARAM&G        T <returns></returns> Public ienumerable<blogcontent> getblogcontents (int. UserID, ref int Total Item, int pageIndex = 1, int pageSize = A, bool Isfriend = FALSE, bool Ismanager = false) {List<blo            gcontent> _list = new list<blogcontent> ();            Mysqlconnection conn = new mysqlconnection (ConnectionString);            Mysqldatareader dr = null; try {Conn.                Open (); Totalitem = Convert.ToInt32 (Mysqlhelper.executescalar (conn, String. Format ("Select COUNT (0) from Blogcontent WHERE [email protected] and IsdelEte=0 and ispublished=1 {0} ", Ismanager? String. Empty:isfriend?                 "And Ispublic<=1": "and Ispublic=0"), New Mysqlparameter ("@uid", UserID)); if (Totalitem > 0) {String sql = @ "SELECT Id,cateid,title,intro,publ                                   Ished,created, viewnums,copnums,ispublic,istop,ispublished, Iscopied,originid,uid,orignaccountid,originaccountname,flowers from Blogcontent WH ERE [email protected] and isdelete=0 and ispublished=1 {0} ORDER by Istop Desc,id D                    ESC LIMIT @Begin, @Size "; Dr = Mysqlhelper.executereader (conn, String. Format (SQL, Ismanager string. Empty:isfriend?                                "And Ispublic<=1": "and Ispublic=0"), New Mysqlparameter ("@uid", UserID), New Mysqlparameter ("@Begin", (pageIndex-1) * pageSize), new Mysqlparameter ("@Size", pageSize)); while (Dr. Read ()) {_list. ADD (New Blogcontent () {Id = Dr. GetInt64 (0), Cateid = Dr. GetInt64 (1), Title = Dr. GetString (2), Intro = Dr. GetString (3), Published = Dr. GetDateTime (4), Created = Dr. GetDateTime (5), viewnums = Dr. GetInt32 (6), copnums = Dr. GetInt32 (7), IsPublic = Dr. GetByte (8), istop = Dr. Getboolean (9), ispublished = Dr. Getboolean (ten), iscopied = Dr. Getboolean (one), originid = Dr. GetInt64 (), uid = Dr. GetInt32 (+), ORignaccountid = Dr. GetInt32 (+), Originaccountname = Dr. GetString (), Flower = Dr.                    GetInt32 (16)});            }}} catch (Mysqlexception e) {throw e; } finally {if (null! = DR) Dr.                Close (); Conn.            Close ();        } return _list; }

B, data manipulation Interface layer (ienumerable<>)

        <summary>///Get a list of articles//</summary>//        <param name= "UserID" > User ID Collection </param> //        <param name= "Totalitem" > Total data Volume </param>//        <param name= "pageIndex" > Current page </param>        //<param name= "pageSize" > Quantity per page </param>//        <param name= "Isdelete" > Delete status </param> //        <returns></returns>        Ienumerable<blogcontent> getblogcontents (list<int> userids, ref int Totalitem, int pageIndex = 1, int pageSiz E = c, bool Isfriend = FALSE, bool Ismanager = false);

  

C, CONTROLLER

var blogs1 = _blogmanager.getblogcontents (zone. UserID, ref totalitem, page, 10). ToList ();

  

MVC common controllers, interfaces, operations between data layers

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.