Esempio n. 1
0
        public ActionResult Reviews(int page = 1, int pageSize = 36)
        {
            try
            {
                using (var db = new DBContext())
                {
                    // Get promotion news
                    var promotions = db.News.Where(r => r.Type == 1).OrderByDescending(r => r.ReleaseDate);
                    // Paging
                    var pageCount = (promotions.Count() / pageSize) + (promotions.Count() % pageSize > 0 ? 1 : 0);
                    if (page > pageCount)
                    {
                        page = pageCount;
                    }
                    var model = new NewsListViewModel();
                    model.News      = promotions.ToList().ToPagedList <News>(page == 0 ? 1 : page, pageSize);
                    model.PageIndex = page;
                    model.PageSize  = pageSize;

                    // Set meta data
                    ViewBag.MetaDescription = "Memory Audio - Đánh giá sản phẩm";
                    ViewBag.MetaKeywords    = "memory audio,review,danh gia,audiophile,sound,hifi,stereo,hi-end,hd,ultra-hd,dts,dts-hd";

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                // Write event logs
                EventLogs.Write("HomeController - Promotion: " + ex.ToString(), EventLogEntryType.Error);

                // Redirect to error page
                return(RedirectToAction("Index", "Error"));
            }
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            try
            {
                // Set meta data
                ViewBag.MetaDescription = "Trang chủ Memory Audio";
                ViewBag.MetaKeywords    = "memory-audio,am-thanh-chau-au,audiophile,sound,hifi,stereo,hi-end,hd,ultra-hd,dts,dts-hd";

                var model = new HomeViewModel();
                using (var db = new DBContext())
                {
                    model.NewProducts = db.Products.Where(r => r.Display == 3).OrderByDescending(r => r.SortIdx).Take(AppSettings.PAGE_SIZE).ToList();
                    model.HotProducts = db.Products.Where(r => r.Display == 4).OrderByDescending(r => r.SortIdx).Take(AppSettings.PAGE_SIZE).ToList();
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                // Write event logs
                EventLogs.Write("HomeController - Index: " + ex.ToString(), EventLogEntryType.Error);

                // Redirect to error page
                return(RedirectToAction("Index", "Error"));
            }
        }
Esempio n. 3
0
 public static BootstrapTree LoadCategoryBootstrapTree()
 {
     try
     {
         var bsTree = new BootstrapTree();
         using (var db = new DBContext())
         {
             var parentCategories = db.Categories
                                    .Where(r => r.ParentId == null)
                                    .OrderBy(r => r.SortIdx)
                                    .ThenBy(r => r.CategoryName)
                                    .ToList();
             foreach (var cat in parentCategories)
             {
                 var parent = new BootstrapTreeNode();
                 parent.text = cat.CategoryName;
                 parent.icon = "fa fa-folder";
                 parent.tags = new string[] { cat.CategoryId.ToString() };
                 AppendChildNodes(parent);
                 bsTree.nodes.Add(parent);
             }
         }
         return(bsTree);
     }
     catch (Exception ex)
     {
         // Write error logs
         EventLogs.Write("BootstrapTree - GetTree: " + ex.ToString());
         throw ex;
     }
 }
Esempio n. 4
0
 public static CategoryTree GetCategoryTree()
 {
     try
     {
         var categoryTree = new CategoryTree();
         using (var db = new DBContext())
         {
             var parentCategories = db.Categories.Where(r => r.ParentId == null).OrderBy(r => r.SortIdx).ThenBy(r => r.CategoryName).ToList();
             foreach (var cat in parentCategories)
             {
                 var parent = new CategoryTreeNode();
                 parent.CategoryId   = cat.CategoryId;
                 parent.CategoryName = cat.CategoryName;
                 parent.Description  = cat.Description;
                 parent.Parent       = null;
                 parent.Level        = 0;
                 parent.Nodes        = new List <CategoryTreeNode>();
                 AppendChildNodes(parent);
                 categoryTree.Nodes.Add(parent);
             }
         }
         return(categoryTree);
     }
     catch (Exception ex)
     {
         // Write error logs
         EventLogs.Write("BootstrapTree - GetCategoryTree: " + ex.ToString());
         throw ex;
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Get top menu raw html
 /// </summary>
 /// <returns></returns>
 public static string GetTopMenuItems()
 {
     try
     {
         var isTimedOut = (DateTime.Now - LastTopMenuUpdated).TotalSeconds > LOADING_TIMEOUT;
         if (isTimedOut)
         {
             using (var db = new DBContext())
             {
                 var categories = db.Categories.Where(r => r.ParentId == null).OrderBy(r => r.SortIdx).ToList();
                 var html       = "";
                 html              += "<ul class=\"right\" style=\"margin-bottom:0px;\">";
                 html              += "    <li><a href=\"\\Trang-chu\">Trang chủ</a></li>";
                 html              += "    <li><a href=\"\\Gioi-thieu\">Giới thiệu</a></li>";
                 html              += "    <li><a href=\"#\">Sản phẩm</a>" + AppendChildMenuItems(categories) + "</li>";
                 html              += "    <li><a href=\"\\Khuyen-mai\">Khuyến mãi</a></li>";
                 html              += "    <li><a href=\"\\Danh-gia\">Đánh giá</a></li>";
                 html              += "    <li><a href=\"\\Thanh-toan\">Thanh toán</a></li>";
                 html              += "    <li><a href=\"\\Lien-he\">Liên hệ</a></li>";
                 html              += "</ul>";
                 _topMenuRawHtml    = html;
                 LastTopMenuUpdated = DateTime.Now;
             }
         }
     }
     catch (Exception ex)
     {
         // Write event logs
         EventLogs.Write(ex.ToString(), EventLogEntryType.Error);
     }
     return(_topMenuRawHtml);
 }
Esempio n. 6
0
 public static void LoadSettings()
 {
     try
     {
         LOG_PATH  = ConfigurationManager.AppSettings["LOG_PATH"];
         PAGE_SIZE = Int32.Parse(ConfigurationManager.AppSettings["PAGE_SIZE"]);
     }
     catch (Exception ex)
     {
         // Write event logs
         EventLogs.Write(ex.ToString(), EventLogEntryType.Error);
     }
 }
Esempio n. 7
0
        public ActionResult News(string title)
        {
            try
            {
                using (var db = new DBContext())
                {
                    // Get newsId
                    var newsId = ParseId(title);

                    // Get news
                    var news = db.News.Where(r => r.NewsId == newsId && r.Status > 1).OrderByDescending(r => r.ReleaseDate).FirstOrDefault();
                    if (news == null)
                    {
                        throw new Exception("Có lỗi xảy ra! Bản tin không tồn tại.");
                    }
                    // Get related news
                    var relatedNews = db.News
                                      .Where(r => r.NewsId < news.NewsId && r.Type == news.Type && r.Status > 1)
                                      .OrderByDescending(r => r.ReleaseDate)
                                      .Take(AppSettings.PAGE_SIZE)
                                      .ToList();
                    // Create view model
                    var model = new NewsViewModel();
                    model.News        = news;
                    model.RelatedNews = relatedNews;

                    // Set meta data
                    ViewBag.MetaDescription = "Memory Audio - " + news.Title;
                    ViewBag.MetaKeywords    = news.Tags;

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                // Write event logs
                EventLogs.Write("HomeController - News: " + ex.ToString(), EventLogEntryType.Error);

                // Redirect to error page
                return(RedirectToAction("Index", "Error"));
            }
        }
Esempio n. 8
0
 public static void AppendChildNodes(BootstrapTreeNode parent)
 {
     if (parent != null)
     {
         var parentId = 0;
         if (int.TryParse(parent.tags[0], out parentId))
         {
             try
             {
                 using (var db = new DBContext())
                 {
                     var childCategories = db.Categories.Where(r => r.ParentId == parentId).OrderBy(r => r.SortIdx).ThenBy(r => r.CategoryName).ToList();
                     foreach (var cat in childCategories)
                     {
                         var child = new BootstrapTreeNode();
                         child.text = cat.CategoryName;
                         child.icon = "fa fa-folder";
                         child.tags = new string[] { cat.CategoryId.ToString() };
                         AppendChildNodes(child);
                         parent.nodes.Add(child);
                     }
                     if (childCategories.Count > 0)
                     {
                         parent.text += " (" + childCategories.Count + ")";
                     }
                 }
             }
             catch (Exception ex)
             {
                 // Write error logs
                 EventLogs.Write("BootstrapTree - AppendChildNodes: " + ex.ToString());
                 throw ex;
             }
             //.try
         }
         //.if
     }
     //.if
 }
Esempio n. 9
0
        public ActionResult Category(String name, string filterText = "", string sortOrder = "", int page = 1, int pageSize = 36)
        {
            var model = new CategoryViewModel();

            try
            {
                model.FilterText = filterText.Trim();
                model.SortOrder  = sortOrder;
                using (var db = new DBContext())
                {
                    // Get category id
                    var categoryId = ParseId(name);

                    // Get category info
                    var category = db.Categories.Where(r => r.CategoryId == categoryId).FirstOrDefault();
                    if (category != null)
                    {
                        // Set meta data
                        ViewBag.MetaDescription = "Memory Audio - " + category.CategoryName;
                        ViewBag.MetaKeywords    = category.CategoryName + ",memory-audio,audiophile,sound,hifi,stereo,hi-end,hd,ultra-hd,dts,dts-hd";

                        // Query products
                        var query = from p in db.Products
                                    join c in db.Categories on p.CategoryId equals c.CategoryId into pc
                                    join b in db.Brands on p.BrandId equals b.BrandId into pb
                                    from j1 in pc.DefaultIfEmpty()
                                    from j2 in pb.DefaultIfEmpty()
                                    where p.Display > 1
                                    select new ProductInfo
                        {
                            ProductId     = p.ProductId,
                            ProductName   = p.ProductName,
                            CategoryId    = p.CategoryId,
                            CategoryName  = j1.CategoryName,
                            BrandId       = p.BrandId,
                            BrandName     = j2.BrandName,
                            Specification = p.Specification,
                            TotalInStock  = p.TotalInStock,
                            Price         = p.Price,
                            Discount      = p.Discount,
                            Image1        = p.Image1,
                            Image2        = p.Image2,
                            Image3        = p.Image3,
                            Image4        = p.Image4,
                            Image5        = p.Image5,
                            Image6        = p.Image6,
                            CreationDate  = p.CreationDate,
                            Display       = p.Display,
                            SortIdx       = p.SortIdx
                        };

                        // Get category nodes include its children and parent
                        var categoryNode = new CategoryTreeNode();
                        categoryNode.CategoryId   = category.CategoryId;
                        categoryNode.CategoryName = category.CategoryName;
                        categoryNode.Description  = category.Description;
                        categoryNode.Level        = 0;
                        categoryNode.Parent       = null;
                        categoryNode.Nodes        = new List <CategoryTreeNode>();
                        CategoryTree.AppendChildNodes(categoryNode);
                        CategoryTree.AppendParentNodes(categoryNode);

                        // Filter products by category which included its children
                        var childNodes       = categoryNode.GetChildNodes();
                        var childCategoryIds = new List <int>();
                        foreach (var node in childNodes)
                        {
                            childCategoryIds.Add(node.CategoryId);
                        }
                        if (childCategoryIds.Count > 0)
                        {
                            query = query.Where(r => childCategoryIds.Contains(r.CategoryId ?? 0));
                        }
                        if (!string.IsNullOrWhiteSpace(filterText))
                        {
                            query = query.Where(r => r.ProductName.Contains(filterText) || r.CategoryName.Contains(filterText));
                        }

                        // Get parent nodes
                        var parentNodes = categoryNode.GetParentNodes();
                        foreach (var parentNode in parentNodes)
                        {
                            var parentCategory = db.Categories.Where(r => r.CategoryId == parentNode.CategoryId).FirstOrDefault();
                            if (parentCategory != null && parentCategory.CategoryId != category.CategoryId)
                            {
                                model.ParentCategories.Add(parentCategory);
                            }
                        }

                        // Sorting
                        switch (sortOrder)
                        {
                        case "price":
                            query = query.OrderBy(p => p.Price);
                            break;

                        case "price_desc":
                            query = query.OrderByDescending(p => p.Price);
                            break;

                        case "name":
                            query = query.OrderBy(p => p.ProductName);
                            break;

                        case "name_desc":
                            query = query.OrderByDescending(p => p.ProductName);
                            break;

                        default:
                            query = query.OrderByDescending(p => p.SortIdx);
                            break;
                        }
                        var products  = query.ToList();
                        var pageCount = (products.Count / pageSize) + (products.Count % pageSize > 0 ? 1 : 0);
                        if (page > pageCount)
                        {
                            page = pageCount;
                        }
                        model.Products = query.ToPagedList <ProductInfo>(page == 0 ? 1 : page, pageSize);
                    }
                    else
                    {
                        throw new Exception("Category not found!");
                    }

                    model.Category  = category;
                    model.PageIndex = model.Products.PageNumber;
                    model.PageSize  = model.Products.PageSize;

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                // Write event logs
                EventLogs.Write("HomeController - Category: " + ex.ToString(), EventLogEntryType.Error);

                // Redirect to error page
                return(RedirectToAction("Index", "Error"));
            }
        }
Esempio n. 10
0
        public ActionResult Product(string name)
        {
            var model = new ProductViewModel();

            try
            {
                using (var db = new DBContext())
                {
                    // Get ProductId
                    var productId = ParseId(name);

                    // Get product info
                    var productInfo = (from p in db.Products
                                       join c in db.Categories on p.CategoryId equals c.CategoryId into pc
                                       join b in db.Brands on p.BrandId equals b.BrandId into pb
                                       from j1 in pc.DefaultIfEmpty()
                                       from j2 in pb.DefaultIfEmpty()
                                       where p.ProductId == productId && p.Display > 1
                                       select new ProductInfo
                    {
                        ProductId = p.ProductId,
                        ProductName = p.ProductName,
                        CategoryId = p.CategoryId,
                        CategoryName = j1.CategoryName,
                        BrandId = p.BrandId,
                        BrandName = j2.BrandName,
                        Specification = p.Specification,
                        TotalInStock = p.TotalInStock,
                        Price = p.Price,
                        Discount = p.Discount,
                        MSRP = p.MSRP,
                        Image1 = p.Image1,
                        Image2 = p.Image2,
                        Image3 = p.Image3,
                        Image4 = p.Image4,
                        Image5 = p.Image5,
                        Image6 = p.Image6,
                        CreationDate = p.CreationDate,
                        Display = p.Display,
                        SortIdx = p.SortIdx
                    }).FirstOrDefault();

                    // Product existed?
                    if (productInfo == null)
                    {
                        return(RedirectToAction("Index", "Error", new { @message = "Product not found!" }));
                    }

                    // Get related products
                    var relatedProducts = from p in db.Products
                                          join c in db.Categories on p.CategoryId equals c.CategoryId into pc
                                          join b in db.Brands on p.BrandId equals b.BrandId into pb
                                          from j1 in pc.DefaultIfEmpty()
                                          from j2 in pb.DefaultIfEmpty()
                                          where p.Display > 1 && p.ProductId != productInfo.ProductId && p.CategoryId == productInfo.CategoryId
                                          orderby p.Display descending, p.SortIdx ascending
                        select new ProductInfo
                    {
                        ProductId     = p.ProductId,
                        ProductName   = p.ProductName,
                        CategoryId    = p.CategoryId,
                        CategoryName  = j1.CategoryName,
                        BrandId       = p.BrandId,
                        BrandName     = j2.BrandName,
                        Specification = p.Specification,
                        TotalInStock  = p.TotalInStock,
                        Price         = p.Price,
                        Discount      = p.Discount,
                        Image1        = p.Image1,
                        Image2        = p.Image2,
                        Image3        = p.Image3,
                        Image4        = p.Image4,
                        Image5        = p.Image5,
                        Image6        = p.Image6,
                        CreationDate  = p.CreationDate,
                        Display       = p.Display,
                        SortIdx       = p.SortIdx
                    };

                    // Get category info and its parent
                    var category = db.Categories.Where(r => r.CategoryId == productInfo.CategoryId).FirstOrDefault();
                    if (category != null)
                    {
                        var categoryNode = new CategoryTreeNode();
                        categoryNode.CategoryId   = category.CategoryId;
                        categoryNode.CategoryName = category.CategoryName;
                        categoryNode.Description  = category.Description;
                        categoryNode.Level        = 0;
                        categoryNode.Parent       = null;
                        categoryNode.Nodes        = new List <CategoryTreeNode>();
                        CategoryTree.AppendParentNodes(categoryNode);

                        var parentNodes = categoryNode.GetParentNodes();
                        foreach (var parentNode in parentNodes)
                        {
                            var parentCategory = db.Categories.Where(r => r.CategoryId == parentNode.CategoryId).FirstOrDefault();
                            if (parentCategory != null && parentCategory.CategoryId != category.CategoryId)
                            {
                                model.ParentCategories.Add(parentCategory);
                            }
                        }
                        model.Category = category;
                    }
                    model.Product         = productInfo;
                    model.RelatedProducts = relatedProducts.Take(AppSettings.PAGE_SIZE).ToList();

                    // Set meta data
                    ViewBag.MetaDescription = "Memory Audio - " + productInfo.ProductName;
                    ViewBag.MetaKeywords    =
                        productInfo.CategoryName + "," +
                        productInfo.ProductName + "," +
                        productInfo.BrandName + ",memory audio,audiophile,sound,hifi,stereo,hi-end,hd,ultra-hd,dts,dts-hd";

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                // Write event logs
                EventLogs.Write("HomeController - Products: " + ex.ToString(), EventLogEntryType.Error);

                // Redirect to error page
                return(RedirectToAction("Index", "Error"));
            }
        }
Esempio n. 11
0
        public ActionResult HotProducts(string filterText = "", string sortOrder = "", int page = 1, int pageSize = 36)
        {
            var model = new HotProductsViewModel();

            try
            {
                // Set meta data
                ViewBag.MetaDescription = "Memory Audio - Sản phẩm nổi bật";
                ViewBag.MetaKeywords    = "memory audio,hot products,san pham noi bat,audiophile,sound,hifi,stereo,hi-end,hd,ultra-hd,dts,dts-hd";

                using (var db = new DBContext())
                {
                    model.FilterText = filterText.Trim();
                    model.SortOrder  = sortOrder;
                    // Select products
                    var query = from p in db.Products
                                join c in db.Categories on p.CategoryId equals c.CategoryId into pc
                                join b in db.Brands on p.BrandId equals b.BrandId into pb
                                from j1 in pc.DefaultIfEmpty()
                                from j2 in pb.DefaultIfEmpty()
                                where p.Display == 4
                                select new ProductInfo
                    {
                        ProductId     = p.ProductId,
                        ProductName   = p.ProductName,
                        CategoryId    = p.CategoryId,
                        CategoryName  = j1.CategoryName,
                        BrandId       = p.BrandId,
                        BrandName     = j2.BrandName,
                        Specification = p.Specification,
                        TotalInStock  = p.TotalInStock,
                        Price         = p.Price,
                        Discount      = p.Discount,
                        Image1        = p.Image1,
                        Image2        = p.Image2,
                        Image3        = p.Image3,
                        Image4        = p.Image4,
                        Image5        = p.Image5,
                        Image6        = p.Image6,
                        CreationDate  = p.CreationDate,
                        Display       = p.Display,
                        SortIdx       = p.SortIdx
                    };

                    // Filter
                    if (!string.IsNullOrWhiteSpace(filterText))
                    {
                        query = query.Where(r => r.ProductName.Contains(filterText) || r.CategoryName.Contains(filterText));
                    }

                    // Sorting
                    switch (sortOrder)
                    {
                    case "price":
                        query = query.OrderBy(p => p.Price);
                        break;

                    case "price_desc":
                        query = query.OrderByDescending(p => p.Price);
                        break;

                    case "name":
                        query = query.OrderBy(p => p.ProductName);
                        break;

                    case "name_desc":
                        query = query.OrderByDescending(p => p.ProductName);
                        break;

                    default:
                        query = query.OrderByDescending(p => p.SortIdx);
                        break;
                    }
                    var products  = query.ToList();
                    var pageCount = (products.Count() / pageSize) + (products.Count() % pageSize > 0 ? 1 : 0);
                    if (page > pageCount)
                    {
                        page = pageCount;
                    }
                    model.Products = query.ToPagedList <ProductInfo>(page == 0 ? 1 : page, pageSize);
                }
                model.PageIndex = model.Products.PageNumber;
                model.PageSize  = model.Products.PageSize;
                return(View(model));
            }
            catch (Exception ex)
            {
                // Write event logs
                EventLogs.Write("HomeController - HotProducts: " + ex.ToString(), EventLogEntryType.Error);

                // Redirect to error page
                return(RedirectToAction("Index", "Error"));
            }
        }
Esempio n. 12
0
        public ActionResult Results(int categoryId = 0, string searchText = "", string sortOrder = "", int page = 1, int pageSize = 12)
        {
            var model = new SearchResultsViewModel();

            try
            {
                model.SearchText = searchText.Trim();
                model.SortOrder  = sortOrder;

                using (var db = new DBContext())
                {
                    var query = from p in db.Products
                                join c in db.Categories on p.CategoryId equals c.CategoryId into pc
                                join b in db.Brands on p.BrandId equals b.BrandId into pb
                                from j1 in pc.DefaultIfEmpty()
                                from j2 in pb.DefaultIfEmpty()
                                where p.Display > 0
                                select new ProductInfo
                    {
                        ProductId     = p.ProductId,
                        ProductName   = p.ProductName,
                        CategoryId    = p.CategoryId,
                        CategoryName  = j1.CategoryName,
                        BrandId       = p.BrandId,
                        BrandName     = j2.BrandName,
                        Specification = p.Specification,
                        TotalInStock  = p.TotalInStock,
                        Price         = p.Price,
                        Discount      = p.Discount,
                        Image1        = p.Image1,
                        Image2        = p.Image2,
                        Image3        = p.Image3,
                        Image4        = p.Image4,
                        Image5        = p.Image5,
                        Image6        = p.Image6,
                        CreationDate  = p.CreationDate,
                        Display       = p.Display,
                        SortIdx       = p.SortIdx
                    };
                    // Filter
                    if (!string.IsNullOrWhiteSpace(searchText))
                    {
                        query = query.Where(r => r.ProductName.Contains(searchText) || r.CategoryName.Contains(searchText));
                    }

                    // Sorting
                    switch (sortOrder)
                    {
                    case "price":
                        query = query.OrderBy(p => p.Price);
                        break;

                    case "price_desc":
                        query = query.OrderByDescending(p => p.Price);
                        break;

                    case "name":
                        query = query.OrderBy(p => p.ProductName);
                        break;

                    case "name_desc":
                        query = query.OrderByDescending(p => p.ProductName);
                        break;

                    default:
                        query = query.OrderBy(p => p.ProductName);
                        break;
                    }
                    // Paging
                    var products  = query.ToList();
                    var pageCount = (products.Count / pageSize) + (products.Count % pageSize > 0 ? 1 : 0);
                    if (page < pageCount)
                    {
                        page = pageCount;
                    }
                    model.Products = query.ToPagedList <ProductInfo>(page, pageSize);
                }
                model.PageIndex = model.Products.PageNumber;
                model.PageSize  = model.Products.PageSize;
                return(View(model));
            }
            catch (Exception ex)
            {
                // Write event logs
                EventLogs.Write(ex.ToString(), EventLogEntryType.Error);
                // Redirect to error page
                return(RedirectToAction("Index", "Error"));
            }
        }