Example #1
0
        public ActionResult Index()
        {
            #region Cart and wishlist actions
            if (User.Identity.IsAuthenticated)
            {
                #region Check iDentity
                if (HttpContext.User.IsInRole("admin"))
                {
                   return  RedirectToAction("Index", "Admin");
                }
                else if (HttpContext.User.IsInRole("supplier"))
                {
                  return  RedirectToAction("Home", "Supplier");
                }
                else if (HttpContext.User.IsInRole("employee"))
                {
                  return  RedirectToAction("Index", "Employee");
                }
                #endregion

                #region Getting cart total
                CartActions act = new CartActions();
                WishlistActions wish = new WishlistActions();
                ApplicationDbContext mycontext = new ApplicationDbContext();
                UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(mycontext);
                ApplicationUserManager mgr = new ApplicationUserManager(myStore);
                var thisUser = mgr.FindByNameAsync(User.Identity.Name);
                int cartId = Convert.ToInt32(thisUser.Result.Carts.CartID);
                //
                try
                {
                    double nm = GetCartTotal(cartId); string[] xn = nm.ToString().Split('.'); Session["cartTotal"] = xn[0] + "," + xn[1];
                }
                catch
                { Session["cartTotal"] = (double)GetCartTotal(cartId); }
                Session["wishlistTotal"] = wish.GetWishlistTotal(thisUser.Result.Wishlists.WishlistID);
                #endregion
            }
            else
            { Session["cartTotal"] = "0,00"; Session["wishlistTotal"] = 0; }
            #endregion

            #region Prep utilities
            BusinessLogicHandler myHandler = new BusinessLogicHandler();
            SearchViewModel model = new SearchViewModel();
            #endregion

            #region Get New Books
            model.BookResults = myHandler.GetNewBooks();
            #endregion

            #region Get Devices
            model.GadgetResults = myHandler.GetNewDevices();
            #endregion

            return View(model);
        }
Example #2
0
        public async Task<ActionResult> Edit()
        {
            if (User.Identity.IsAuthenticated)
            {
                ApplicationDbContext mycontext = new ApplicationDbContext();
                UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(mycontext);
                ApplicationUserManager mgr = new ApplicationUserManager(myStore);
                var user = await mgr.FindByNameAsync(User.Identity.Name);

                WishlistActions grantMyWish = new WishlistActions();
                CartActions cart = new CartActions();
                ProductViewModel bridge = new ProductViewModel();
                List<Book> bookList = new List<Book>();
                List<Technology> deviceList = new List<Technology>();
                myHandler = new BusinessLogicHandler();
                bridge.allWishlistItems = new List<WishlistItem>();
                bridge.allWishlistItems =  grantMyWish.GetWishlistItems(user.Wishlists.WishlistID);
                if(bridge.allWishlistItems != null)
                {
                    bridge.allBook = new List<Book>();
                    foreach(var item in bridge.allWishlistItems)
                    {
                        if(myHandler.CheckProductType(item.ProductID))
                        {
                             Book myBook = new Book();
                             myBook = myHandler.GetBook(item.ProductID);
                             bookList.Add(myBook);
                        }
                        else
                        {
                            Technology myDevice = new Technology();
                            myDevice = myHandler.GetTechnologyDetails(item.ProductID);
                            deviceList.Add(myDevice);
                        }
                    }
                    //bridge.allBook = myHandler.GetBooks();
                    bridge.allTechnology = new List<Technology>();
                    //bridge.allTechnology = myHandler.GetTechnology();
                    bridge.allBook = bookList;
                    bridge.allTechnology = deviceList;
                }

                Session["wishlistTotal"] =  grantMyWish.GetWishlistTotal(user.Wishlists.WishlistID);
                Session["cartTotal"] = cart.GetTotalAsync(user.Carts.CartID);
                return View(bridge);
            }
            else
                return RedirectToAction("Login", "Account", null);
        }
