// GET: Products/Details/5
        public async Task <IActionResult> Details(string id, bool recommended = false)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var product = await _context.Computer.FirstOrDefaultAsync(m => m.Id == id);

            if (product == null)
            {
                return(NotFound());
            }

            //StockItem stockItem = await _apiClient.ApiStockGetAsync(product.Id);

            //ViewBag.AmountInStock = stockItem.AmountInStock;

            if (recommended)
            {
                RecommendationStats recommendationStats = _context.RecommendationStats.FirstOrDefault();
                recommendationStats.BoughtCount += 1;

                _context.RecommendationStats.Update(recommendationStats);
                _context.Entry(recommendationStats).Property("RecommendedCount").IsModified = false;
                await _context.SaveChangesAsync();
            }

            return(View(product));
        }
Пример #2
0
        public void Activate(int id)
        {
            Category category = db.Categories.Find(id);

            category.Enable          = !category.Enable;
            db.Entry(category).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #3
0
        public void Activate(int id)
        {
            Product product = db.Products.Find(id);

            product.Enable          = !product.Enable;
            db.Entry(product).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #4
0
        public void Activate(int id)
        {
            Article article = db.Articles.Find(id);

            article.Enable          = !article.Enable;
            db.Entry(article).State = EntityState.Modified;
            db.SaveChanges();
        }
        public void AddOneProductToCart(int?id, int quantity = 1)
        {
            var userId = User.Identity.GetUserId();

            if (id == null)
            {
            }
            Product product = db.Products.Find(id);

            if (product.Quantity < quantity)
            {
                quantity = product.Quantity;
            }

            OrderProduct orderProduct = db.OrderProducts.Where(y => y.ProductOrderStateID == 1).FirstOrDefault(x => x.Product.ProductID == id);

            if (orderProduct == null)
            {
                Order orderX = db.Orders.Where(y => y.OrderStateID == 1).FirstOrDefault(x => x.UserID == userId);
                if (orderX == null)
                {
                    Order order = new Order {
                        UserID = userId, OrderStateID = 1, OrderPaymentID = 1, OrderSupplyID = 1
                    };
                    db.Orders.Add(order);
                    db.SaveChanges();
                }

                Order orderY  = db.Orders.Where(y => y.OrderStateID == 1).FirstOrDefault(x => x.UserID == userId);
                int   orderId = orderY.OrderID;



                OrderProduct OP = new OrderProduct {
                    Product = product, Quantity = quantity, ProductOrderStateID = 1, OrderID = orderId, userID = userId
                };
                OP.Suma = OP.Product.Price * OP.Quantity;
                db.OrderProducts.Add(OP);
                db.SaveChanges();
            }


            else
            {
                orderProduct.Quantity       += quantity;
                orderProduct.Suma            = orderProduct.Product.Price * orderProduct.Quantity;
                db.Entry(orderProduct).State = EntityState.Modified;
                db.SaveChanges();
            }
            product.Quantity       -= quantity;
            db.Entry(product).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #6
0
 public void Update(Address entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }
Пример #7
0
 public PartialViewResult Edit([Bind(Include = "ContactID, Telephone,Address,AccountNumber,Email,WeekOpenTime,SaturdayOpenTime,SundayOpenTime,GoogleMapUrl")] Contact contact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contact).State = EntityState.Modified;
         db.SaveChanges();
         return(PartialView("~/Views/Admin/Contact.cshtml", contact));
     }
     return(PartialView());
 }
Пример #8
0
 public PartialViewResult Edit([Bind(Include = "OrderSupplyID,Name,Time,Price")] OrderSupply orderSupply)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderSupply).State = EntityState.Modified;
         db.SaveChanges();
         return(PartialView("~/Views/Admin/OrderSupplies.cshtml", db.OrderSupplies.ToList()));
     }
     return(PartialView());
 }
        public async Task <IActionResult> Index(RecommendationViewModel recommendationViewModel)
        {
            if (ModelState.IsValid)
            {
                Computer requestedComputer = recommendationViewModel.RequestedComputer;

                int    requestedCores         = recommendationViewModel.CoresNotImportant ? 0 : requestedComputer.Cores;
                double requestedCpuClockSpeed = recommendationViewModel.ClockSpeedNotImportant ? 0 : requestedComputer.ClockSpeed;
                int    requestedRAM           = recommendationViewModel.RAMNotImportant ? 0 : requestedComputer.RAM;
                int    requestedStorage       = recommendationViewModel.StorageNotImportant ? 0 : requestedComputer.Storage;
                double requestedPrice         = recommendationViewModel.PriceNotImportant ? 0 : requestedComputer.Price;

                double coresPriority      = recommendationViewModel.CoresNotImportant ? 0 : recommendationViewModel.CorePriority;
                double clockSpeedPriority = recommendationViewModel.ClockSpeedNotImportant ? 0 : recommendationViewModel.ClockSpeedPriority;
                double ramPriority        = recommendationViewModel.RAMNotImportant ? 0 : recommendationViewModel.RAMPriority;
                double storagePriority    = recommendationViewModel.StorageNotImportant ? 0 : recommendationViewModel.StoragePriority;
                double pricePriority      = recommendationViewModel.PriceNotImportant ? 0 : recommendationViewModel.PricePriority;

                IList <Computer> computers = await _context.Computer
                                             .Where(c => c.CategoryId == requestedComputer.CategoryId)
                                             .ToListAsync();

                RecommendationStats recommendationStats = _context.RecommendationStats.FirstOrDefault();
                recommendationStats.RecommendedCount += 1;

                _context.RecommendationStats.Update(recommendationStats);
                _context.Entry(recommendationStats).Property("BoughtCount").IsModified = false;
                await _context.SaveChangesAsync();

                IDictionary <double, Computer> offers = new Dictionary <double, Computer>();

                foreach (Computer computer in computers)
                {
                    double distance = Math.Sqrt(coresPriority * Math.Pow(requestedCores - computer.Cores, 2)
                                                + clockSpeedPriority * Math.Pow(requestedCpuClockSpeed - computer.ClockSpeed, 2)
                                                + ramPriority * Math.Pow(requestedRAM - computer.RAM, 2)
                                                + storagePriority * Math.Pow(requestedStorage - computer.Storage, 2)
                                                + pricePriority * Math.Pow(requestedPrice - computer.Price, 2));

                    offers.Add(distance, computer);
                }

                IOrderedEnumerable <KeyValuePair <double, Computer> > sortedOffers = offers.OrderBy(key => key.Key);

                Computer bestOffer = sortedOffers.FirstOrDefault().Value;
                bestOffer.Category = _context.Category.Where(c => c.Id == bestOffer.CategoryId).FirstOrDefault();

                recommendationViewModel.RecommendedComputer = bestOffer;
            }

            ViewData["CategoryId"] = new SelectList(await _context.Category.ToListAsync(), "Id", "Name");

            return(View(recommendationViewModel));
        }
