public bool DeleteCMSCategory(int id, string deleteBy, bool isAdmin)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var category = db.cms_Categories.Find(id);
                    if (isAdmin == true)
                    {
                        category.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Delete;
                    }
                    else
                    {
                        category.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.WaitingDelete;
                    }

                    category.ModifiedByTy = deleteBy;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #2
0
        public bool AddProfile(ProfileViewModel profileViewModel)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var profile = new system_Profiles
                    {
                        UserId   = profileViewModel.UserId,
                        UserName = profileViewModel.UserName,
                        Emaill   = profileViewModel.Emaill,
                        Password = profileViewModel.Password,
                        Phone    = profileViewModel.Phone,
                        Address  = profileViewModel.Address
                    };
                    db.system_Profiles.Add(profile);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public bool DeleteCMSNews(int id, string deleteBy, bool isAdmin)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var news = db.cms_News.Find(id);
                    if (isAdmin == true)
                    {
                        news.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Delete;
                    }
                    else
                    {
                        news.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.WaitingDelete;
                    }

                    news.ModifiedByTy = deleteBy;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public bool AddCMSNews(CMSNewsView cmsNewsView)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var cmsNews = new cms_News
                    {
                        CategoryId      = cmsNewsView.CategoryId,
                        CoverImageId    = cmsNewsView.CoverImageId,
                        Title           = cmsNewsView.Title,
                        SubTitle        = cmsNewsView.SubTitle,
                        ContentNews     = cmsNewsView.ContentNews,
                        Authors         = cmsNewsView.Authors,
                        Tags            = cmsNewsView.Tags,
                        TotalView       = cmsNewsView.TotalView,
                        DisplayHomePage = cmsNewsView.DisplayHomePage,
                        Status          = cmsNewsView.Status,
                        SortOrder       = cmsNewsView.SortOrder,
                        CreatedDate     = DateTime.Now,
                        ModifiedDate    = DateTime.Now
                    };
                    db.cms_News.Add(cmsNews);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
 public IList <CMSNewsView> GetCMSNewsForHomePage()
 {
     using (var db = new OnlineStoreMVCEntities())
     {
         return(db.cms_News.Where(x => x.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.Active && x.DisplayHomePage == true ||
                                  x.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.WaitingDelete && x.DisplayHomePage == true
                                  )
                .OrderByDescending(x => x.CreatedDate)
                .Take(3)
                .Select(x => new CMSNewsView
         {
             Id = x.Id,
             CategoryId = x.CategoryId,
             CategoryTitle = x.cms_Categories.Title,
             CoverImageId = x.CoverImageId,
             CoverImagePath = x.share_Images.ImagePath,
             Title = x.Title,
             SubTitle = x.SubTitle,
             ContentNews = x.ContentNews,
             Authors = x.Authors,
             Tags = x.Tags,
             TotalView = x.TotalView,
             Status = x.Status,
             CreatedDate = x.CreatedDate
         }).ToList());
     }
 }
Example #6
0
        public IList <CMSNewsView> GetCMSNews(int pageNumber, int pageSize, out int totalItems)
        {
            using (var db = new OnlineStoreMVCEntities())
            {
                totalItems = db.cms_News.Count(x => x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.Delete);

                return(db.cms_News.Where(x => x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.Delete && x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.WaitingCreate)
                       .OrderByDescending(x => x.SortOrder).ThenByDescending(x => x.CreatedDate)
                       .Skip(pageSize * (pageNumber - 1)).Take(pageSize)
                       .Select(x => new CMSNewsView
                {
                    Id = x.Id,
                    CategoryId = x.CategoryId,
                    CategoryTitle = x.cms_Categories.Title,
                    Title = x.Title,
                    SubTitle = x.SubTitle,
                    ContentNews = x.ContentNews,
                    Authors = x.Authors,
                    Tags = x.Tags,
                    TotalView = x.TotalView,
                    Status = x.Status,
                    CreatedDate = x.CreatedDate
                }).ToList());
            }
        }
