/// <summary>
        /// 添加Blog
        /// </summary>
        /// <param name="blog"></param>
        /// <returns></returns>
        public async Task <ResponseModel> AddBlog(AddBlog blog)
        {
            _context.Blogs.Add(new BlogInfo
            {
                Title      = blog.Title,
                Abstr      = blog.Abstr,
                CreateTime = DateTime.Now,
                CategoryId = blog.CategoryId,
                Content    = new BContent {
                    Content = blog.Content
                }
            });
            var i = await _context.SaveChangesAsync();

            if (i > 0)
            {
                return new ResponseModel()
                       {
                           code = 200, result = "Blog添加成功", data = ""
                       }
            }
            ;
            else
            {
                return new ResponseModel()
                       {
                           code = 0, result = "Blog添加失败", data = ""
                       }
            };
        }
        public async Task <ResponseModel> UpdateAdmin(UpdataAdmin admin)
        {
            var result = await _context.Admins.FirstOrDefaultAsync();

            result.Password = admin.Password;
            result.NickName = admin.NickName;
            result.Email    = admin.Email;
            var i = await _context.SaveChangesAsync();

            if (i > 0)
            {
                return new ResponseModel()
                       {
                           code = 200, result = "Admin信息修改成功", data = ""
                       }
            }
            ;
            else
            {
                return new ResponseModel()
                       {
                           code = 0, result = "Admin信息修改失败", data = ""
                       }
            };
        }
        public async Task <ResponseModel> AddDiary(string Content)
        {
            _context.Diarys.Add(new Diary {
                Content = Content, CreateTime = DateTime.Now.ToString()
            });
            var i = await _context.SaveChangesAsync();

            if (i > 0)
            {
                return new ResponseModel()
                       {
                           code = 200, result = "日记添加成功", data = ""
                       }
            }
            ;
            else
            {
                return new ResponseModel()
                       {
                           code = 0, result = "日记添加失败", data = ""
                       }
            };
        }
Exemple #4
0
        /// <summary>
        /// 添加类别服务
        /// </summary>
        /// <param name="CategoryName">类别名</param>
        /// <returns></returns>
        public async Task <ResponseModel> AddCategory(string CategoryName)
        {
            _context.Categorys.Add(new Category {
                CategoryName = CategoryName, CreateTime = DateTime.Now
            });
            var i = await _context.SaveChangesAsync();

            if (i > 0)
            {
                return new ResponseModel()
                       {
                           code = 200, result = "类别添加成功", data = ""
                       }
            }
            ;
            else
            {
                return new ResponseModel()
                       {
                           code = 0, result = "类别添加失败", data = ""
                       }
            };
        }