コード例 #1
0
        public JsonResult ShowMoreDiscussions(int goodId, int showedDiscussionsNumber, int addedDiscussionsNumber)
        {
            using (GoodContext db = new GoodContext())
            {
                var discussionsList = db.Goods.Where(x => x.Id == goodId).First().Discussions
                                      .Select(x => new {
                    Message                = x.Message,
                    AuthorName             = x.AuthorName,
                    AuthorAvatarSrc        = x.AuthorAvatarSrc,
                    Date                   = x.Date,
                    StringDate             = x.Date.ToShortDateString(),
                    FirstDiscussionMessage = x.FirstDiscussionMessage,
                    DiscussionGroup        = x.DiscussionGroup
                })
                                      .OrderByDescending(p => p.FirstDiscussionMessage).ThenBy(p => p.Date).GroupBy(p => p.DiscussionGroup).ToList();
                int    lastShowedDiscussionIndex = showedDiscussionsNumber + addedDiscussionsNumber;
                int    discussionsListLength     = discussionsList.Count();
                var    addedDiscussionsList      = discussionsList;
                string allDiscussionsShowed      = "false";

                if (lastShowedDiscussionIndex < discussionsListLength)
                {
                    addedDiscussionsList = discussionsList.GetRange(showedDiscussionsNumber, addedDiscussionsNumber);
                }
                else
                {
                    addedDiscussionsList = discussionsList.GetRange(showedDiscussionsNumber, discussionsListLength - showedDiscussionsNumber);
                    allDiscussionsShowed = "true";
                }
                System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                string   addedDiscussionsJsonList = oSerializer.Serialize(addedDiscussionsList);
                string[] jsonResult = { allDiscussionsShowed, addedDiscussionsJsonList };
                return(Json(jsonResult, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public ActionResult AddMessage(string message, string categoryUrl, string subcategoryUrl, string goodUrl, string goodName, int discussionGroup)
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                if (db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).Any() &&
                    db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).Any() &&
                    db.Goods.Where(x => x.GoodUrl == goodUrl).Any())
                {
                    Discussion newDiscussion = new Discussion
                    {
                        AuthorName             = "Viktor Chugunov",
                        AuthorAvatarSrc        = "",
                        Date                   = DateTime.Now.Date.ToUniversalTime(),
                        Message                = message,
                        FirstDiscussionMessage = discussionGroup == -1 ? true : false,
                        DiscussionGroup        = discussionGroup == -1 ? db.Discussions.Select(p => p.DiscussionGroup).Max() + 1 : discussionGroup
                    };
                    db.Discussions.Add(newDiscussion);

                    List <Good> goodList = db.Goods.Where(x => x.GoodName == goodName).ToList();
                    foreach (var item in goodList)
                    {
                        Good good = db.Goods.Find(item.Id);
                        good.Discussions.Add(newDiscussion);
                    }
                    db.SaveChanges();
                    return(Redirect("/catalog/" + categoryUrl + "/" + subcategoryUrl + "/" + goodUrl + "/Discussions"));
                }
                else
                {
                    return(Redirect("/"));
                }
            }
        }
