示例#1
0
        public ActionResult ResetPassword(Guid id, string code)
        {
            var model = new FeUserAccountCheckCode();

            try
            {
                User u;

                using (var db = new CoreCmsDbContext())
                {
                    u = db.Users.SingleOrDefault(i => i.Id == id);
                }

                if (u == null)
                {
                    model.ErrorMessage = "Not found user";
                }

                MemoryMessageBuss.PushCommand(new ResetUserPassword(id, code, DateTime.Now));

                model.Success = true;
            }
            catch (Exception ex)
            {
                model.ErrorMessage = ex.GetMessages();
            }

            return(View(model));
        }
示例#2
0
        public List <MenuItem> MainMenu()
        {
            List <Category>        cat = new List <Category>();
            List <ContentLanguage> contentLanguages = null;

            using (var db = new CoreCmsDbContext())
            {
                contentLanguages = db.ContentLanguages.Join(db.Categories, cl => cl.Id, c => c.Id,
                                                            (cl, c) => new { Cl = cl, C = c })
                                   .Select(i => i.Cl).ToList();
                cat = db.Categories.Where(i => i.ShowInFrontEnd).ToList();
            }

            return(cat.Where(i => i.ParentId == null || i.ParentId == Guid.Empty).Select(c => new MenuItem()
            {
                Id = c.Id,
                Title = contentLanguages.GetValue(c.Id, "Title"),
                SeoUrlFriendly = contentLanguages.GetValue(c.Id, "SeoUrlFriendly")
                ,
                DisplayOrder = c.DisplayOrder,
                SubItems = cat.Where(i => i.ParentId == c.Id)
                           .Select(s => new MenuItem()
                {
                    Id = s.Id,
                    Title = contentLanguages.GetValue(s.Id, "Title"),
                    DisplayOrder = s.DisplayOrder,
                    SeoUrlFriendly = contentLanguages.GetValue(s.Id, "SeoUrlFriendly")
                }).OrderBy(i => i.DisplayOrder).ToList()
            }).OrderBy(i => i.DisplayOrder).ToList());
        }
示例#3
0
        private static List <News> ResultNoKeywords(List <Guid> categoryIds, out List <ContentLanguage> contentLanguages, bool isSearchWithCategory,
                                                    Expression <Func <News, bool> > newsPredicate, int xskip, int xtake, out long total)
        {
            using (var db = new CoreCmsDbContext())
            {
                var tempNoKeywords = db.News.AsQueryable();

                if (isSearchWithCategory)
                {
                    tempNoKeywords = tempNoKeywords.Join(db.RelationShips, n => n.Id, rs => rs.ToId,
                                                         (n, rs) => new { N = n, Rs = rs })
                                     .Where(m => categoryIds.Contains(m.Rs.FromId)).Select(i => i.N).Distinct();
                }

                total = tempNoKeywords.LongCount();

                var resultNoKeywords = tempNoKeywords.Where(newsPredicate)
                                       .OrderBy(i => i.CreatedDate)
                                       .Skip(xskip)
                                       .Take(xtake)
                                       .ToList();

                var newsIdWithEmptyKeywords = resultNoKeywords.Select(i => i.Id).ToList();

                contentLanguages = db.ContentLanguages.Where(i => newsIdWithEmptyKeywords.Contains(i.Id)).ToList();

                return(resultNoKeywords);
            }
        }
示例#4
0
        public JsonResult ListHomePageSection()
        {
            List <ContentLanguage> contentLangs;
            List <HomePageSettingsAdminPage.Section> sections;

            using (var db = new CoreCmsDbContext())
            {
                sections = db.HomePageSections.OrderBy(i => i.DisplayOrder)
                           .Select(i => new HomePageSettingsAdminPage.Section()
                {
                    Id                      = i.Id,
                    Published               = i.Published,
                    CategoryId              = i.CategoryId,
                    DisplayOrder            = i.DisplayOrder,
                    HomePageSectionViewName = i.HomePageSectionViewName,
                }).ToList();

                var ids = sections.Select(i => i.Id).ToList();
                ids.AddRange(sections.Select(i => i.CategoryId).ToList());

                contentLangs = db.ContentLanguages.Where(i => ids.Contains(i.Id)).ToList();
            }

            foreach (var ms in sections)
            {
                ms.Title         = contentLangs.GetValue(ms.Id, "Title");
                ms.CategoryTitle = contentLangs.GetValue(ms.CategoryId, "Title");
            }

            return(Json(new { sections.Count, rows = sections, success = true }, JsonRequestBehavior.AllowGet));
        }
