private void Resource_Change(Book obj)
        {
            var context = WebRepoFactory.CreateRepo <UserResourceIndex>();
            var urs     = context.Where(r => r.ResourceIndexId == obj.ResourceIndex.Id).Select(r => r.User).ToList();

            if (urs.Count() > 0)
            {
                foreach (var item in urs)
                {
                    var temp = new BookUserMsg()
                    {
                        UserMsg = new UserMsg()
                        {
                            User = item,
                            Msg  = "更新提示"
                        },
                        LastChapterUrl = obj.LastChapterUrl,
                        LastChapter    = obj.LastChapter,
                        BookId         = obj.ResourceIndexId
                    };
                    WebRepoFactory.CreateRepo <BookUserMsg>(context.dbContext).Insert(temp);
                }
                context.Save();
            }
        }
Esempio n. 2
0
        public List <Book> GetRemindBook(User user)
        {
            var urContext = WebRepoFactory.CreateRepo <UserResourceIndex>(Repo.dbContext);
            var ids       = urContext.Where(r => r.UserId == user.Id).Select(r => r.ResourceIndex.Id);
            var books     = Repo.Where(r => ids.Contains(r.ResourceIndexId)).Include(r => r.ResourceIndex);

            return(books.ToList());
        }
Esempio n. 3
0
        public ActionResult Index(string initKey, string type, string siteType)
        {
            var obj = WebRepoFactory.CreateRepo <BookUserMsg>().GetAll().ToList();

            ViewData["initKey"]    = initKey != null ? initKey : "";
            ViewData["type"]       = type != null ? type : "";
            ViewData["siteType"]   = siteType != null ? siteType : "";
            ViewData["searchType"] = Enum.GetNames(typeof(BookSearchType));
            return(View());
        }
Esempio n. 4
0
        public ValidationResult AddRemindBook(string resourceId, ResourceFromSite site, User user)
        {
            if (site == null || user == null || resourceId == null)
            {
                return(new ValidationResult("服务器错误,请刷新后重试"));
            }
            using (var scope = new System.Transactions.TransactionScope())
            {
                var userRoleContext = WebRepoFactory.CreateRepo <UserResourceIndex>(Repo.dbContext);
                try
                {
                    var data = MemoryCacheProvider.Cache.Get(resourceId + site.ToString()) as SearchBook;

                    var modelcontext = WebRepoFactory.CreateRepo <ResourceIndex>(userRoleContext.dbContext);

                    var resource = modelcontext.GetAll().FirstOrDefault(r => r.ResourceId == resourceId && r.ResourceFromsite == site);

                    if (resource == null)
                    {
                        resource = new ResourceIndex()
                        {
                            Name             = data.BookName,
                            ResourceFromsite = site,
                            ResourceId       = resourceId,
                            ResourceType     = ResourceType.小说,
                            SubscribeNum     = 1,
                            Url        = data.BookUrl,
                            CreatedBy  = user.UserName,
                            CreatedOn  = DateTime.Now,
                            ModifiedBy = user.UserName,
                            ModifiedOn = DateTime.Now,
                        };
                        Repo.Insert(new Book()
                        {
                            AuthorName     = " " + data.AuthorName,
                            ImgUrl         = data.ImgUrl,
                            ResourceIndex  = resource,
                            Description    = data.Description.Trim(),
                            LastChapter    = data.LastChapter,
                            LastChapterUrl = data.LastChapterUrl
                        });
                        userRoleContext.Insert(new UserResourceIndex()
                        {
                            ResourceIndex = resource,
                            UserId        = user.Id
                        });
                    }
                    else
                    {
                        if (userRoleContext.GetAll().Any(r => r.ResourceIndexId == resource.Id && r.UserId == user.Id))
                        {
                            return(new ValidationResult("用户已经订阅个信息"));
                        }
                        resource.SubscribeNum += 1;
                        userRoleContext.Insert(new UserResourceIndex()
                        {
                            ResourceIndex = resource,
                            UserId        = user.Id
                        });
                    }
                    userRoleContext.Save();
                    scope.Complete();
                }
                catch (Exception e)
                {
                    LogHelper.error(e.Message);
                    return(new ValidationResult(e.Message));
                }
            }
            return(null);
        }