コード例 #3
0
 public JsonResult FastGoodSearch(string searchInputData)
 {
     using (GoodContext db = new GoodContext())
     {
         var goodList = db.Goods.Where(x => (x.GoodBrand + " " + x.GoodName + " " + x.GoodColor).Contains(searchInputData) ||
                                       (x.GoodBrand + " " + x.GoodColor + " " + x.GoodName).Contains(searchInputData) ||
                                       (x.GoodName + " " + x.GoodBrand + " " + x.GoodColor).Contains(searchInputData) ||
                                       (x.GoodName + " " + x.GoodColor + " " + x.GoodBrand).Contains(searchInputData) ||
                                       (x.GoodColor + " " + x.GoodName + " " + x.GoodBrand).Contains(searchInputData) ||
                                       (x.GoodColor + " " + x.GoodBrand + " " + x.GoodName).Contains(searchInputData))
                        .Select(p => new {
             GoodName     = p.GoodName,
             GoodBrand    = p.GoodBrand,
             GoodImageUrl = "/Content/Images/Goods/"
                            + db.GoodCategories.Where(x => x.Id == db.GoodSubcategories.Where(y => y.Id == db.Goods.Where(z => z.Id == z.Id).FirstOrDefault().GoodSubcategoryId).FirstOrDefault().GoodCategoryId).FirstOrDefault().CategoryUrl
                            + "/" + db.GoodSubcategories.Where(x => x.Id == db.Goods.Where(y => y.Id == y.Id).FirstOrDefault().GoodSubcategoryId).FirstOrDefault().SubcategoryUrl
                            + "/" + p.GoodUrl + "/" + p.GoodImagesUrls.Substring(0, p.GoodImagesUrls.IndexOf("::")),
             GoodPageLink = "/catalog/" + db.GoodCategories.Where(x => x.Id == db.GoodSubcategories.Where(y => y.Id == db.Goods.Where(z => z.Id == z.Id).FirstOrDefault().GoodSubcategoryId).FirstOrDefault().GoodCategoryId).FirstOrDefault().CategoryUrl + "/" + db.GoodSubcategories.Where(x => x.Id == db.Goods.Where(y => y.Id == y.Id).FirstOrDefault().GoodSubcategoryId).FirstOrDefault().SubcategoryUrl + "/" + p.GoodUrl + "/",
             GoodColor    = p.GoodColor,
             GoodPrice    = p.GoodPrice
         }).OrderBy(p => p.GoodColor).ToList();
         int goodListLength = goodList.Count();
         if (goodListLength <= 5)
         {
             goodList = goodList.GetRange(0, goodListLength);
         }
         else
         {
             goodList = goodList.GetRange(0, 5);
         }
         System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
         string jsonGoodList = oSerializer.Serialize(goodList);
         return(Json(jsonGoodList, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #4
0
        public JsonResult ShowMoreReviews(int goodId, int showedReviewsNumber, int addedReviewsNumber)
        {
            using (GoodContext db = new GoodContext())
            {
                var reviewsList = db.Goods.Where(x => x.Id == goodId).First().Reviews
                                  .Select(x => new { Reviewer = x.Reviewer, ReviewerAvatarSrc = x.ReviewerAvatarSrc, Date = x.Date.ToShortDateString(), Advantages = x.Advantages, Disadvantages = x.Disadvantages, Comment = x.Comment, Mark = x.Mark, LikesNumber = x.LikesNumber, DislikesNumber = x.DislikesNumber, ExperienceOfUse = x.ExperienceOfUse })
                                  .ToList();
                int    lastShowedReviewIndex = showedReviewsNumber + addedReviewsNumber;
                int    reviewsListLength     = reviewsList.Count();
                var    addedReviewsList      = reviewsList;
                string allReviewsShowed      = "false";

                if (lastShowedReviewIndex < reviewsListLength)
                {
                    addedReviewsList = reviewsList.GetRange(showedReviewsNumber, addedReviewsNumber);
                }
                else
                {
                    addedReviewsList = reviewsList.GetRange(showedReviewsNumber, reviewsListLength - showedReviewsNumber);
                    allReviewsShowed = "true";
                }
                System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                string   addedReviewsJsonList = oSerializer.Serialize(addedReviewsList);
                string[] jsonResult           = { allReviewsShowed, addedReviewsJsonList };
                return(Json(jsonResult, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #5
0
 public IEnumerable <GoodCategory> GetCategoriesData()
 {
     using (GoodContext db = new GoodContext())
     {
         IEnumerable <GoodCategory> goodCategories = db.GoodCategories.ToList();
         return(goodCategories);
     }
 }
コード例 #6
0
 public ActionResult Catalog()
 {
     using (GoodContext db = new GoodContext())
     {
         ViewBag.CategoriesData = GetCategoriesData();
         ViewBag.PageHeader     = "Catalog";
         return(View());
     }
 }
コード例 #7
0
        public PartialViewResult BreadCrumbs(string pageUrl)
        {
            using (GoodContext db = new GoodContext())
            {
                string[]          pageUrlList     = pageUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                List <BreadCrumb> breadCrumbsList = new List <BreadCrumb>();

                if (pageUrlList.Length == 1 && pageUrlList[0].ToLower() == "cart")
                {
                    BreadCrumb breadCrumbCart = new BreadCrumb {
                        Name = "Cart", Link = "/cart"
                    };
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    breadCrumbsList.AddRange(new BreadCrumb[] { breadCrumbCart, breadCrumbMain });
                }
                else if (pageUrlList.Length == 2 && pageUrlList[0].ToLower() == "cart" && pageUrlList[1].ToLower() == "order-acceptance")
                {
                    string     categoryName   = "Order acceptance";
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbCart = new BreadCrumb {
                        Name = "Cart", Link = "/cart"
                    };
                    BreadCrumb breadCrumbOrderAcceptance = new BreadCrumb {
                        Name = categoryName, Link = "/cart/order-acceptance"
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbOrderAcceptance, breadCrumbCart, breadCrumbMain
                    });
                }
                else
                {
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbUnknown = new BreadCrumb {
                        Name = "Unknown Link", Link = "/"
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbUnknown, breadCrumbMain
                    });
                }

                var viewModel = new BreadCrumbsListViewModel {
                    BreadCrumbsList = breadCrumbsList
                };
                return(PartialView("_BreadCrumbs", viewModel));
            }
        }
コード例 #8
0
        public PartialViewResult BreadCrumbs(string pageUrl)
        {
            using (GoodContext db = new GoodContext())
            {
                string[]          pageUrlList     = pageUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                List <BreadCrumb> breadCrumbsList = new List <BreadCrumb>();

                if (pageUrlList.Length == 2 && pageUrlList[0].ToLower() == "good-search-result")
                {
                    BreadCrumb breadCrumbCatalog = new BreadCrumb {
                        Name = "Good search results", Link = "/good-search-result"
                    };
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    breadCrumbsList.AddRange(new BreadCrumb[] { breadCrumbCatalog, breadCrumbMain });
                }
                else if (pageUrlList.Length == 2 && pageUrlList[0].ToLower() == "cart" && pageUrlList[1].ToLower() == "confirm-order")
                {
                    string     categoryName   = "Confirm order";
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbCart = new BreadCrumb {
                        Name = "Cart", Link = "/cart"
                    };
                    BreadCrumb breadCrumbConfirmOrder = new BreadCrumb {
                        Name = categoryName, Link = "/cart/confirm-order"
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbConfirmOrder, breadCrumbCart, breadCrumbMain
                    });
                }
                else
                {
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbUnknown = new BreadCrumb {
                        Name = "Unknown Link", Link = "/"
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbUnknown, breadCrumbMain
                    });
                }

                var viewModel = new BreadCrumbsListViewModel {
                    BreadCrumbsList = breadCrumbsList
                };
                return(PartialView("_BreadCrumbs", viewModel));
            }
        }
コード例 #9
0
        public ActionResult Discussions(string categoryUrl, string subcategoryUrl, string goodUrl)
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                if (db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).Any() &&
                    db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).Any() &&
                    db.Goods.Where(x => x.GoodUrl == goodUrl).Any())
                {
                    string goodBrand       = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand;
                    string goodName        = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName;
                    string goodColor       = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodColor;
                    string fullGoodName    = goodBrand + " " + goodName + ", " + goodColor;
                    string subcategoryName = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().SubcategoryName;
                    string categoryName    = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;

                    ViewBag.PageHeader = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand + " " +
                                         db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName + " Discussions";
                    ViewBag.CategoryUrl    = categoryUrl;
                    ViewBag.SubcategoryUrl = subcategoryUrl;
                    ViewBag.GoodUrl        = goodUrl;
                    ViewBag.InitiallyShowedDiscussionsNumber = 2;

                    int currentGoodId = db.Goods.Where(x => x.GoodUrl == goodUrl).First().Id;
                    ViewBag.GoodId   = currentGoodId;
                    ViewBag.GoodName = db.Goods.Find(currentGoodId).GoodName;
                    DateTime currentDate = DateTime.Now.Date;
                    var      viewModel   = new DiscussionViewModel()
                    {
                        todayReviewsNumber     = db.Goods.Where(x => x.Id == currentGoodId).First().Discussions.Where(c => c.Date >= currentDate && c.Date <= currentDate.AddDays(1)).Count(),
                        lastWeekReviewsNumber  = db.Goods.Where(x => x.Id == currentGoodId).First().Discussions.Where(c => c.Date >= currentDate.AddDays(-7) && c.Date <= currentDate.AddDays(1)).Count(),
                        lastMonthReviewsNumber = db.Goods.Where(x => x.Id == currentGoodId).First().Discussions.Where(c => c.Date >= currentDate.AddMonths(-1) && c.Date <= currentDate.AddDays(1)).Count(),
                        lastYearReviewsNumber  = db.Goods.Where(x => x.Id == currentGoodId).First().Discussions.Where(c => c.Date >= currentDate.AddYears(-1) && c.Date <= currentDate.AddDays(1)).Count(),
                        allReviewsNumber       = db.Goods.Where(x => x.Id == currentGoodId).First().Discussions.Count(),
                        discussions            = db.Goods.Where(x => x.Id == currentGoodId).First().Discussions.GroupBy(p => p.DiscussionGroup).ToList().Count() <= 2
                                      ? db.Goods.Where(x => x.Id == currentGoodId).First().Discussions.GroupBy(p => p.DiscussionGroup).ToList()
                                      : db.Goods.Where(x => x.Id == currentGoodId).First().Discussions.GroupBy(p => p.DiscussionGroup).ToList().GetRange(0, 2)
                    };
                    List <string> breadcrumbList = new List <string>()
                    {
                        "Discussions", fullGoodName, subcategoryName, categoryName, "Catalog", "Main"
                    };
                    ViewBag.breadCrumbList = breadcrumbList;
                    return(View(viewModel));
                }
                else
                {
                    return(Redirect("/"));
                }
            }
        }