示例#5
0
 public void Handle(CategoryChangedDisplayOrder e)
 {
     using (var db = new CoreCmsDbContext())
     {
         var temp = db.Categories.SingleOrDefault(i => i.Id.Equals(e.Id));
         if (temp != null)
         {
             temp.DisplayOrder = e.DisplayOrder;
         }
         db.SaveChanges();
     }
 }
示例#6
0
 public void Handle(NewsUnpublished e)
 {
     using (var db = new CoreCmsDbContext())
     {
         var temp = db.News.SingleOrDefault(i => i.Id == e.Id);
         if (temp != null)
         {
             temp.Published = false;
         }
         db.SaveChanges();
     }
 }
示例#7
0
 public void Handle(CategoryDeleted e)
 {
     using (var db = new CoreCmsDbContext())
     {
         var temp = db.Categories.SingleOrDefault(i => i.Id.Equals(e.Id));
         if (temp != null)
         {
             temp.Deleted = true;
         }
         db.SaveChanges();
     }
 }
示例#8
0
 public void Handle(CategoryRootChanged e)
 {
     using (var db = new CoreCmsDbContext())
     {
         var temp = db.Categories.SingleOrDefault(i => i.Id.Equals(e.Id));
         if (temp != null)
         {
             temp.ParentId = e.ParentId;
         }
         db.SaveChanges();
     }
 }
示例#9
0
 public void Handle(NewsUpdated e)
 {
     using (var db = new CoreCmsDbContext())
     {
         var temp = db.News.SingleOrDefault(i => i.Id == e.Id);
         if (temp != null)
         {
             temp.AllowComment = e.AllowComment;
             db.SaveChanges();
         }
     }
 }
        public static List <FeSearchResult> Search(string keywords, Guid?languageId, List <Guid> categoryIds
                                                   , int skip, int take)
        {
            if (string.IsNullOrEmpty(keywords))
            {
                return(new List <FeSearchResult>());
            }
            skip = skip * 3;
            take = take * 3;
            List <ContentLanguage> idsFound = null;

            using (var db = new CoreCmsDbContext())
            {
                var idsQuery = db.ContentLanguages.Where(i => i.ColumnValue.Contains(keywords));
                if (languageId != null)
                {
                    idsQuery = idsQuery.Where(i => i.LanguageId == languageId);
                }
                if (categoryIds != null && categoryIds.Count > 0)
                {
                    idsQuery = idsQuery.Join(db.RelationShips, cl => cl.Id, rs => rs.ToId,
                                             (cl, rs) => new { Cl = cl, Rs = rs })
                               .Where(m => categoryIds.Contains(m.Rs.FromId))
                               .Select(m => m.Cl);
                }
                var ids = idsQuery.OrderByDescending(i => i.CreatedDate)
                          .Skip(skip).Take(take)
                          .Select(i => i.Id).Distinct().ToList();

                idsFound = db.ContentLanguages.Where(i => ids.Contains(i.Id))
                           .Where(i => i.ColumnName.Equals("Title", StringComparison.OrdinalIgnoreCase) ||
                                  i.ColumnName.Equals("SeoUrlFriendly", StringComparison.OrdinalIgnoreCase) ||
                                  i.ColumnName.Equals("UrlImage", StringComparison.OrdinalIgnoreCase))
                           .OrderByDescending(i => i.CreatedDate)
                           .Skip(skip).Take(take).ToList();
            }
            List <FeSearchResult> result = new List <FeSearchResult>();

            foreach (var cl in idsFound)
            {
                var r = new FeSearchResult();
                r.Id             = cl.Id;
                r.Title          = cl.ColumnName.Equals("Title", StringComparison.OrdinalIgnoreCase) ? cl.ColumnValue : idsFound.GetValue(r.Id, "Title");
                r.SeoUrlFriendly = cl.ColumnName.Equals("SeoUrlFriendly", StringComparison.OrdinalIgnoreCase) ? cl.ColumnValue : idsFound.GetValue(r.Id, "SeoUrlFriendly");
                r.UrlImage       = cl.ColumnName.Equals("UrlImage", StringComparison.OrdinalIgnoreCase) ? cl.ColumnValue : idsFound.GetValue(r.Id, "UrlImage");
                r.TableName      = cl.TableName;
                result.Add(r);
            }

            return(result.DistinctBy(i => i.SeoUrlFriendly).ToList());
        }