Example #3
0
        public async Task<ActionResult> Add(int productId, string returnUrl)
        {
            WishlistActions act = new WishlistActions();
            if (User.Identity.IsAuthenticated)
            {
                ApplicationDbContext mycontext = new ApplicationDbContext();
                UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(mycontext);
                ApplicationUserManager mgr = new ApplicationUserManager(myStore);
                var thisUser = await mgr.FindByNameAsync(User.Identity.Name);

                WishlistItem wish = new WishlistItem();
                CartActions cart = new CartActions();
                wish.ProductID = productId;

                myHandler = new BusinessLogicHandler();
                IEnumerable<CartItem> inItems = myHandler.GetCartItems(thisUser.Carts.CartID);
                if (inItems != null)
                {
                    CartItem items = inItems.SingleOrDefault(item => item.ProductID == productId);
                    if (items != null)
                    {
                        if (items.ProductID == productId)
                        { myHandler = new BusinessLogicHandler(); myHandler.DeleteCartItem(items.CartItemID); }
                    }

                }
                wish.WishlistID = (int)thisUser.Wishlists.WishlistID;
                wish.DateAdded = DateTime.Now;
                myHandler.AddWishlistItem(wish);

                Session["wishlistTotal"] =  act.GetWishlistTotal(thisUser.Wishlists.WishlistID);
                Session["cartTotal"] =(double) cart.GetTotalAsync(thisUser.Carts.CartID);

                return Redirect(returnUrl);
            }
            else
            { return RedirectToAction("Account", "Login", null); }
        }
Example #4
0
 public async Task<ActionResult> _AddToCart(int ProductID, int wishID, string returnUrl)
 {
     string userName = User.Identity.GetUserName();
     ApplicationDbContext dataSocket = new ApplicationDbContext();
     UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(dataSocket);
     userMgr = new ApplicationUserManager(myStore);
     var user = await userMgr.FindByEmailAsync(userName);
     //int customer = (int)user.Customers.CustomerID;
     CartActions myActions = new CartActions();
     WishlistActions wishes = new WishlistActions();
     Cart cart = new Cart();
     cart.CartID = user.Carts.CartID;
     if (myActions.AddToCartAsync(cart.CartID, ProductID))
     {
         myHandler = new BusinessLogicHandler();
         myHandler.DeleteWishlistItem(wishID);
         Session["cartTotal"] = await GetCartTotal(cart.CartID);
         Session["wishlistTotal"] = wishes.GetWishlistTotal(user.Wishlists.WishlistID);
     }
     else
     { }
     //return Json(new { success = true }, JsonRequestBehavior.AllowGet);
     return Redirect(returnUrl); //RedirectToAction(returnUrl);
 }