コード例 #10
0
        public ActionResult Subcategory(string categoryUrl, string subcategoryUrl)
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                if (db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).Any() && db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).Any())
                {
                    string pageHeader = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().SubcategoryName;
                    ViewBag.PageHeader = pageHeader;
                    string categoryName = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;

                    ViewBag.CategoryUrl    = categoryUrl;
                    ViewBag.SubcategoryUrl = subcategoryUrl;
                    int currentGoodSubcategoryId = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().Id;
                    //
                    List <GoodViewModel> SubcategoryGoodsList = db.Goods.Where(x => x.GoodSubcategoryId == currentGoodSubcategoryId)
                                                                .Select(p => new GoodViewModel
                    {
                        Id              = p.Id,
                        GoodName        = p.GoodName,
                        GoodBrand       = p.GoodBrand,
                        GoodUrl         = p.GoodUrl,
                        GoodColor       = p.GoodColor,
                        GoodImagesUrls  = p.GoodImagesUrls,
                        GoodPrice       = p.GoodPrice,
                        NewGood         = p.NewGood,
                        SalesGood       = p.SalesGood,
                        RecommendedGood = p.RecommendedGood,
                        ReviewsNumber   = p.Reviews.Count(),
                        GoodRating      = p.Reviews.Any() ? p.Reviews.Average(x => x.Mark) : 0
                    }).ToList();
                    var viewModel = new SubcategoryGoodsViewModel {
                        SubcategoryGoodsList = SubcategoryGoodsList
                    };
                    List <string> breadcrumbList = new List <string>()
                    {
                        pageHeader, categoryName, "Catalog", "Main"
                    };
                    ViewBag.breadCrumbList = breadcrumbList;
                    return(View(viewModel));
                }
                else
                {
                    return(Redirect("/"));
                }
            }
        }
コード例 #11
0
 public ActionResult Reviews(string categoryUrl, string subcategoryUrl, string goodUrl)
 {
     using (GoodContext db = new GoodContext())
     {
         ViewBag.CategoriesData = GetCategoriesData();
         if (db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).Any() &&
             db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).Any() &&
             db.Goods.Where(x => x.GoodUrl == goodUrl).Any())
         {
             string goodBrand       = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand;
             string goodName        = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName;
             string goodColor       = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodColor;
             string fullGoodName    = goodBrand + " " + goodName + ", " + goodColor;
             string subcategoryName = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().SubcategoryName;
             string categoryName    = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;
             ViewBag.PageHeader = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand + " " +
                                  db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName + " Reviews";
             ViewBag.CategoryUrl    = categoryUrl;
             ViewBag.SubcategoryUrl = subcategoryUrl;
             ViewBag.GoodUrl        = goodUrl;
             ViewBag.InitiallyShowedReviewsNumber = 2;
             int currentGoodId = db.Goods.Where(x => x.GoodUrl == goodUrl).First().Id;
             ViewBag.GoodId   = currentGoodId;
             ViewBag.GoodName = db.Goods.Find(currentGoodId).GoodName;
             var viewModel = new ReviewViewModel()
             {
                 goodRating = db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Any() ?
                              db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Average(x => x.Mark) : 0,
                 reviewsNumberList = GetReviewsNumberList(currentGoodId),
                 goodReviewsList   = db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.ToList().Count() <= 2
                                                               ? db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.ToList()
                                                               : db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.ToList().GetRange(0, 2)
             };
             List <string> breadcrumbList = new List <string>()
             {
                 "Reviews", fullGoodName, subcategoryName, categoryName, "Catalog", "Main"
             };
             ViewBag.breadCrumbList = breadcrumbList;
             return(View(viewModel));
         }
         else
         {
             return(Redirect("/"));
         }
     }
 }