示例#11
0
 public void Handle(NewsCreated e)
 {
     using (var db = new CoreCmsDbContext())
     {
         db.News.Add(new News()
         {
             Id           = e.Id,
             ParentId     = e.ParentId,
             CreatedDate  = e.CreatedDate,
             AllowComment = e.AllowComment
         });
         db.SaveChanges();
     }
 }
        public void Handle(PublishHomePageSection c)
        {
            HomePageSection h = null;

            using (var db = new CoreCmsDbContext())
            {
                h = db.HomePageSections.FirstOrDefault(i => i.Id == c.Id);
                if (h == null)
                {
                    return;
                }
                h.Published = c.IsPublish;
                db.SaveChanges();
            }
        }
示例#13
0
 public void Handle(CategoryUpdated e)
 {
     using (var db = new CoreCmsDbContext())
     {
         var temp = db.Categories.SingleOrDefault(i => i.Id.Equals(e.Id));
         if (temp != null)
         {
             temp.IsSinglePage     = e.IsSinglePage;
             temp.ShowInFrontEnd   = e.ShowInFrontEnd;
             temp.CategoryViewName = e.CategoryViewName;
             temp.Type             = (short)e.Type;
             db.SaveChanges();
         }
     }
 }
        public void Update(Guid id, string title, string code, string currencyCode, double currencyExchageRate)
        {
            using (var db = new CoreCmsDbContext())
            {
                var lexisted = db.Languages.SingleOrDefault(i => i.Id == id);
                if (lexisted != null)
                {
                    lexisted.Code                 = code;
                    lexisted.Title                = title;
                    lexisted.CurrencyCode         = currencyCode;
                    lexisted.CurrencyExchangeRate = currencyExchageRate;

                    db.SaveChanges();
                }
            }
        }
        public void Handle(DeleteHomPageSection c)
        {
            HomePageSection h = null;

            using (var db = new CoreCmsDbContext())
            {
                h = db.HomePageSections.FirstOrDefault(i => i.Id == c.Id);
                if (h == null)
                {
                    return;
                }
                db.HomePageSections.Remove(h);
                db.SaveChanges();
            }

            _eventPublisher.Publish(new ContentLanguageDeleted(c.Id));
        }
        public void Handle(CreateHomePageSection c)
        {
            var h = new HomePageSection();

            using (var db = new CoreCmsDbContext())
            {
                h.CategoryId              = c.CategoryId;
                h.Id                      = c.Id;
                h.CreatedDate             = DateTime.Now;
                h.DisplayOrder            = c.DisplayOrder;
                h.HomePageSectionViewName = c.ViewName;

                db.HomePageSections.Add(h);
                db.SaveChanges();
            }
            _eventPublisher.Publish(new ContentLanguageUpdated(c.Id, c.LanguageId, "Title", c.Title, "HomePageSection"));
        }
示例#17
0
 public void Handle(CategoryCreated e)
 {
     using (var db = new CoreCmsDbContext())
     {
         db.Categories.Add(new Category()
         {
             Deleted          = false,
             Id               = e.Id,
             ParentId         = e.ParentId,
             IsSinglePage     = e.IsSinglePage,
             ShowInFrontEnd   = e.ShowInFrontEnd,
             CategoryViewName = e.CategoryViewName,
             Type             = (short)e.Type
         });
         db.SaveChanges();
     }
 }
        public void Delete(Guid id)
        {
            if (id == EngineeCurrentContext.DefaultLanguageId)
            {
                throw new Exception("Can not delete Default language");
            }

            using (var db = new CoreCmsDbContext())
            {
                var lexisted = db.Languages.SingleOrDefault(i => i.Id == id);
                if (lexisted != null)
                {
                    db.Languages.Remove(lexisted);

                    db.SaveChanges();
                }
            }
        }
        public void Handle(UpdateHomePageSection c)
        {
            HomePageSection h = null;

            using (var db = new CoreCmsDbContext())
            {
                h = db.HomePageSections.FirstOrDefault(i => i.Id == c.Id);
                if (h == null)
                {
                    return;
                }
                h.CategoryId = c.CategoryId;

                h.DisplayOrder            = c.DisplayOrder;
                h.HomePageSectionViewName = c.ViewName;
                db.SaveChanges();
            }
            _eventPublisher.Publish(new ContentLanguageUpdated(c.Id, c.LanguageId, "Title", c.Title, "HomePageSection"));
        }