Example #5
0
        public async Task<ActionResult> Checkout()
        {

            #region Data to Display
            CartActions act = new CartActions(); WishlistActions wishAct = new WishlistActions();
            ApplicationDbContext dataSocket = new ApplicationDbContext();
            UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(dataSocket);
            userMgr = new ApplicationUserManager(myStore);
            var thisUser = await userMgr.FindByNameAsync(User.Identity.Name);
            int Id = (int)thisUser.Carts.CartID;


            try
            { double nm = await GetCartTotal(Id); string[] xn = nm.ToString().Split('.'); Session["cartTotal"] = xn[0] + "," + xn[1]; }
            catch { Session["cartTotal"] = act.GetTotalAsync(Id); }


            Session["wishlistTotal"] = wishAct.GetWishlistTotal(thisUser.Wishlists.WishlistID);
            //List<CartItem> myItems = new List<CartItem>(); 
            ProductViewModel myNewModel = new ProductViewModel();
            IEnumerable<CartItem> myItems = act.GetCartItemsAsync(Id);
            if (myItems != null)
            {
                myHandler = new BusinessLogicHandler();
                List<Book> ifBooks = new List<Book>();
                List<Technology> ifGadget = new List<Technology>();

                foreach (var item in myItems)
                {
                    if (myHandler.CheckProductType(item.ProductID))
                    {
                        Book book = new Book();
                        book = myHandler.GetBook(item.ProductID);
                        ifBooks.Add(book);
                    }
                    else
                    {
                        Technology device = new Technology();
                        device = myHandler.GetTechnologyDetails(item.ProductID);
                        ifGadget.Add(device);
                    }
                }

                myNewModel.allBook = ifBooks;
                myNewModel.allCartItem = myItems.ToList();
                myNewModel.allTechnology = ifGadget;
                List<ProductViewModel.CartHelper> itemList = new List<ProductViewModel.CartHelper>();
                ProductViewModel.CartHelper cartHelp;
                if (myItems != null)
                {
                    var revised = from rev in ifBooks
                                  join item in myItems on rev.ProductID equals item.ProductID
                                  where rev.ProductID == item.ProductID
                                  select new { rev.ProductID, rev.SellingPrice, item.Quantity };
                    foreach (var ite in revised)
                    {
                        cartHelp = new ProductViewModel.CartHelper();
                        cartHelp.ProductID = ite.ProductID;
                        cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity);
                        itemList.Add(cartHelp);
                    }
                }
                if (myItems != null)
                {
                    if (ifGadget != null)
                    {
                        var revised = from rev in ifGadget
                                      join item in myItems on rev.ProductID equals item.ProductID
                                      where rev.ProductID == item.ProductID
                                      select new { rev.ProductID, rev.SellingPrice, item.Quantity };
                        foreach (var ite in revised)
                        {
                            cartHelp = new ProductViewModel.CartHelper();
                            cartHelp.ProductID = ite.ProductID;
                            cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity);
                            itemList.Add(cartHelp);
                        }
                    }
                }
                double cartTotal = Convert.ToDouble(Session["cartTotal"].ToString());
                cartTotal = cartTotal / 100;
                List<Company> company = myHandler.GetCompanyDetails();
                double vat = 0;
                foreach (var item in company)
                { vat = item.VATPercentage; }
                vat = vat + 1;
                double subTotal = cartTotal / vat;
                double vatAmount = cartTotal - subTotal;
                ProductViewModel.CartConclude finishing = new ProductViewModel.CartConclude();
                finishing.CartTotal = cartTotal;
                finishing.VatAddedTotal = vatAmount;
                finishing.SubTotal = subTotal;
                myNewModel.ItsA_wrap = new List<ProductViewModel.CartConclude>();
                myNewModel.ItsA_wrap.Add(finishing);

                myNewModel.secureCart = itemList;
            }
            else
            { return RedirectToAction("Edit"); }

            #endregion

            #region Drop down data
            DeliveryHandler deliver = new DeliveryHandler();
            IEnumerable<Delivery> delivery = (IEnumerable<Delivery>)deliver.GetDeliveryList();
            var dataStore = from name in delivery
                            select new { Value = name.DeliveryServiceID, Text = name.ServiceName };
            ViewBag.DeliveryList = new SelectList(dataStore.ToList());

            List<SelectListItem> deliveryI = new List<SelectListItem>();
            deliveryI.Add(new SelectListItem { Text = "Delivery Service", Value = "", Selected = true });
            foreach (var item in delivery)
            { deliveryI.Add(new SelectListItem { Text = item.ServiceName, Value = item.DeliveryServiceID.ToString() }); }
            myNewModel.I_DeliveryList = new List<SelectListItem>();
            myNewModel.I_DeliveryList = deliveryI;
            ViewData["I_Delivery"] = deliveryI;
            #endregion

            #region Default Address
            if (thisUser.Address != null)
            { myNewModel.deliveryHelper = new DeliveryHelper(); myNewModel.deliveryHelper.DeliveryAddress = thisUser.Address; }
            #endregion

            return View(myNewModel);
        }
