/// <summary> /// 获取文章扩展数据 /// </summary> /// <returns></returns> public ArticleExtend GetData(string unionID) { var nowDate = DateTime.Now; if (nowDate.TimeOfDay < DateTime.MinValue.AddHours(4).TimeOfDay) { nowDate = nowDate.AddDays(-1); } var model = DataProvider.GetAll_Article().OrderByDescending(x => x.CreateTime).FirstOrDefault(x => SqlFunctions.DateDiff("d", x.ArticleDate, nowDate) == 0).ToExtendModel(); if (model == null) { throw new Exception("文章数据为空"); } var list = DataProvider.GetAll_ArticleOperating().Where(x => x.ArticleID == model.ID).ToList(); model.ArticleLike = list.Where(x => x.Like).Count(); model.ArticleComment = DataProvider.GetAll_Comment().Where(x => x.ArticleID == model.ID).Count(); //model.ArticleForward = list.Where(x => x.Forward).Count(); //model.ArticleViews = list.Count; if (!string.IsNullOrEmpty(unionID)) { var operating = list.FirstOrDefault(x => x.UnionID == unionID); if (operating != null) { model.Like = operating.Like; model.Favorite = operating.Favorite; model.Forward = operating.Forward; } else { if (DataProvider.GetAll_WeCharUserInfo().FirstOrDefault(x => x.UnionID == unionID) == null) { throw new Exception("不存在该账号"); } ArticleOperating operatingModel = new ArticleOperating(); operatingModel.ID = Guid.NewGuid(); operatingModel.CraeteTime = DateTime.Now; operatingModel.ArticleID = model.ID; operatingModel.UnionID = unionID; DataProvider.Create(operatingModel); } } return(model); }
/// <summary> /// 删 - 删除单条数据 /// </summary> /// <param name="model"></param> public void Delete(ArticleOperating model) { context.ArticleOperating.Remove(model); Save(); }
/// <summary> /// 增 - 添加单条数据 /// </summary> /// <param name="model"></param> public void Create(ArticleOperating model) { context.ArticleOperating.Add(model); Save(); }
public static ArticleOperatingDomain ToDomainModel(this ArticleOperating model) { return(Mapper.Map <ArticleOperatingDomain>(model)); }