コード例 #12
0
 public int[] GetRandomItemsIndexesList(int currentGoodId)
 {
     using (GoodContext db = new GoodContext())
     {
         int[]      randomItemsIndexes = new int[4];
         List <int> goodsIdList        = db.Goods.Select(p => p.Id).ToList();
         goodsIdList.RemoveAt(goodsIdList.IndexOf(currentGoodId));
         Random randomNumber = new Random();
         for (int i = 0; i < 4; i++)
         {
             int randomIndex = randomNumber.Next(0, goodsIdList.Count());
             randomItemsIndexes[i] = goodsIdList[randomIndex];
             goodsIdList.RemoveAt(randomIndex);
         }
         return(randomItemsIndexes);
     }
 }
コード例 #13
0
        public ActionResult ConfirmOrder(OrderInformation orderInformation)
        {
            using (GoodContext db = new GoodContext())
            {
                Order order = new Order
                {
                    GoodIdArray            = string.Join(";", string.Join(";", new List <int>(orderInformation.GoodIdArray).ConvertAll(i => i.ToString()).ToArray())),
                    GoodNameArray          = string.Join(";", orderInformation.GoodNameArray),
                    GoodLinkArray          = string.Join(";", orderInformation.GoodLinkArray),
                    GoodImageUrlArray      = string.Join(";", orderInformation.GoodImageUrlArray),
                    GoodQuantityArray      = string.Join(";", new List <int>(orderInformation.GoodQuantityArray).ConvertAll(i => i.ToString()).ToArray()),
                    GoodPriceArray         = string.Join(";", string.Join(";", new List <double>(orderInformation.GoodPriceArray).ConvertAll(i => i.ToString()).ToArray())),
                    GoodTotalPriceArray    = string.Join(";", new List <double>(orderInformation.GoodTotalPriceArray).ConvertAll(i => i.ToString()).ToArray()),
                    GoodsTotalPrice        = orderInformation.GoodsTotalPrice,
                    DeliveryPrice          = orderInformation.DeliveryPrice,
                    CustomerName           = orderInformation.CustomerName,
                    CardOwnerName          = orderInformation.CardOwnerName,
                    CardNumber             = orderInformation.CardNumber,
                    CardMonth              = orderInformation.CardMonth,
                    CardYear               = orderInformation.CardYear,
                    CardCvv                = orderInformation.CardCvv,
                    BankSystem             = orderInformation.BankSystem,
                    AddresseeFirstName     = orderInformation.AddresseeFirstName,
                    AddresseeSecondName    = orderInformation.AddresseeSecondName,
                    AddresseeCountry       = orderInformation.AddresseeCountry,
                    AddresseeRegion        = orderInformation.AddresseeRegion,
                    AddresseeCity          = orderInformation.AddresseeCity,
                    AddresseeIndex         = orderInformation.AddresseeIndex,
                    AddresseeStreetAddress = orderInformation.AddresseeStreetAddress,
                    AddresseePhoneNumber   = orderInformation.AddresseePhoneNumber,
                    AddresseeEmail         = orderInformation.AddresseeEmail,
                    DeliveryMethods        = orderInformation.DeliveryMethods
                };
                db.Orders.Add(order);
                db.SaveChanges();

                int orderNumber = db.Orders.Max(p => p.Id);
                SendMail(orderInformation, orderNumber);
                Session["GoodIdList"] = null;

                TempData["orderInformation"] = orderInformation;
                return(Redirect("/cart/order-acceptance"));
            }
        }
コード例 #14
0
        // GET: Cart
        public ActionResult Index()
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                ViewBag.PageHeader     = "Cart";

                CartGoodsListViewModel viewModel = new CartGoodsListViewModel {
                };
                if ((List <int>)Session["GoodIdList"] != null)
                {
                    List <CartGoodViewModel> cartGoodsList = new List <CartGoodViewModel>()
                    {
                    };
                    foreach (int currentGoodId in (List <int>)Session["GoodIdList"])
                    {
                        int goodSubcategoryId = db.Goods.Where(x => x.Id == currentGoodId).First().GoodSubcategoryId;
                        int goodCategoryId    = db.GoodSubcategories.Where(x => x.Id == goodSubcategoryId).First().GoodCategoryId;

                        string            goodSubcategoryUrl = db.GoodSubcategories.Where(x => x.Id == goodSubcategoryId).First().SubcategoryUrl;
                        string            goodCategoryUrl    = db.GoodCategories.Where(x => x.Id == goodCategoryId).First().CategoryUrl;
                        CartGoodViewModel goodInfo           = db.Goods.Where(x => x.Id == currentGoodId)
                                                               .Select(p => new CartGoodViewModel
                        {
                            Id                 = p.Id,
                            GoodName           = p.GoodName,
                            GoodBrand          = p.GoodBrand,
                            GoodCategoryUrl    = goodCategoryUrl,
                            GoodSubcategoryUrl = goodSubcategoryUrl,
                            GoodUrl            = p.GoodUrl,
                            GoodColor          = p.GoodColor,
                            GoodImagesUrls     = p.GoodImagesUrls,
                            GoodPrice          = p.GoodPrice,
                            SalesGood          = p.SalesGood
                        }).First();
                        cartGoodsList.Add(goodInfo);
                    }
                    viewModel = new CartGoodsListViewModel {
                        CartGoodsList = cartGoodsList
                    };
                }
                return(View(viewModel));
            }
        }
コード例 #15
0
 public ActionResult Category(string categoryUrl)
 {
     ViewBag.CategoriesData = GetCategoriesData();
     using (GoodContext db = new GoodContext())
     {
         if (db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).Any())
         {
             string pageHeader = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;
             ViewBag.PageHeader        = pageHeader;
             ViewBag.CategoryUrl       = categoryUrl;
             ViewBag.SubcategoriesList = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().GoodSubcategories;
             return(View());
         }
         else
         {
             return(Redirect("/"));
         }
     }
 }