Example #6
0
        public async Task<ActionResult> Edit()
        {
            CartActions act = new CartActions(); WishlistActions wishAct = new WishlistActions();
            ApplicationDbContext dataSocket = new ApplicationDbContext();
            UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(dataSocket);
            userMgr = new ApplicationUserManager(myStore);
            var thisUser = await userMgr.FindByNameAsync(User.Identity.Name);
            int Id = (int)thisUser.Carts.CartID;
            try
            { double nm = await GetCartTotal(Id); string[] xn = nm.ToString().Split('.'); Session["cartTotal"] = xn[0] + "," + xn[1]; }
            catch { Session["cartTotal"] = act.GetTotalAsync(Id); }
            
            Session["wishlistTotal"] = wishAct.GetWishlistTotal(thisUser.Wishlists.WishlistID);
            List<CartItem> myItems = new List<CartItem>();
            try
            { myItems =  act.GetCartItemsAsync(Id).ToList();}
            catch(ArgumentNullException)
            { myItems = null; }
            
            myHandler = new BusinessLogicHandler();
            List<Book> ifBooks = new List<Book>();
            ProductViewModel myNewModel = new ProductViewModel();
            List<Technology> ifGadget = new List<Technology>();
            if (myItems != null)
            {
                foreach (var item in myItems)
                {
                    if (myHandler.CheckProductType(item.ProductID))
                    {
                        Book book = new Book();
                        book = myHandler.GetBook(item.ProductID);
                        ifBooks.Add(book);
                    }
                    else
                    {
                        Technology device = new Technology();
                        device = myHandler.GetTechnologyDetails(item.ProductID);
                        ifGadget.Add(device);
                    }
                }

                
                myNewModel.allCartItem = new List<CartItem>();
                myNewModel.allBook = new List<Book>();
                myNewModel.allTechnology = new List<Technology>();
                List<ProductViewModel.CartHelper> itemList = new List<ProductViewModel.CartHelper>();
                ProductViewModel.CartHelper cartHelp;
                if (myItems != null)
                {
                    if (ifBooks != null)
                    {
                        var revised = from rev in ifBooks
                                      join item in myItems on rev.ProductID equals item.ProductID
                                      where rev.ProductID == item.ProductID
                                      select new { rev.ProductID, rev.SellingPrice, item.Quantity };
                        foreach (var ite in revised)
                        {
                            cartHelp = new ProductViewModel.CartHelper();
                            cartHelp.ProductID = ite.ProductID;
                            cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity);
                            itemList.Add(cartHelp);
                        }
                    }
                }
                if (myItems != null)
                {
                    if (ifGadget != null)
                    {
                        var revised = from rev in ifGadget
                                      join item in myItems on rev.ProductID equals item.ProductID
                                      where rev.ProductID == item.ProductID
                                      select new { rev.ProductID, rev.SellingPrice, item.Quantity };
                        foreach (var ite in revised)
                        {
                            cartHelp = new ProductViewModel.CartHelper();
                            cartHelp.ProductID = ite.ProductID;
                            cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity);
                            itemList.Add(cartHelp);
                        }
                    }
                }
                double cartTotal = Convert.ToDouble(Session["cartTotal"].ToString());
                cartTotal = cartTotal / 100;
                List<Company> company = myHandler.GetCompanyDetails();
                double vat = 0;
                foreach (var item in company)
                { vat = item.VATPercentage; }
                vat = vat + 1;
                double subTotal = cartTotal / vat;
                double vatAmount = cartTotal - subTotal;
                ProductViewModel.CartConclude finishing = new ProductViewModel.CartConclude();
                finishing.CartTotal = cartTotal;
                finishing.VatAddedTotal = vatAmount;
                finishing.SubTotal = subTotal;
                myNewModel.allBook = ifBooks;
                myNewModel.allCartItem = myItems;
                myNewModel.allTechnology = ifGadget;
                myNewModel.ItsA_wrap = new List<ProductViewModel.CartConclude>();
                myNewModel.ItsA_wrap.Add(finishing);

                myNewModel.secureCart = itemList;
                return View(myNewModel);
            }
            else
            {
                myNewModel.ItsA_wrap = new List<ProductViewModel.CartConclude>();
                return View(myNewModel);
            }

        }