Example #7
0
        public bool UpdateTotalVisitors()
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var config = db.system_Config.FirstOrDefault(x => x.Name == OnlineStore.Infractructure.Utility.Define.SystemConfig.TotalVisitors.ToString());
                    if (config != null)
                    {
                        config.Value = (Convert.ToInt32(config.Value) + 1).ToString();
                    }
                    else
                    {
                        var TrackingConfig = new system_Config
                        {
                            Name   = OnlineStore.Infractructure.Utility.Define.SystemConfig.TotalVisitors.ToString(),
                            Value  = "1",
                            Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Active
                        };
                        db.system_Config.Add(TrackingConfig);
                    }
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #8
0
        public IList <CMSNewsView> GetCMSNewsByCategoryId(int categoryId, int pageNumber, int pageSize, out int totalItems)
        {
            using (var db = new OnlineStoreMVCEntities())
            {
                var news = db.cms_News.Where(x => x.CategoryId == categoryId && x.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.Active ||
                                             x.CategoryId == categoryId && x.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.WaitingDelete
                                             )
                           .Select(x => new CMSNewsView
                {
                    Id             = x.Id,
                    CategoryId     = x.CategoryId,
                    CategoryTitle  = x.cms_Categories.Title,
                    CoverImageId   = x.CoverImageId,
                    CoverImagePath = x.share_Images.ImagePath,
                    Title          = x.Title,
                    SubTitle       = x.SubTitle,
                    ContentNews    = x.ContentNews,
                    Authors        = x.Authors,
                    Tags           = x.Tags,
                    TotalView      = x.TotalView,
                    Status         = x.Status
                }).ToList();

                news.AddRange(GetCMSNewsRecursive(categoryId));
                totalItems = news.Count();

                return(news.OrderByDescending(x => x.SortOrder).ThenByDescending(x => x.CreatedDate).Skip(pageSize * (pageNumber - 1)).Take(pageSize).ToList());
            }
        }
Example #9
0
 public IList <CMSNewsView> GetCMSNewsTy(int categoryId = 0)
 {
     using (var db = new OnlineStoreMVCEntities())
     {
         return(db.cms_News.Where(x => x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.Delete && categoryId == 0 &&
                                  x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.WaitingCreate && categoryId == 0 ||
                                  x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.Delete && x.CategoryId == categoryId &&
                                  x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.WaitingCreate && x.CategoryId == categoryId
                                  )
                .OrderByDescending(x => x.SortOrder).ThenByDescending(x => x.CreatedDate)
                .Select(x => new CMSNewsView
         {
             Id = x.Id,
             CategoryId = x.CategoryId,
             CategoryTitle = x.cms_Categories.Title,
             Title = x.Title,
             SubTitle = x.SubTitle,
             ContentNews = x.ContentNews,
             Authors = x.Authors,
             Tags = x.Tags,
             TotalView = x.TotalView,
             Status = x.Status,
             CreatedDate = x.CreatedDate,
             ModifiedBy = x.ModifiedByTy
         }).ToList());
     }
 }
Example #10
0
        public BannerViewModel GetBannerById(int?bannerId)
        {
            if (bannerId == null)
            {
                return(null);
            }

            using (var db = new OnlineStoreMVCEntities())
            {
                var banner = db.system_Banners.Find(bannerId.Value);
                return(new BannerViewModel
                {
                    Id = banner.Id,
                    ImageId = banner.ImageId,
                    ImageName = banner.share_Images.ImageName,
                    ImagePath = banner.share_Images.ImagePath,
                    Name = banner.Name,
                    Type = banner.Type,
                    Status = banner.Status,
                    SortOrder = banner.SortOrder,
                    StartEndDate = banner.StartDate.HasValue && banner.EndDate.HasValue ?
                                   string.Format("{0} - {1}", banner.StartDate.Value.ToString("dd/MM/yyyy"), banner.EndDate.Value.ToString("dd/MM/yyyy")) : string.Empty
                });
            }
        }
        public bool AddCMSCategory(CMSCategoryView categoryView)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var category = new cms_Categories
                    {
                        ParentId = categoryView.ParentId,
                        Title = categoryView.Title,
                        Description = categoryView.Description,
                        Url = categoryView.Url,
                        SortOrder = categoryView.SortOrder,
                        Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Active,
                        CreatedDate = DateTime.Now,
                        ModifiedDate = DateTime.Now
                    };
                    db.cms_Categories.Add(category);
                    db.SaveChanges();

                    return true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #12
0
        public bool EditCMSNews(CMSNewsView cmsNewsView)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var news = db.cms_News.Find(cmsNewsView.Id);
                    news.CategoryId   = cmsNewsView.CategoryId;
                    news.Title        = cmsNewsView.Title;
                    news.SubTitle     = cmsNewsView.SubTitle;
                    news.ContentNews  = cmsNewsView.ContentNews;
                    news.Authors      = cmsNewsView.Authors;
                    news.Tags         = cmsNewsView.Tags;
                    news.TotalView    = cmsNewsView.TotalView;
                    news.SortOrder    = cmsNewsView.SortOrder;
                    news.Status       = cmsNewsView.Status;
                    news.ModifiedDate = DateTime.Now;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #13