コード例 #16
0
 public int[] GetReviewsNumberList(int currentGoodId)
 {
     using (GoodContext db = new GoodContext())
     {
         int reviewsNumber            = db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Any() ? db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Count() : 0;
         int reviewsNumberWithMarkOne = db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 1).Any() ?
                                        db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 1).Count() : 0;
         int reviewsNumberWithMarkTwo = db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 2).Any() ?
                                        db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 2).Count() : 0;
         int reviewsNumberWithMarkThree = db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 3).Any() ?
                                          db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 3).Count() : 0;
         int reviewsNumberWithMarkFour = db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 4).Any() ?
                                         db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 4).Count() : 0;
         int reviewsNumberWithMarkFive = db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 5).Any() ?
                                         db.Goods.Where(x => x.Id == currentGoodId).First().Reviews.Where(x => x.Mark == 5).Count() : 0;
         int[] reviewsNumberList = new[] { reviewsNumberWithMarkOne, reviewsNumberWithMarkTwo, reviewsNumberWithMarkThree, reviewsNumberWithMarkFour, reviewsNumberWithMarkFive };
         return(reviewsNumberList);
     }
 }
コード例 #17
0
        public ActionResult AddReview(string advantages, string disadvantages, string comment, string experienceOfUse, int mark, string categoryUrl, string subcategoryUrl, string goodUrl, string goodName)
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                if (db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).Any() &&
                    db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).Any() &&
                    db.Goods.Where(x => x.GoodUrl == goodUrl).Any())
                {
                    Review newReview = new Review {
                        Reviewer          = "asdasd",
                        ReviewerAvatarSrc = "",
                        Date            = DateTime.Now.Date.ToUniversalTime(),
                        Advantages      = advantages,
                        Disadvantages   = disadvantages,
                        Comment         = comment,
                        ExperienceOfUse = experienceOfUse,
                        Mark            = mark,
                        LikesNumber     = 0,
                        DislikesNumber  = 0
                    };
                    db.Reviews.Add(newReview);

                    List <Good> goodList = db.Goods.Where(x => x.GoodName == goodName).ToList();
                    foreach (var item in goodList)
                    {
                        Good good = db.Goods.Find(item.Id);
                        good.Reviews.Add(newReview);
                    }
                    db.SaveChanges();
                    return(Redirect("/catalog/" + categoryUrl + "/" + subcategoryUrl + "/" + goodUrl + "/Reviews"));
                }
                else
                {
                    return(Redirect("/"));
                }
            }
        }
コード例 #18
0
 public PartialViewResult SimilarOffers(string CategoryUrl, string SubcategoryUrl, string goodUrl)
 {
     using (GoodContext db = new GoodContext())
     {
         int currentGoodId = db.Goods.Where(x => x.GoodUrl == goodUrl).First().Id;
         ViewBag.CategoryUrl = CategoryUrl;
         int[] randomItemsIndexes             = GetRandomItemsIndexesList(currentGoodId);
         List <GoodViewModel> RandomGoodsList = new List <GoodViewModel>(4);
         for (int i = 0; i < 4; i++)
         {
             int randomGoodItem = randomItemsIndexes[i];
             var RandomGoodData = db.Goods.Where(x => x.Id == randomGoodItem)
                                  .Select(p => new GoodViewModel
             {
                 Id                 = p.Id,
                 GoodName           = p.GoodName,
                 GoodBrand          = p.GoodBrand,
                 GoodCategoryUrl    = db.Goods.Where(x => x.Id == randomGoodItem).FirstOrDefault().GoodSubcategory.GoodCategory.CategoryUrl,
                 GoodSubcategoryUrl = db.Goods.Where(x => x.Id == randomGoodItem).FirstOrDefault().GoodSubcategory.SubcategoryUrl,
                 GoodUrl            = p.GoodUrl,
                 GoodColor          = p.GoodColor,
                 GoodImagesUrls     = p.GoodImagesUrls,
                 GoodPrice          = p.GoodPrice,
                 NewGood            = p.NewGood,
                 SalesGood          = p.SalesGood,
                 RecommendedGood    = p.RecommendedGood,
                 ReviewsNumber      = p.Reviews.Count(),
                 GoodRating         = p.Reviews.Any() ? p.Reviews.Average(x => x.Mark) : 0,
                 Characteristics    = p.Characteristics
             }).FirstOrDefault();
             RandomGoodsList.Add(RandomGoodData);
         }
         var viewModel = new RandomGoodViewModel {
             RandomGoodsList = RandomGoodsList
         };
         return(PartialView("SimilarOffers", viewModel));
     }
 }
コード例 #19
0
        public ActionResult Overview(string categoryUrl, string subcategoryUrl, string goodUrl)
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                if (db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).Any() &&
                    db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).Any() &&
                    db.Goods.Where(x => x.GoodUrl == goodUrl).Any())
                {
                    string goodBrand       = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand;
                    string goodName        = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName;
                    string goodColor       = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodColor;
                    string fullGoodName    = goodBrand + " " + goodName + ", " + goodColor;
                    string subcategoryName = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().SubcategoryName;
                    string categoryName    = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;

                    ViewBag.PageHeader = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand + " " +
                                         db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName + " Overview";
                    ViewBag.CategoryUrl    = categoryUrl;
                    ViewBag.SubcategoryUrl = subcategoryUrl;
                    ViewBag.GoodUrl        = goodUrl;
                    int currentGoodId = db.Goods.Where(x => x.GoodUrl == goodUrl).First().Id;
                    ViewBag.goodOverview = db.Goods.Where(x => x.Id == currentGoodId).First().Overviews.Any() == true?db.Goods.Where(x => x.Id == currentGoodId).First().Overviews.First().Text : "<p class='no-overview-message'>There is no overview</p>";

                    List <string> breadcrumbList = new List <string>()
                    {
                        "Overview", fullGoodName, subcategoryName, categoryName, "Catalog", "Main"
                    };
                    ViewBag.breadCrumbList = breadcrumbList;
                    return(View());
                }
                else
                {
                    return(Redirect("/"));
                }
            }
        }
