Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var _repo = new ShoppingCartRepo(new ProductRepo());

            //StoreDataInitializer.ClearData(_repo.Context);
            StoreDataInitializer.InitializeData(_repo.Context);
            Console.ReadLine();
        }
        public IActionResult AddToCart(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            List <ShoppingCartVM> cartAddItem = new ShoppingCartRepo(_context, HttpContext).AddToCart(id);

            ViewData["CartData"] = cartAddItem;
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var connections = _config["ConnectionStrings:Default"];

            services.AddDbContext <AppDbContext>(options => options.UseSqlServer(connections));

            services.AddDefaultIdentity <IdentityUser>().AddEntityFrameworkStores <AppDbContext>().AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(option =>
            {
                option.Password.RequiredLength         = 8;
                option.Password.RequireDigit           = true;
                option.Password.RequireNonAlphanumeric = false;
                option.Password.RequireUppercase       = false;
                option.Password.RequireLowercase       = true;
                option.Password.RequiredUniqueChars    = 2;

                option.Lockout.AllowedForNewUsers      = true;
                option.Lockout.MaxFailedAccessAttempts = 5;
                option.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(10);

                option.User.RequireUniqueEmail = true;

                option.SignIn.RequireConfirmedEmail = false;
            });
            services.AddAuthentication().AddFacebook(option =>
            {
                option.AppId     = _config["FacebookAppId"];
                option.AppSecret = _config["FacebookAppSecret"];
            }).AddGoogle(option =>
            {
                option.ClientId     = _config["GoogleClientId"];
                option.ClientSecret = _config["GoogleClientSecret"];
            });

            services.AddControllersWithViews();
            services.AddScoped <ICandyRepo, CandyRepo>();
            services.AddScoped <ICategoryRepo, CategoryRepo>();
            //services.AddScoped<IUnitOfWork, UnitOfWork>();
            services.AddScoped <IShoppingCartItemRepo, ShoppingCartItemRepo>();
            services.AddScoped <IShoppingCartRepo, ShoppingCartRepo>(sc => ShoppingCartRepo.GetCart(sc));
            services.AddScoped <IOrderRepo, OrderRepo>();
            services.AddScoped <IOrderDetailRepo, OrderDetailRepo>();
            services.AddScoped <IOrderService, OrderService>();
            services.AddScoped <ICandyService, CandyService>();
            services.AddScoped <ICategoryService, CategoryService>();
            services.AddScoped <IShoppingCartService, ShoppingCartService>();

            services.AddHttpContextAccessor();
            services.AddSession();
            services.AddRazorPages();
            //var config = new MapperConfiguration(cfg => cfg.AddProfile(new MappingProfile()));
            //services.AddSingleton(c => config.CreateMapper());
        }
 public int GetCartCount(int userId)
 {
     if (userId <= 0)
     {
         return(0);
     }
     using (var cxt = DbContext(DbOperation.Read))
     {
         var repo = new ShoppingCartRepo(cxt);
         return(repo.GetCartCount(userId));
     }
 }
 public IEnumerable <ShoppingCartDetailDto> GetItemsByCartIds(int[] cartIdArr)
 {
     if (cartIdArr.Length == 0)
     {
         return(null);
     }
     using (var cxt = DbContext(DbOperation.Read))
     {
         var repo = new ShoppingCartRepo(cxt);
         return(repo.GetItemsByCartIds(cartIdArr));
     }
 }
 public IEnumerable <ShoppingCartDetailDto> GetDetailsByUser(int userId)
 {
     if (userId <= 0)
     {
         return(null);
     }
     using (var cxt = DbContext(DbOperation.Read))
     {
         var repo = new ShoppingCartRepo(cxt);
         return(repo.GetDetailsByUser(userId));
     }
 }
        public IActionResult Index()
        {
            var shoppingCart = new ShoppingCartRepo(_context, HttpContext).GetAll();

            if (shoppingCart == null)
            {
                shoppingCart = new List <ShoppingCartVM> {
                }
            }
            ;
            ViewData["CartData"] = shoppingCart;
            return(View());
        }
