コード例 #1
0
        public ActionResult ModelDetails(int id)
        {
            if (User.IsInRole("Supplier"))
                return RedirectToAction("Index", "Supplier");

            if (User.IsInRole("Admin"))
                return RedirectToAction("Index", "Admin");

            dynamic model = new ExpandoObject();

            if (id < 0)
            {
                return RedirectToAction("Error404", "Home");
            }
            var modelDetails = new HomeCatalogViewModel()
            {
                ModelId = id,
                ModelNumber = db.Models.Find(id).ModelNumber,
                Price = db.Models.Find(id).Price,
                BrandName = (from m in db.Models
                             join b in db.Brands on m.BrandId equals b.BrandId
                             where m.ModelId == id
                             select b.Name).FirstOrDefault(),
                ImageUrl = (from ph in db.Photos
                            join pm in db.PhotoModels on ph.PhotoId equals pm.PhotoId
                            join m in db.Models on pm.ModelId equals m.ModelId
                            where pm.ModelId == id
                            select ph.ImageUrl).FirstOrDefault(),

                Supplier = (from m in db.Models
                            join u in db.Users on m.UserId equals u.Id
                            where m.ModelId == id
                            select u.Name).FirstOrDefault()
            };
            model.Info = modelDetails;

            var modelSpecRecords = (from ms in db.ModelSpecs
                                    where ms.ModelId == id
                                    select ms).ToList();

            var modelSpecList = new List<ModelSpecificationDetails>();

            foreach (var item in modelSpecRecords)
            {
                var modelSpecification = new ModelSpecificationDetails()
                {
                    SpecificationName = (from sp in db.Specifications
                                         join modelSpecs in db.ModelSpecs on sp.SpecificationId equals modelSpecs.SpecificationId
                                         where modelSpecs.SpecificationId == item.SpecificationId && modelSpecs.ModelId == id
                                         select sp.Description).FirstOrDefault(),
                    SpecificationValue = item.Value,
                    SpecialCategoryName = (from sp in db.SpecialCategories
                                           join s in db.Specifications on sp.SpecialCatId equals s.SpecialCatId
                                           where s.SpecificationId == item.SpecificationId
                                           select sp.Description).FirstOrDefault(),

                    SpecialCategoryPosition = (from sp in db.SpecialCategories
                                               join s in db.Specifications on sp.SpecialCatId equals s.SpecialCatId
                                               where s.SpecificationId == item.SpecificationId
                                               select sp.Position).FirstOrDefault()
                };
                modelSpecList.Add(modelSpecification);
            }

            model.SpecificationDetails = modelSpecList.GroupBy(m => m.SpecialCategoryName).ToDictionary(g => g.Key, g => g.ToList());

            int modelItemId = (from m in db.Models
                               where m.ModelId == id
                               select m.ItemId).FirstOrDefault();
            var relatedRecords = (from m in db.Models
                                  where m.ItemId == modelItemId && m.Status == "Active"
                                  select m).ToList();
            var relatedList = new List<HomeCatalogViewModel>();
            foreach (var item in relatedRecords.OrderBy(f => Guid.NewGuid()).Take(15))
            {
                var relatedItem = new HomeCatalogViewModel()
                {
                    ModelId = item.ModelId,
                    ModelNumber = item.ModelNumber,
                    Price = item.Price,
                    BrandName = (from m in db.Models
                                 join b in db.Brands on m.BrandId equals b.BrandId
                                 where m.ModelId == item.ModelId
                                 select b.Name).FirstOrDefault(),
                    ImageUrl = (from ph in db.Photos
                                join pm in db.PhotoModels on ph.PhotoId equals pm.PhotoId
                                join m in db.Models on pm.ModelId equals m.ModelId
                                where pm.ModelId == item.ModelId
                                select ph.ImageUrl).FirstOrDefault(),
                    DtCreated = (from m in db.Models
                                 where m.ModelId == item.ModelId
                                 select m.DtCreated).FirstOrDefault()
                };
                relatedList.Add(relatedItem);
            }
            model.RelatedProducts = relatedList;

            var ratingSum = db.RatingModels.Where(r => r.ModelId == id).ToList().Sum(r => r.RatingId);
            var ratingCount = db.RatingModels.Where(r => r.ModelId == id).ToList().Count();

            if (ratingSum <= 0 || ratingCount <= 0)
            {
                ratingSum = 1;
                ratingCount = 1;
            }
            int averageRating = ratingSum / ratingCount;
            ViewBag.ratingCount = ratingCount;
            ViewBag.AverageRating = averageRating;

            var reviewRecords = db.Reviews.Where(r => r.ModelId == id).ToList();
            var reviewList = new List<ReviewRatingViewModel>();
            foreach (var item in reviewRecords)
            {
                var reviewItem = new ReviewRatingViewModel()
                {
                    UserName = (from u in db.Users
                                where u.Id == item.UserId
                                select u.Name).FirstOrDefault(),
                    Description = item.Description,
                    DtCreated = item.DtCreated
                };
                reviewList.Add(reviewItem);
            }

            ViewBag.Reviews = reviewList.OrderByDescending(r => r.DtCreated);

            return View(model);
        }