コード例 #20
0
        public ActionResult GoodSearch(string searchInputData)
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                ViewBag.PageHeader     = "Good Search Results";

                var GoodSearchResultList = db.Goods.Where(x => (x.GoodBrand + " " + x.GoodName + " " + x.GoodColor).Contains(searchInputData) ||
                                                          (x.GoodBrand + " " + x.GoodColor + " " + x.GoodName).Contains(searchInputData) ||
                                                          (x.GoodName + " " + x.GoodBrand + " " + x.GoodColor).Contains(searchInputData) ||
                                                          (x.GoodName + " " + x.GoodColor + " " + x.GoodBrand).Contains(searchInputData) ||
                                                          (x.GoodColor + " " + x.GoodName + " " + x.GoodBrand).Contains(searchInputData) ||
                                                          (x.GoodColor + " " + x.GoodBrand + " " + x.GoodName).Contains(searchInputData))
                                           .Select(p => new GoodViewModel
                {
                    Id                 = p.Id,
                    GoodName           = p.GoodName,
                    GoodBrand          = p.GoodBrand,
                    GoodCategoryUrl    = db.Goods.Where(x => x.Id == p.Id).FirstOrDefault().GoodSubcategory.GoodCategory.CategoryUrl,
                    GoodSubcategoryUrl = db.Goods.Where(x => x.Id == p.Id).FirstOrDefault().GoodSubcategory.SubcategoryUrl,
                    GoodUrl            = p.GoodUrl,
                    GoodColor          = p.GoodColor,
                    GoodImagesUrls     = p.GoodImagesUrls,
                    GoodPrice          = p.GoodPrice,
                    NewGood            = p.NewGood,
                    SalesGood          = p.SalesGood,
                    RecommendedGood    = p.RecommendedGood,
                    ReviewsNumber      = p.Reviews.Count(),
                    GoodRating         = p.Reviews.Any() ? p.Reviews.Average(x => x.Mark) : 0,
                    Characteristics    = p.Characteristics
                }).ToList();
                var viewModel = new GoodSearchResultsViewModel {
                    GoodSearchResult = GoodSearchResultList
                };
                return(View(viewModel));
            }
        }
コード例 #21
0
 public HomeController(GoodContext context)
 {
     db = context;
 }
コード例 #22
0
        public ActionResult Index()
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                MainPageViewModel viewModel          = new MainPageViewModel {
                };
                List <GoodViewModel> viewedGoodsList = new List <GoodViewModel>()
                {
                };

                if ((List <int>)Session["recentlyViewedGoods"] != null)
                {
                    foreach (int currentGoodId in (List <int>)Session["recentlyViewedGoods"])
                    {
                        int goodSubcategoryId = db.Goods.Where(x => x.Id == currentGoodId).First().GoodSubcategoryId;
                        int goodCategoryId    = db.GoodSubcategories.Where(x => x.Id == goodSubcategoryId).First().GoodCategoryId;

                        string        goodSubcategoryUrl = db.GoodSubcategories.Where(x => x.Id == goodSubcategoryId).First().SubcategoryUrl;
                        string        goodCategoryUrl    = db.GoodCategories.Where(x => x.Id == goodCategoryId).First().CategoryUrl;
                        GoodViewModel goodInfo           = db.Goods.Where(x => x.Id == currentGoodId)
                                                           .Select(p => new GoodViewModel
                        {
                            Id                 = p.Id,
                            GoodName           = p.GoodName,
                            GoodBrand          = p.GoodBrand,
                            GoodCategoryUrl    = goodCategoryUrl,
                            GoodSubcategoryUrl = goodSubcategoryUrl,
                            GoodUrl            = p.GoodUrl,
                            GoodColor          = p.GoodColor,
                            GoodImagesUrls     = p.GoodImagesUrls,
                            GoodPrice          = p.GoodPrice,
                            SalesGood          = p.SalesGood
                        }).First();
                        viewedGoodsList.Add(goodInfo);
                    }
                }

                List <GoodViewModel> interestingGoodsList = new List <GoodViewModel>()
                {
                };
                if (HttpContext.Request.RawUrl == "/sales-goods")
                {
                    interestingGoodsList = db.Goods.Where(x => x.SalesGood == true)
                                           .Select(p => new GoodViewModel
                    {
                        Id                 = p.Id,
                        GoodName           = p.GoodName,
                        GoodBrand          = p.GoodBrand,
                        GoodCategoryUrl    = db.GoodCategories.Where(x => x.Id == db.Goods.Where(y => y.Id == p.Id).FirstOrDefault().GoodSubcategory.GoodCategoryId).FirstOrDefault().CategoryUrl,
                        GoodSubcategoryUrl = db.Goods.Where(x => x.Id == p.Id).FirstOrDefault().GoodSubcategory.SubcategoryUrl,
                        GoodUrl            = p.GoodUrl,
                        GoodColor          = p.GoodColor,
                        GoodImagesUrls     = p.GoodImagesUrls,
                        GoodPrice          = p.GoodPrice,
                        NewGood            = p.NewGood,
                        SalesGood          = p.SalesGood,
                        RecommendedGood    = p.RecommendedGood,
                        ReviewsNumber      = p.Reviews.Count(),
                        GoodRating         = p.Reviews.Any() ? p.Reviews.Average(x => x.Mark) : 0
                    }).ToList().GetRange(0, 8);
                }
                else if (HttpContext.Request.RawUrl == "/recommended-goods")
                {
                    interestingGoodsList = db.Goods.Where(x => x.RecommendedGood == true)
                                           .Select(p => new GoodViewModel
                    {
                        Id                 = p.Id,
                        GoodName           = p.GoodName,
                        GoodBrand          = p.GoodBrand,
                        GoodCategoryUrl    = db.GoodCategories.Where(x => x.Id == db.Goods.Where(y => y.Id == p.Id).FirstOrDefault().GoodSubcategory.GoodCategoryId).FirstOrDefault().CategoryUrl,
                        GoodSubcategoryUrl = db.Goods.Where(x => x.Id == p.Id).FirstOrDefault().GoodSubcategory.SubcategoryUrl,
                        GoodUrl            = p.GoodUrl,
                        GoodColor          = p.GoodColor,
                        GoodImagesUrls     = p.GoodImagesUrls,
                        GoodPrice          = p.GoodPrice,
                        NewGood            = p.NewGood,
                        SalesGood          = p.SalesGood,
                        RecommendedGood    = p.RecommendedGood,
                        ReviewsNumber      = p.Reviews.Count(),
                        GoodRating         = p.Reviews.Any() ? p.Reviews.Average(x => x.Mark) : 0
                    }).ToList().GetRange(0, 8);
                }
                else if (HttpContext.Request.RawUrl == "/new-goods")
                {
                    interestingGoodsList = db.Goods.Where(x => x.NewGood == true)
                                           .Select(p => new GoodViewModel
                    {
                        Id                 = p.Id,
                        GoodName           = p.GoodName,
                        GoodBrand          = p.GoodBrand,
                        GoodCategoryUrl    = db.GoodCategories.Where(x => x.Id == db.Goods.Where(y => y.Id == p.Id).FirstOrDefault().GoodSubcategory.GoodCategoryId).FirstOrDefault().CategoryUrl,
                        GoodSubcategoryUrl = db.Goods.Where(x => x.Id == p.Id).FirstOrDefault().GoodSubcategory.SubcategoryUrl,
                        GoodUrl            = p.GoodUrl,
                        GoodColor          = p.GoodColor,
                        GoodImagesUrls     = p.GoodImagesUrls,
                        GoodPrice          = p.GoodPrice,
                        NewGood            = p.NewGood,
                        SalesGood          = p.SalesGood,
                        RecommendedGood    = p.RecommendedGood,
                        ReviewsNumber      = p.Reviews.Count(),
                        GoodRating         = p.Reviews.Any() ? p.Reviews.Average(x => x.Mark) : 0
                    }).ToList().GetRange(0, 8);
                }
                else
                {
                    interestingGoodsList = db.Goods.Where(x => x.SalesGood == true || x.NewGood == true || x.RecommendedGood == true)
                                           .Select(p => new GoodViewModel
                    {
                        Id                 = p.Id,
                        GoodName           = p.GoodName,
                        GoodBrand          = p.GoodBrand,
                        GoodCategoryUrl    = db.GoodCategories.Where(x => x.Id == db.Goods.Where(y => y.Id == p.Id).FirstOrDefault().GoodSubcategory.GoodCategoryId).FirstOrDefault().CategoryUrl,
                        GoodSubcategoryUrl = db.Goods.Where(x => x.Id == p.Id).FirstOrDefault().GoodSubcategory.SubcategoryUrl,
                        GoodUrl            = p.GoodUrl,
                        GoodColor          = p.GoodColor,
                        GoodImagesUrls     = p.GoodImagesUrls,
                        GoodPrice          = p.GoodPrice,
                        NewGood            = p.NewGood,
                        SalesGood          = p.SalesGood,
                        RecommendedGood    = p.RecommendedGood,
                        ReviewsNumber      = p.Reviews.Count(),
                        GoodRating         = p.Reviews.Any() ? p.Reviews.Average(x => x.Mark) : 0
                    }).ToList().GetRange(0, 8);
                }
                viewModel = new MainPageViewModel {
                    InterestingGoodsList = interestingGoodsList, ViewedGoodsList = viewedGoodsList
                };
                return(View(viewModel));
            }
        }