示例#20
0
        private static List <News> ResultWithKeywords(string keywords, Guid?languageId, List <Guid> categoryIds, out List <ContentLanguage> contentLanguages,
                                                      bool isSearchWithCategory, Expression <Func <News, bool> > newsPredicate
                                                      , int xskip, int xtake, out long total)
        {
            List <News> result;

            using (var db = new CoreCmsDbContext())
            {
                var queryIds = db.ContentLanguages.Where(
                    i => i.TableName.Equals("News", StringComparison.OrdinalIgnoreCase) &&
                    i.ColumnValue.Contains(keywords));

                if (languageId != null)
                {
                    var xlang = languageId.Value;
                    queryIds = queryIds.Where(i => i.LanguageId == xlang);
                }

                if (isSearchWithCategory)
                {
                    queryIds = queryIds.Join(db.RelationShips, n => n.Id, rs => rs.ToId, (n, rs) => new { N = n, Rs = rs })
                               .Where(m => categoryIds.Contains(m.Rs.FromId)).Select(i => i.N).Distinct();
                }

                var idsForNews = queryIds.Select(i => i.Id).Distinct().ToList();

                total = queryIds.LongCount();

                result = db.News
                         .Where(newsPredicate)
                         .Where(i => idsForNews.Contains(i.Id))
                         .OrderBy(i => i.CreatedDate)
                         .Skip(xskip)
                         .Take(xtake)
                         .ToList();

                var idsForContentLanguages = result.Select(i => i.Id).ToList();

                contentLanguages = db.ContentLanguages.Where(i => idsForContentLanguages.Contains(i.Id)).ToList();
            }
            return(result);
        }
 public DomainLanguage(Guid id, string title, string code, string currencyCode, double currencyExchageRate)
 {
     using (var db = new CoreCmsDbContext())
     {
         var lexisted = db.Languages.SingleOrDefault(i => i.Code.Equals(code, StringComparison.OrdinalIgnoreCase) ||
                                                     i.Id == id ||
                                                     i.CurrencyCode.Equals(currencyCode, StringComparison.OrdinalIgnoreCase));
         if (lexisted == null)
         {
             db.Languages.Add(new Language()
             {
                 Id                   = id,
                 Title                = title,
                 Code                 = code,
                 CurrencyCode         = currencyCode,
                 CurrencyExchangeRate = currencyExchageRate
             });
             db.SaveChanges();
         }
     }
 }
示例#22
0
        public JsonResult HomePageSectionDetail(Guid id)
        {
            HomePageSettingsAdminPage.Section section = new HomePageSettingsAdminPage.Section();
            using (var db = new CoreCmsDbContext())
            {
                section = db.HomePageSections.Where(i => i.Id == id).Select(i => new HomePageSettingsAdminPage.Section()
                {
                    Id                      = i.Id,
                    Published               = i.Published,
                    CategoryId              = i.CategoryId,
                    DisplayOrder            = i.DisplayOrder,
                    HomePageSectionViewName = i.HomePageSectionViewName,
                }).FirstOrDefault();

                var contentLangs = db.ContentLanguages.Where(i => i.Id == id || i.Id == section.CategoryId).ToList();

                section.Title         = contentLangs.GetValue(id, "Title");
                section.CategoryTitle = contentLangs.GetValue(section.CategoryId, "Title");
            }

            return(Json(new { Ok = true, Data = section, Message = "Success" }, JsonRequestBehavior.AllowGet));
        }
示例#23
0
        public ActionResult HomePageSettings()
        {
            var model = new HomePageSettingsAdminPage();

            model.Categories = new List <FeCategory>();

            List <Guid>            cats;
            List <ContentLanguage> contentLangs;

            using (var db = new CoreCmsDbContext())
            {
                cats = db.Categories.Where(i => i.Deleted == false).Select(i => i.Id).ToList();

                contentLangs = db.ContentLanguages.Where(i => cats.Contains(i.Id)).ToList();
            }
            foreach (var c in cats)
            {
                model.Categories.Add(new FeCategory()
                {
                    Id    = c,
                    Title = contentLangs.GetValue(c, "Title")
                });
            }
            var rootPath = Server.MapPath("~/");
            var pdir     = Server.MapPath("~/Views/HomePageSection/");

            if (Directory.Exists(pdir))
            {
                var pfiles = Directory.GetFiles(pdir, "*.cshtml");
                model.ListViewName = pfiles.Select(i => i.Replace(rootPath, "~/").Replace("\\", "/")).ToList();
            }
            else
            {
                model.ListViewName = new List <string>();
            }

            return(View(model));
        }