Пример #10
0
 public ActionResult Edit([Bind(Include = "OrderProductHistoryID,OrderProductID,Price")] OrderProductHistory orderProductHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderProductHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OrderProductID = new SelectList(db.OrderProducts, "OrderProductID", "userID", orderProductHistory.OrderProductID);
     return(View(orderProductHistory));
 }
Пример #11
0
 public ActionResult Edit([Bind(Include = "UserID,UserRoleID,Email,Name,Surname,Password,Address,Telephone")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserRoleID = new SelectList(db.UserRoles, "UserRoleID", "Name", user.UserRoleID);
     return(View(user));
 }
Пример #12
0
        public PartialViewResult Edit([Bind(Include = "RegulationID,Rule")] Regulation regulation)
        {
            if (ModelState.IsValid)
            {
                db.Entry(regulation).State = EntityState.Modified;
                db.SaveChanges();
                return(PartialView("~/Views/Regulation/Edit.cshtml", db.Regulations.ToList()));
            }
            else if (regulation.Rule != "")
            {
                db.Regulations.Add(regulation);
                db.SaveChanges();
                return(PartialView("~/Views/Regulation/Edit.cshtml", db.Regulations.ToList()));
            }

            return(PartialView());
        }
Пример #13
0
        public ActionResult Index()
        {
            var today = DateTime.Now.Date;

            double dailySum    = 0;
            int    ordersSum   = 0;
            int    productsSum = 0;
            int    realised    = 0;
            var    orders      = db.Orders.Include(o => o.OrderPayment).Include(o => o.OrderState).Include(o => o.OrderSupply).Include(o => o.User).Where(x => x.OrderStateID != 1);

            if (orders.Any())
            {
                foreach (var x in orders.Where(x => DateTime.Compare(x.IncomingDate ?? DateTime.MinValue, today) > 0))
                {
                    dailySum += x.Suma;
                    ordersSum++;
                    if (x.OrderStateID == 3)
                    {
                        realised++;
                    }
                }
                Raport raport = db.Raports.Where(x => (DateTime.Compare(x.Date, today) == 0)).FirstOrDefault();

                var order = orders.Where(x => (DateTime.Compare(x.IncomingDate ?? DateTime.MinValue, today) > 0)).FirstOrDefault();
                if (order != null)
                {
                    int orderId = order.OrderID;
                    foreach (var x in db.OrderProducts.Where(x => x.OrderID == orderId))
                    {
                        productsSum += x.Quantity;
                    }


                    if (raport == null)
                    {
                        Raport raportX = new Raport {
                            Date = today, DailyRevenue = dailySum, ProductsQuantity = productsSum, OrdersQuantity = ordersSum, Realised = realised
                        };
                        db.Raports.Add(raportX);
                        db.SaveChanges();
                    }
                    else
                    {
                        raport.DailyRevenue     = dailySum;
                        raport.ProductsQuantity = productsSum;
                        raport.OrdersQuantity   = ordersSum;
                        raport.Realised         = realised;

                        db.Entry(raport).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(View(db.Raports));
                }
                else
                {
                    if (raport == null)
                    {
                        Raport raportX = new Raport {
                            Date = today, DailyRevenue = dailySum, ProductsQuantity = productsSum, OrdersQuantity = ordersSum, Realised = realised
                        };
                        db.Raports.Add(raportX);
                        db.SaveChanges();
                    }
                }
            }

            return(View(db.Raports));
        }