public InformationContent GetSingleInformationContent(int appUserId = 0) { List <int> readList = informationReadLogOperation.GetReadedInformationContentByAppUserId(appUserId); InformationContent informationContent = new InformationContent(); if (appUserId != 0) { informationContent = context.InformationContent.Include(s => s.Author).Include(a => a.Category).Where(s => s.IsActive && !s.IsDeleted && !readList.Contains(s.InformationContentId)).OrderBy(s => Guid.NewGuid()).Take(1).SingleOrDefault(); if (informationContent != null) { DATA.Models.InformationReadLog informationReadLog = new DATA.Models.InformationReadLog() { AppUserId = appUserId, CreateDate = DateTime.Now, InformationContentId = informationContent.InformationContentId, IsActive = true, IsDeleted = false, }; informationReadLogOperation.InsertInformationContentReadList(informationReadLog); } } else { informationContent = context.InformationContent.Where(s => s.IsActive && !s.IsDeleted).OrderBy(s => Guid.NewGuid()).Take(1).SingleOrDefault(); } return(informationContent); }
public void InsertInformationContentReadList(DATA.Models.InformationReadLog informationReadLog) { context.InformationReadLog.Add(informationReadLog); context.SaveChanges(); }