Exemplo n.º 1
0
        public ActionResult EditOutfit(int id)
        {
            var departments = new SelectList(departmentRepository.GetDepartments().Select(d => d.DepartmentName));

            var        Outfit = OutfitRepository.Get(id);
            OutfitEdit model  = new OutfitEdit
            {
                Id                = Outfit.Id,
                Title             = Outfit.Title,
                Price             = Outfit.Price,
                Discount          = Outfit.Discount,
                DepartmentName    = Outfit.DepartmentName,
                Description       = Outfit.Description,
                ExistingPhotoPath = Outfit.PhotoPath
            };

            foreach (var d in departments)
            {
                if (d.Value == model.DepartmentName)
                {
                    d.Selected = true;
                    break;
                }
            }

            ViewBag.Department = departments;

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UserOrders(string sort = "DSC")
        {
            order.Clear();
            var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user   = await userManager.FindByIdAsync(userId);

            int sum    = 0;
            int number = 0;

            IEnumerable <Order> orders = orderRepository.GetOrders(user.Id);

            UserOrdersVM userOrders = new UserOrdersVM
            {
                Orders = new List <OrderVM>()
            };


            foreach (Order o in orders)
            {
                OrderVM orderVm          = new OrderVM();
                var     DbOrderedOutfits = orderedOutfitRepository.GetOrderedOutfits(o.Id);

                foreach (OrderedOutfit ob in DbOrderedOutfits)
                {
                    var outfit = OutfitRepository.Get(ob.OutfitId);
                    int price  = outfit.Price * ob.Quantity;
                    if (outfit.Discount.HasValue)
                    {
                        price = price * (100 - outfit.Discount.Value) / 100;
                    }

                    CartLine ct = new CartLine
                    {
                        Price    = price,
                        Outfit   = outfit,
                        Quantity = ob.Quantity
                    };
                    orderVm.Lines.Add(ct);
                }
                sum               += o.Price;
                orderVm.Number     = ++number;
                orderVm.OrderPrice = o.Price;
                orderVm.OrderId    = o.Id;

                userOrders.Orders.Add(orderVm);
            }
            if (sort == "DSC")
            {
                userOrders.Orders.Reverse();
                TempData["Sort"] = "ASC";
            }
            else
            {
                TempData["Sort"] = "DSC";
            }

            userOrders.Price = sum;
            return(View(userOrders));
        }
        public RedirectToActionResult AddToCart(int OutfitId, string returnUrl)
        {
            Outfit Outfit = OutfitRepository.Get(OutfitId);

            if (Outfit != null)
            {
                cart.AddLine(Outfit, 1);
                SaveCart(cart);
            }
            ViewBag.Price       = cart.Sum();
            ViewBag.OutfitCount = cart.Lines.Count;
            return(RedirectToAction("CartIndex", new { returnUrl }));
        }
Exemplo n.º 4
0
        public IActionResult Details(int OutfitId)
        {
            var               Outfit    = OutfitRepository.Get(OutfitId);
            var               userId    = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            string            userName  = WindowsIdentity.GetCurrent().Name.ToString();
            List <FeedbackVM> feedModel = new List <FeedbackVM>();
            var               feeds     = feedbackRepository.GetFeedbacks(OutfitId);

            foreach (Feedback f in feeds)
            {
                FeedbackVM feedVM;

                if (f.CustomerId == userId)
                {
                    feedVM = new FeedbackVM
                    {
                        UserName  = userName,
                        OutfitId  = f.OutfitId,
                        Rating    = f.Rating,
                        Comment   = f.Comment,
                        CommentId = f.Id,
                        IsUsers   = true
                    };
                }
                else
                {
                    feedVM = new FeedbackVM
                    {
                        UserName  = userName,
                        OutfitId  = f.OutfitId,
                        Rating    = f.Rating,
                        Comment   = f.Comment,
                        CommentId = f.Id,
                        IsUsers   = false
                    };
                }
                feedModel.Add(feedVM);
            }
            double rating = feedbackRepository.OutfitRating(OutfitId);


            OutfitDetailsViewModel model = new OutfitDetailsViewModel
            {
                Feedbacks = feedModel,
                Outfit    = Outfit,
                Rating    = rating
            };

            return(View(model));
        }