0
        public CMSNewsView GetCMSNewsById(int?newsId)
        {
            if (newsId == null)
            {
                return(null);
            }

            using (var db = new OnlineStoreMVCEntities())
            {
                var news = db.cms_News.Find(newsId);
                return(new CMSNewsView
                {
                    Id = news.Id,
                    CategoryId = news.CategoryId,
                    CategoryTitle = news.cms_Categories.Title,
                    CoverImageId = news.CoverImageId,
                    CoverImageName = news.share_Images.ImageName,
                    CoverImagePath = news.share_Images.ImagePath,
                    Title = news.Title,
                    SubTitle = news.SubTitle,
                    ContentNews = news.ContentNews,
                    Authors = news.Authors,
                    Tags = news.Tags,
                    DisplayHomePage = news.DisplayHomePage,
                    TotalView = news.TotalView,
                    Status = news.Status,
                    SortOrder = news.SortOrder,
                    CreatedDate = news.CreatedDate
                });
            }
        }
Example #14
0
        public CMSNewsView GetCMSNewsById(int?newsId)
        {
            if (newsId == null)
            {
                return(null);
            }

            using (var db = new OnlineStoreMVCEntities())
            {
                var news = db.cms_News.Find(newsId.Value);
                return(new CMSNewsView
                {
                    Id = news.Id,
                    CategoryId = news.CategoryId,
                    Title = news.Title,
                    SubTitle = news.SubTitle,
                    ContentNews = news.ContentNews,
                    Authors = news.Authors,
                    Tags = news.Tags,
                    TotalView = news.TotalView,
                    Status = news.Status,
                    SortOrder = news.SortOrder
                });
            }
        }
 public IList <CMSNewsView> GetRelatedCMSNews(int id)
 {
     using (var db = new OnlineStoreMVCEntities())
     {
         var news = db.cms_News.Find(id);
         return(db.cms_News.Where(x => x.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.Active && x.CategoryId == news.CategoryId && x.Id != news.Id)
                .OrderByDescending(x => x.CreatedDate)
                .Take(3)
                .Select(x => new CMSNewsView
         {
             Id = x.Id,
             CategoryId = x.CategoryId,
             CategoryTitle = x.cms_Categories.Title,
             CoverImageId = x.CoverImageId,
             CoverImagePath = x.share_Images.ImagePath,
             Title = x.Title,
             SubTitle = x.SubTitle,
             ContentNews = x.ContentNews,
             Authors = x.Authors,
             Tags = x.Tags,
             TotalView = x.TotalView,
             Status = x.Status,
             CreatedDate = x.CreatedDate
         }).ToList());
     }
 }
        public bool EditCMSCategory(CMSCategoryView categoryView)
        {
            try
            {
                if (categoryView.ParentId == null)
                {
                    categoryView.ParentId = 0;
                }
                using (var db = new OnlineStoreMVCEntities())
                {
                    var category = db.cms_Categories.Find(categoryView.Id);
                    category.ParentId     = categoryView.ParentId;
                    category.Title        = categoryView.Title;
                    category.Description  = categoryView.Description;
                    category.Url          = categoryView.Url;
                    category.SortOrder    = categoryView.SortOrder;
                    category.Status       = categoryView.Status;
                    category.ModifiedDate = DateTime.Now;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool AddCMSCategory(CMSCategoryView categoryView)
        {
            try
            {
                if (categoryView.ParentId == null)
                {
                    categoryView.ParentId = 0;
                }
                using (var db = new OnlineStoreMVCEntities())
                {
                    var category = new cms_Categories
                    {
                        ParentId     = categoryView.ParentId,
                        Title        = categoryView.Title,
                        Description  = categoryView.Description,
                        Url          = categoryView.Url,
                        SortOrder    = categoryView.SortOrder,
                        Status       = categoryView.Status,
                        CreatedDate  = DateTime.Now,
                        ModifiedDate = DateTime.Now,
                        CreateByTy   = categoryView.CreatedBy,
                    };
                    db.cms_Categories.Add(category);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public IList <cms_Categories> Getcms_CategoriesTy()
 {
     using (var db = new OnlineStoreMVCEntities())
     {
         return(db.cms_Categories.Where(x => x.Status != (int)Define.Status.Delete && x.Status != (int)Define.Status.WaitingCreate)
                .OrderBy(x => x.ParentId).ThenBy(x => x.SortOrder).ToList());
     }
 }
Example #19
0
 public ProductService()
 {
     context                = new OnlineStoreMVCEntities();
     db                     = new ProductRepository(context);
     brandRepository        = new BrandRepository(context);
     imageRepository        = new Repository <share_Images>(context);
     categoryRepository     = new CategoryRepository(context);
     productGroupRepository = new ProductGroupRepository(context);
 }
Example #20
0
 public int GetTotalVisitors()
 {
     using (var db = new OnlineStoreMVCEntities())
     {
         var config = db.system_Config.FirstOrDefault(x => x.Name == OnlineStore.Infractructure.Utility.Define.SystemConfig.TotalVisitors.ToString());
         if (config != null)
         {
             return(Convert.ToInt32(config.Value));
         }
         return(0);
     }
 }
Example #21
0
 public IList <BannerViewModel> GetBanners1ForHomePage()
 {
     using (var db = new OnlineStoreMVCEntities())
     {
         return(db.system_Banners.Where(x => x.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.Active && x.Type == (int)OnlineStore.Infractructure.Utility.Define.BannerTypes.Banner1)
                .OrderBy(x => x.SortOrder).ThenBy(x => x.Id)
                .Select(x => new BannerViewModel
         {
             Name = x.Name,
             ImageName = x.share_Images.ImageName,
             ImagePath = x.share_Images.ImagePath,
         }).ToList());
     }
 }
Example #22
0
 public IList <BannerViewModel> GetBannersTy()
 {
     using (var db = new OnlineStoreMVCEntities())
     {
         return(db.system_Banners.Where(x => x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.Delete)
                .OrderBy(x => x.SortOrder).ThenBy(x => x.Id)
                .Select(x => new BannerViewModel
         {
             Id = x.Id,
             Name = x.Name,
             Type = x.Type,
             Status = x.Status
         }).ToList());
     }
 }
Example #23
0
 public IList <MenuView> GetMenuByType(int typeId)
 {
     using (var db = new OnlineStoreMVCEntities())
     {
         return(db.system_Menu.Where(x => x.Type == typeId && x.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.Active).OrderBy(x => x.SortOrder)
                .Select(x => new MenuView
         {
             Id = x.Id,
             Name = x.Name,
             Url = x.Url,
             Type = x.Type,
             Icon = x.Icon
         }).ToList());
     }
 }
Example #24
0
        public BannerViewModel GetBanners2ForHomePage()
        {
            int month     = DateTime.Now.Month;
            int brandType = 1;

            switch (month)
            {
            case 1:
            case 2:
            case 3:
                brandType = 2;    //Spring
                break;

            case 4:
            case 5:
            case 6:
                brandType = 3;    //Summer
                break;

            case 7:
            case 8:
            case 9:
                brandType = 4;    //Autumn
                break;

            case 10:
            case 11:
            case 12:
                brandType = 5;    //Winter
                break;
            }

            using (var db = new OnlineStoreMVCEntities())
            {
                var banner2 = db.system_Banners.FirstOrDefault(x => x.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.Active && x.Type == brandType);
                if (banner2 != null)
                {
                    return(new BannerViewModel
                    {
                        Name = banner2.Name,
                        ImageName = banner2.share_Images.ImageName,
                        ImagePath = banner2.share_Images.ImagePath,
                    });
                }

                return(null);
            }
        }
        public bool DeleteCMSNews(int id)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var news = db.cms_News.Find(id);
                    news.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Delete;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #26
0
        public IList <BannerViewModel> GetBanners(int pageNumber, int pageSize, out int totalItems)
        {
            using (var db = new OnlineStoreMVCEntities())
            {
                totalItems = db.system_Banners.Count(x => x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.Delete);

                return(db.system_Banners.Where(x => x.Status != (int)OnlineStore.Infractructure.Utility.Define.Status.Delete)
                       .OrderBy(x => x.SortOrder).ThenBy(x => x.Id)
                       .Skip(pageSize * (pageNumber - 1)).Take(pageSize)
                       .Select(x => new BannerViewModel
                {
                    Id = x.Id,
                    Name = x.Name,
                    Type = x.Type,
                    Status = x.Status
                }).ToList());
            }
        }
Example #27
0
        public bool DeleteBanner(int id)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var banner = db.system_Banners.Find(id);
                    banner.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Delete;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool DeleteCMSCategory(int id)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var category = db.cms_Categories.Find(id);
                    category.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Delete;
                    db.SaveChanges();

                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Example #29
0
        public bool VerifyCMSNews(int id, int status)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var news = db.cms_News.Find(id);
                    news.Status = status;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #30
0
        public bool UpdateCMSNewsCountView(int?newsId)
        {
            try
            {
                using (var db = new OnlineStoreMVCEntities())
                {
                    var news = db.cms_News.Find(newsId);
                    news.TotalView++;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }