Beispiel #1
0
        public BlogApply SelectById(int id)
        {
            BlogApply result = null;

            using (MySqlConnection conn = new MySqlConnection(connStr))
            {
                conn.Open();
                var command = new MySqlCommand("select * from BlogApply where Id=@id", conn);
                command.Parameters.AddWithValue("@id", id);
                DbDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    result                  = new BlogApply();
                    result.Id               = reader.GetInt32(0);
                    result.UserId           = reader.GetInt32(1);
                    result.Reason           = reader.GetString(2);
                    result.RealName         = reader[3] == DBNull.Value ? null : reader[3].ToString();
                    result.Position         = reader[4] == DBNull.Value ? null : reader[4].ToString();
                    result.Unit             = reader[5] == DBNull.Value ? null : reader[5].ToString();
                    result.Interest         = reader[6] == DBNull.Value ? null : reader[6].ToString();
                    result.IsRead           = reader.GetBoolean(7);
                    result.LastModifiedTime = reader.GetDateTime(8);
                    result.CreateTime       = reader.GetDateTime(9);
                }
                conn.Close();
            }
            return(result);
        }
Beispiel #2
0
        public IEnumerable <BlogApply> SelectAll()
        {
            List <BlogApply> result = null;

            using (MySqlConnection conn = new MySqlConnection(connStr))
            {
                conn.Open();
                var command = new MySqlCommand("select * from BlogApply", conn);
                var reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    result = new List <BlogApply>();
                }
                while (reader.Read())
                {
                    var blogApply = new BlogApply();
                    blogApply.Id               = reader.GetInt32(0);
                    blogApply.UserId           = reader.GetInt32(1);
                    blogApply.Reason           = reader.GetString(2);
                    blogApply.RealName         = reader[3] == DBNull.Value ? null : reader[3].ToString();
                    blogApply.Position         = reader[4] == DBNull.Value ? null : reader[4].ToString();
                    blogApply.Unit             = reader[5] == DBNull.Value ? null : reader[5].ToString();
                    blogApply.Interest         = reader[6] == DBNull.Value ? null : reader[6].ToString();
                    blogApply.IsRead           = reader.GetBoolean(7);
                    blogApply.LastModifiedTime = reader.GetDateTime(8);
                    blogApply.CreateTime       = reader.GetDateTime(9);
                    result.Add(blogApply);
                }
                conn.Close();
            }
            return(result);
        }
Beispiel #3
0
        public ActionResult Apply(BlogApply info)
        {
            if (ModelState.IsValid)
            {
                var model = Mapper.Map <Blog>(info);
                model.AddTime  = DateTime.Now;
                model.EditTime = DateTime.Now;
                model.Status   = true;
                model.UserID   = LoginUser.ID;
                blogsdbContext.blog.Add(model);
                int res = blogsdbContext.SaveChanges();
                //TODO:把这里以后放到事务里面

                if (res > 0)
                {
                    LoginUser.BlogID = model.ID;
                    blogsdbContext.user.Attach(LoginUser);
                    blogsdbContext.Entry <User>(LoginUser).State = System.Data.Entity.EntityState.Modified;

                    Session["LoginBlog"] = model;
                    res = blogsdbContext.SaveChanges();
                    return(Content("申请成功"));
                }
            }
            return(View());
        }
Beispiel #4
0
        public void CreateBlogApply(int userId, BlogApplyViewModel model)
        {
            BlogApply blogApply = new BlogApply();

            blogApply.UserId           = userId;
            blogApply.RealName         = model.RealName;
            blogApply.Reason           = model.Reason;
            blogApply.Position         = model.Position;
            blogApply.Unit             = model.Unit;
            blogApply.Interest         = model.Interest;
            blogApply.LastModifiedTime = DateTime.Now;
            blogApply.CreateTime       = DateTime.Now;
            blogApply.IsRead           = false;
            blogApplyRepository.Insert(blogApply);
        }
Beispiel #5
0
 public void Insert(BlogApply blogApply)
 {
     using (var conn = new MySqlConnection(connStr))
     {
         conn.Open();
         var command = new MySqlCommand("insert into BlogApply(UserId,Reason,RealName,Position,Unit,Interest,IsRead,LastModifiedTime,CreateTime) values(@UserId,@Reason,@RealName,@Position,@Unit,@Interest,@IsRead,@LastModifiedTime,@CreateTime)", conn);
         command.Parameters.AddWithValue("@UserId", blogApply.UserId);
         command.Parameters.AddWithValue("@RealName", blogApply.RealName);
         command.Parameters.AddWithValue("@Reason", blogApply.Reason);
         command.Parameters.AddWithValue("@Position", blogApply.Position);
         command.Parameters.AddWithValue("@Unit", blogApply.Unit);
         command.Parameters.AddWithValue("@Interest", blogApply.Interest);
         command.Parameters.AddWithValue("@IsRead", blogApply.IsRead);
         command.Parameters.AddWithValue("@LastModifiedTime", blogApply.LastModifiedTime);
         command.Parameters.AddWithValue("@CreateTime", blogApply.CreateTime);
         command.ExecuteNonQuery();
         conn.Close();
     }
 }