コード例 #23
0
 public GoodsController(GoodContext context)
 {
     _context = context;
 }
コード例 #24
0
 public UserRepository(GoodContext db)
 {
     this.db = db;
 }
コード例 #25
0
        public PartialViewResult BreadCrumbs(string pageUrl)
        {
            using (GoodContext db = new GoodContext())
            {
                string[]          pageUrlList     = pageUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                List <BreadCrumb> breadCrumbsList = new List <BreadCrumb>();

                if (pageUrlList.Length == 1 && pageUrlList[0].ToLower() == "catalog")
                {
                    BreadCrumb breadCrumbCatalog = new BreadCrumb {
                        Name = "Catalog", Link = "/catalog"
                    };
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    breadCrumbsList.AddRange(new BreadCrumb[] { breadCrumbCatalog, breadCrumbMain });
                }
                else if (pageUrlList.Length == 2 && pageUrlList[0].ToLower() == "catalog")
                {
                    string     categoryUrl    = pageUrlList[1];
                    string     categoryName   = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbCatalog = new BreadCrumb {
                        Name = "Catalog", Link = "/catalog"
                    };
                    BreadCrumb breadCrumbCategory = new BreadCrumb {
                        Name = categoryName, Link = "/catalog/" + categoryUrl
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbCategory, breadCrumbCatalog, breadCrumbMain
                    });
                }
                else if (pageUrlList.Length == 3 && pageUrlList[0].ToLower() == "catalog")
                {
                    string     categoryUrl     = pageUrlList[1];
                    string     subcategoryUrl  = pageUrlList[2];
                    string     categoryName    = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;
                    string     subcategoryName = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().SubcategoryName;
                    BreadCrumb breadCrumbMain  = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbCatalog = new BreadCrumb {
                        Name = "Catalog", Link = "/catalog"
                    };
                    BreadCrumb breadCrumbCategory = new BreadCrumb {
                        Name = categoryName, Link = "/catalog/" + categoryUrl
                    };
                    BreadCrumb breadCrumbSubcategory = new BreadCrumb {
                        Name = subcategoryName, Link = "/catalog/" + categoryUrl + "/" + subcategoryUrl
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbSubcategory, breadCrumbCategory, breadCrumbCatalog, breadCrumbMain
                    });
                }
                else if (pageUrlList.Length == 4 && pageUrlList[0].ToLower() == "catalog")
                {
                    string categoryUrl    = pageUrlList[1];
                    string subcategoryUrl = pageUrlList[2];
                    string goodUrl        = pageUrlList[3];

                    string categoryName    = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;
                    string subcategoryName = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().SubcategoryName;
                    string goodName        = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand + " " +
                                             db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName + ", " +
                                             db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodColor;

                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbCatalog = new BreadCrumb {
                        Name = "Catalog", Link = "/catalog"
                    };
                    BreadCrumb breadCrumbCategory = new BreadCrumb {
                        Name = categoryName, Link = "/catalog/" + categoryUrl
                    };
                    BreadCrumb breadCrumbSubcategory = new BreadCrumb {
                        Name = subcategoryName, Link = "/catalog/" + categoryUrl + "/" + subcategoryUrl
                    };
                    BreadCrumb breadCrumbGood = new BreadCrumb {
                        Name = goodName, Link = "/catalog/" + categoryUrl + "/" + subcategoryUrl + "/" + goodUrl
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbGood, breadCrumbSubcategory, breadCrumbCategory, breadCrumbCatalog, breadCrumbMain
                    });
                }
                else if (pageUrlList.Length == 5 && pageUrlList[0].ToLower() == "catalog" && (pageUrlList[4].ToLower() == "reviews" || pageUrlList[4].ToLower() == "discussions" || pageUrlList[4].ToLower() == "overview"))
                {
                    string categoryUrl     = pageUrlList[1];
                    string subcategoryUrl  = pageUrlList[2];
                    string goodUrl         = pageUrlList[3];
                    string categoryName    = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;
                    string subcategoryName = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().SubcategoryName;
                    string goodName        = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand + " " +
                                             db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName + ", " +
                                             db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodColor;
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbCatalog = new BreadCrumb {
                        Name = "Catalog", Link = "/catalog"
                    };
                    BreadCrumb breadCrumbCategory = new BreadCrumb {
                        Name = categoryName, Link = "/catalog/" + categoryUrl
                    };
                    BreadCrumb breadCrumbSubcategory = new BreadCrumb {
                        Name = subcategoryName, Link = "/catalog/" + categoryUrl + "/" + subcategoryUrl
                    };
                    BreadCrumb breadCrumbGood = new BreadCrumb {
                        Name = goodName, Link = "/catalog/" + categoryUrl + "/" + subcategoryUrl + "/" + goodUrl
                    };
                    BreadCrumb breadCrumbGoodOption = new BreadCrumb {
                        Name = pageUrlList[4], Link = "/catalog/" + categoryUrl + "/" + subcategoryUrl + "/" + goodUrl + "/" + pageUrlList[4]
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbGoodOption, breadCrumbGood, breadCrumbSubcategory, breadCrumbCategory, breadCrumbCatalog, breadCrumbMain
                    });
                }
                else
                {
                    BreadCrumb breadCrumbMain = new BreadCrumb {
                        Name = "Main", Link = "/"
                    };
                    BreadCrumb breadCrumbUnknown = new BreadCrumb {
                        Name = "Unknown Link", Link = "/"
                    };
                    breadCrumbsList.AddRange(new List <BreadCrumb>()
                    {
                        breadCrumbUnknown, breadCrumbMain
                    });
                }
                var viewModel = new BreadCrumbsListViewModel {
                    BreadCrumbsList = breadCrumbsList
                };
                return(PartialView("_BreadCrumbs", viewModel));
            }
        }
