Example #1
0
        public IActionResult Create(WebShout WebShout)
        {
            // gets the id of current logged in user from session
            var userId = LoggedInUserId();

            WebShout.ApplicationUserId = (int)userId;
            dbContent.Add(WebShout);
            dbContent.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
        public void SaveProduct(Product product)
        {
            Product prod = dbContent.Product.Find(product.Id);

            if (prod != null)
            {
                prod.Name        = product.Name;
                prod.isAvailable = product.isAvailable;
                prod.Price       = product.Price;
                prod.Category    = product.Category ?? prod.Category;
                prod.categoryId  = product.categoryId;
            }

            dbContent.SaveChanges();
        }
Example #3
0
 public void AddToCart(Bike bike)
 {
     appDBContent.ShopCartItem.Add(new ShopCartItem
     {
         ShopCartId = ShopCartId,
         bike       = bike,
         price      = bike.price
     });
     appDBContent.SaveChanges();
 }
        public void createOrder(Order order)
        {
            order.orderTime = DateTime.Now;
            applicationDbContent.Order.Add(order);
            var items = shopCart.listShopItems;

            foreach (var el in items)
            {
                var orderDetail = new OrderDetail()
                {
                    BikeID  = el.bike.id,
                    orderID = order.id,
                    price   = el.bike.price
                };
                applicationDbContent.OrderDetail.Add(orderDetail);
            }

            applicationDbContent.SaveChanges();
        }
Example #5
0
        public IActionResult FollowStranger(int followingUserId)
        {
            // get current login user id from session
            var id = LoggedInUserId();

            // creates follow entity
            var follow = new FollowUser()
            {
                FollowerApplicationUserId  = (int)id,
                FollowingApplicationUserId = followingUserId
            };

            // save the entity in db
            dbContent.FollowUsers.Add(follow);
            dbContent.SaveChanges();

            // redirects to home page
            return(RedirectToAction("AllShouts", "Home"));
        }
Example #6
0
        public void CreateOrder(Order order)
        {
            applicationDbContent.order.Add(order);
            var devices = basket.GetProductFromBasket();

            foreach (var device in devices)
            {
                var orderDetail = new OrderDetail
                {
                    ProductId = device.product.Id,
                    OrderId   = order.id,
                    Price     = device.product.Price,
                };

                applicationDbContent.orderDetail.Add(orderDetail);
            }

            applicationDbContent.SaveChanges();
        }
Example #7
0
        public IActionResult Signup(LogOnVM logOnVM)
        {
            // creates an object for user
            var applicationUser = new ApplicationUser()
            {
                UserName     = logOnVM.UserName,
                UserEmail    = logOnVM.UserEmail,
                UserPassword = logOnVM.UserPassword
            };

            // save the user object in db
            dbContent.ApplicationUsers.Add(applicationUser);
            dbContent.SaveChanges();

            // save user id in session when the record is saved in db
            HttpContext.Session.SetString("ApplicationUserId", applicationUser.UserId.ToString());

            //redirects to home page
            return(RedirectToAction("Allshouts", "Home"));
        }
Example #8
0
        public static void Initial(ApplicationDbContent content)
        {
            if (!content.Category.Any())
            {
                content.Category.AddRange(Categories.Select(x => x.Value));
            }

            if (!content.Product.Any())
            {
                content.AddRange(
                    new Product
                {
                    Name        = "iPhone XR",
                    Price       = 2100M,
                    isAvailable = true,
                    Category    = Categories["Мобильные телефоны"]
                },
                    new Product
                {
                    Name        = "iPhone XS",
                    Price       = 2010M,
                    isAvailable = true,
                    Category    = Categories["Мобильные телефоны"]
                },
                    new Product
                {
                    Name        = "iPhone X",
                    Price       = 1980M,
                    isAvailable = true,
                    Category    = Categories["Мобильные телефоны"]
                },
                    new Product
                {
                    Name        = "iPhone 7",
                    Price       = 1342M,
                    isAvailable = true,
                    Category    = Categories["Мобильные телефоны"]
                },
                    new Product
                {
                    Name        = "iPhone SE",
                    Price       = 877M,
                    isAvailable = true,
                    Category    = Categories["Мобильные телефоны"]
                },
                    new Product
                {
                    Name        = "ASUS X540SA-XX236T",
                    Price       = 668.58M,
                    isAvailable = true,
                    Category    = Categories["Ноутбуки"]
                },
                    new Product
                {
                    Name        = "LENOVO IDEAPAD 300",
                    Price       = 1238.10M,
                    isAvailable = false,
                    Category    = Categories["Ноутбуки"]
                },
                    new Product
                {
                    Name        = "HP 255 G7 7DF18EA",
                    Price       = 1024.52M,
                    isAvailable = true,
                    Category    = Categories["Ноутбуки"]
                },
                    new Product
                {
                    Name        = "Prestigio Wize 4117",
                    Price       = 903M,
                    isAvailable = true,
                    Category    = Categories["Планшеты"]
                },
                    new Product
                {
                    Name        = "Prestigio Wize 4111",
                    Price       = 880M,
                    isAvailable = true,
                    Category    = Categories["Планшеты"]
                },
                    new Product
                {
                    Name        = "Galaxy Tab",
                    Price       = 679M,
                    isAvailable = true,
                    Category    = Categories["Планшеты"]
                },
                    new Product
                {
                    Name        = "Epson EB-U05",
                    Price       = 2263.70M,
                    isAvailable = false,
                    Category    = Categories["Проекторы"]
                },
                    new Product
                {
                    Name        = "Panasonic PT-TW350",
                    Price       = 2318.62M,
                    isAvailable = false,
                    Category    = Categories["Проекторы"]
                },
                    new Product
                {
                    Name        = "Epson EB-W39",
                    Price       = 1849.92M,
                    isAvailable = true,
                    Category    = Categories["Проекторы"]
                }
                    );
            }

            content.SaveChanges();
        }