/// <summary> /// 添加一个新闻类别 /// </summary> /// <param name="newsClassify"></param> /// <returns></returns> public ResponseModel AddNewsClassify(AddNewsClassify newsClassify) { //判断这个新闻类别是否存在 var exit = _db.NewsClassify.FirstOrDefault(c => c.Name == newsClassify.Name) != null; //如果存在,就返回已存在 if (exit) { return new ResponseModel { code = 0, result = "该类别已存在" } } ; //不存在就返回添加的newsclassify的实体 var classify = new NewsClassify { Name = newsClassify.Name, Sort = newsClassify.Sort, Remark = newsClassify.Remark }; _db.NewsClassify.Add(classify); //判断数据库返回值 int i = _db.SaveChanges(); if (i > 0) { return new ResponseModel { code = 200, result = "类别添加成功" } } ; return(new ResponseModel { code = 0, result = "类别添加失败!" }); }
/// <summary> /// 添加Banner /// </summary> /// <param name="banner"></param> /// <returns></returns> public ResponseModel AddBanner(AddBanner banner) { var ba = new Banner { AddTime = DateTime.Now, Image = banner.Image, Url = banner.Url, Remark = banner.Remark }; _db.Banner.Add(ba); int i = _db.SaveChanges(); if (i > 0) { return new ResponseModel { code = 200, result = "Banner添加成功" } } ; return(new ResponseModel { code = 0, result = "Banner添加失败" }); }