コード例 #26
0
        public ActionResult Good(string categoryUrl, string subcategoryUrl, string goodUrl)
        {
            using (GoodContext db = new GoodContext())
            {
                ViewBag.CategoriesData = GetCategoriesData();
                if (db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).Any() &&
                    db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).Any() &&
                    db.Goods.Where(x => x.GoodUrl == goodUrl).Any())
                {
                    string goodBrand       = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodBrand;
                    string goodName        = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodName;
                    string goodColor       = db.Goods.Where(x => x.GoodUrl == goodUrl).First().GoodColor;
                    string pageHeader      = goodBrand + " " + goodName + ", " + goodColor;
                    string subcategoryName = db.GoodSubcategories.Where(x => x.SubcategoryUrl == subcategoryUrl).First().SubcategoryName;
                    string categoryName    = db.GoodCategories.Where(x => x.CategoryUrl == categoryUrl).First().CategoryName;

                    ViewBag.PageHeader     = pageHeader;
                    ViewBag.CategoryUrl    = categoryUrl;
                    ViewBag.SubcategoryUrl = subcategoryUrl;
                    ViewBag.GoodUrl        = goodUrl;
                    int currentGoodId = db.Goods.Where(x => x.GoodUrl == goodUrl).First().Id;

                    //Add current Good to Session
                    if (Session["recentlyViewedGoods"] == null)
                    {
                        Session["recentlyViewedGoods"] = new List <int>()
                        {
                        };
                    }
                    if (!(Session["recentlyViewedGoods"] as List <int>).Contains(currentGoodId))
                    {
                        int listLength = (Session["recentlyViewedGoods"] as List <int>).Count();
                        if (listLength >= 4)
                        {
                            (Session["recentlyViewedGoods"] as List <int>).Insert(0, currentGoodId);
                            Session["recentlyViewedGoods"] = (Session["recentlyViewedGoods"] as List <int>).GetRange(0, 4);
                        }
                        else
                        {
                            (Session["recentlyViewedGoods"] as List <int>).Insert(0, currentGoodId);
                        }
                    }

                    var viewModel = db.Goods.Where(x => x.Id == currentGoodId)
                                    .Select(p => new GoodViewModel
                    {
                        Id        = p.Id,
                        GoodName  = p.GoodName,
                        GoodBrand = p.GoodBrand,
                        GoodUrl   = p.GoodUrl,
                        GoodColor = p.GoodColor,
                        SameGoodColorsAndLinksList = db.Goods.Where(x => x.GoodName == goodName).Select(x => new SameGoodColorsAndLinks {
                            GoodColor = x.GoodColor, GoodUrl = x.GoodUrl
                        }).ToList(),
                        GoodImagesUrls  = p.GoodImagesUrls,
                        GoodPrice       = p.GoodPrice,
                        NewGood         = p.NewGood,
                        SalesGood       = p.SalesGood,
                        RecommendedGood = p.RecommendedGood,
                        ReviewsNumber   = p.Reviews.Count(),
                        GoodRating      = p.Reviews.Any() ? p.Reviews.Average(x => x.Mark) : 0,
                        Characteristics = p.Characteristics
                    }).First();
                    return(View(viewModel));
                }
                else
                {
                    return(Redirect("/"));
                }
            }
        }