Exemplo n.º 8
0
        public ActionResult AddProduct(int productID, string productName, decimal price, int qty)
        {
            ShoppingCartRepo cartRepo = new ShoppingCartRepo();
            SessionHelper    session  = new SessionHelper();

            if (ModelState.IsValid)
            {
                session.SetProductQty(productID, qty);
                cartRepo.SaveProductVisit(session.SessionID, productID, productName, price, qty);
                return(RedirectToAction("ViewCart", new { sessionID = session.SessionID }));
            }
            else
            {
                ViewBag.qty = session.GetProductQty(productID);
                return(View(cartRepo.GetProduct(productID)));
            }
        }
Exemplo n.º 9
0
        public ActionResult Add(ProductVM productVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(productVM));
            }

            string  sessionID = System.Web.HttpContext.Current.Session.SessionID;
            Product product   = productVM.CreateProductEntity();
            int?    quantity  = productVM.quantity;


            ShoppingCartRepo cartRepo = new ShoppingCartRepo();

            cartRepo.AddCartItem(sessionID, product, quantity);
            ViewBag.Quantity = quantity;

            // Session.Timeout = 1; // necessary or does i automatically do this?
            return(RedirectToAction("ViewCart"));
        }
Exemplo n.º 10
0
        public ActionResult ViewCart(int?id)
        {
            string sessionID = System.Web.HttpContext.Current.Session.SessionID;

            if (id != null)
            {
                // remove product visit
                ProductVisitRepo productVisitRepo = new ProductVisitRepo();
                productVisitRepo.RemoveProductVisit(sessionID, (int)id);
            }

            ShoppingCartRepo cartRepo = new ShoppingCartRepo();
            // get all product visit entries
            IEnumerable <ProductVisit> productVisits = cartRepo.GetCartItems(sessionID);

            // if have product visit can create a cart item out of it via the naviagtion properties
            List <ProductVM> products = new List <ProductVM>();

            foreach (ProductVisit item in productVisits)
            {
                ProductVM product = new ProductVM(item.Product, (int)item.qtyOrdered);
                product.SetTotalCost();
                product.image = item.Product.Image.imageTitle;
                products.Add(product);
            }

            ShoppingCartVM cart = new ShoppingCartVM(products);

            if (products.Count() > 0)
            {
                return(View(cart));
            }
            else
            {
                ViewBag.Message = "No cart items selected";
                return(View(cart));
            }
        }
Exemplo n.º 11
0
        protected void Session_Start()
        {
            // Remove abandoned sessions
            SessionManagement s = new SessionManagement();

            s.RemoveExpiredSessions();

            SessionHelper session = new SessionHelper();

            if (Request.Cookies["ASP.NET_SessionId"] == null)
            {
                session.Initialize();
            }
            else
            {
                session.UpdateSession();
            }


            ShoppingCartRepo cartRepo = new ShoppingCartRepo();

            cartRepo.SaveVisit(session.SessionID, session.Start);
        }
Exemplo n.º 12
0
 public ShoppingCartRepoTests()
 {
     _repo = new ShoppingCartRepo(new ProductRepo());
     StoreDataInitializer.ClearData(_repo.Context);
     StoreDataInitializer.InitializeData(_repo.Context);
 }
Exemplo n.º 13
0
 public ShoppingCartRepoTests()
 {
     _repo         = new ShoppingCartRepo(Db, new ProductRepo(Db), new CustomerRepo(Db));
     Db.CustomerId = 1;
     LoadDatabase();
 }
Exemplo n.º 14
0
 public ShoppingCartController()
 {
     _shoppingCartRepo = new ShoppingCartRepo();
 }
Exemplo n.º 15
0
 public ShoppingCartService()
 {
     _bookRepo         = new BookRepo();
     _orderRepo        = new OrderRepo();
     _shoppingCartRepo = new ShoppingCartRepo();
 }
        public ShoppingCartRepoTests()
        {
            _repo = new ShoppingCartRepo();
            StoreDataInitializer.InitializeData(_repo.Context);

        }