コード例 #2
0
        public ActionResult SupplierGetOrderDetailsForReturn(int id)
        {
            if (User.IsInRole("Supplier"))
            {
                var record = db.Orders.Where(o => o.OrderId == id).FirstOrDefault();
                SupplierGetOrderViewModel orderDetails = new SupplierGetOrderViewModel()
                {
                    OrderId = record.OrderId,
                    CustomerName = (from c in db.Customers
                                    where c.CustomerId == record.CustomerId
                                    select c.Name).FirstOrDefault(),
                    ModelNumber = (from m in db.Models
                                   where m.ModelId == record.ModelId
                                   select m.ModelNumber).FirstOrDefault(),
                    Status = record.Status,
                    Total = record.Total,
                    Quantity = record.Quantity,
                    GrandTotal = record.Total,
                    DtCreated = record.DtCreated,
                    ExpectedDeliveryDate = record.ExpectedDeliveryDate,
                    RealDeliveryDate = record.RealDeliveryDate,

                    Street = (from d in db.Deliveries
                              where d.OrderId == id
                              select d.Street).FirstOrDefault(),

                    City = (from d in db.Deliveries
                            where d.OrderId == id
                            select d.City).FirstOrDefault(),

                    Zipcode = (from d in db.Deliveries
                               where d.OrderId == id
                               select d.Zipcode).FirstOrDefault(),

                    PhoneNumber = (from u in db.Users
                                   join o in db.Orders on u.Id equals o.CustomerUserId
                                   where o.OrderId == id
                                   select u.PhoneNumber).FirstOrDefault()
                };

                int modelId = record.ModelId;
                var specGeneral = (from spCat in db.SpecialCategories
                                   join sp in db.Specifications on spCat.SpecialCatId equals sp.SpecialCatId
                                   where spCat.Description == "General"
                                   select sp).ToList();

                var specList = new List<ModelSpecificationDetails>();
                foreach (var item in specGeneral)
                {
                    var spec = new ModelSpecificationDetails()
                    {
                        SpecificationName = item.Description,
                        SpecificationValue = (from ms in db.ModelSpecs
                                              join sp in db.Specifications on ms.SpecificationId equals sp.SpecificationId
                                              where ms.SpecificationId == item.SpecificationId
                                              select ms.Value).FirstOrDefault()
                    };
                    specList.Add(spec);
                }

                ViewBag.Specification = specList;
                return View(orderDetails);
            }
            else if (User.IsInRole("Admin"))
            {
                return RedirectToAction("Index", "Admin");
            }
            else if (User.IsInRole("Customer"))
            {
                return RedirectToAction("Index", "Customer");
            }
            return RedirectToAction("Login", "Account");
        }