public IActionResult AddCartDetail([FromBody] DTO.AccessoryJSON acc)
        {
            string msg;
            Dictionary <string, DTO.Accessory> shoppingCart = HttpContext.Session.GetCollectionFromJson <Dictionary <string, DTO.Accessory> >("cart");

            if (shoppingCart == null)
            {
                shoppingCart = new Dictionary <string, DTO.Accessory>();
            }
            AccessoryDAO dao = new AccessoryDAO(_context);

            DTO.Accessory dto = dao.FindByPrimaryKey(acc.AccId);
            dto.Quantity = int.Parse(acc.Quantity);
            if (DTO.ShoppingCart.AddCart(dto, shoppingCart))
            {
                msg = "Added to cart";
            }
            else
            {
                msg = "Available quantity is not enough to buy.";
            }
            var obj = new
            {
                msg   = msg,
                count = shoppingCart.Count
            };

            HttpContext.Session.SetCollectionAsJson("cart", shoppingCart);
            return(new JsonResult(obj));
        }
        public IActionResult GetRelatedAccessories([FromBody] DTO.Accessory acc)
        {
            AccessoryDAO         dao  = new AccessoryDAO(_context);
            List <DTO.Accessory> list = dao.FindRelatedAccessories(acc.AccCatId, acc.AccId);

            return(new JsonResult(list));
        }
        public IActionResult AddCart([FromBody] string accID)
        {
            string msg;
            Dictionary <string, DTO.Accessory> cart = HttpContext.Session.GetCollectionFromJson <Dictionary <string, DTO.Accessory> >("cart") ?? new Dictionary <string, DTO.Accessory>();
            AccessoryDAO dao = new AccessoryDAO(_context);

            DTO.Accessory dto = dao.FindByPrimaryKey(accID);
            dto.Quantity = 1;
            if (DTO.ShoppingCart.AddCart(dto, cart))
            {
                msg = "Added to cart";
            }
            else
            {
                msg = "Available quantity is not enough to buy";
            }
            var obj = new
            {
                msg   = msg,
                count = cart.Count
            };

            HttpContext.Session.SetCollectionAsJson("cart", cart);
            return(new JsonResult(obj));
        }
        public IActionResult CheckAccIDExisted([FromBody] string id)
        {
            AccessoryDAO dao       = new AccessoryDAO(_context);
            bool         isExisted = dao.CheckExisted(id);

            return(new JsonResult(isExisted));
        }
        public IActionResult FindByAccCatID(string accCatIDSearch, int?pageNumber)
        {
            AccessoryDAO         dao  = new AccessoryDAO(_context);
            List <DTO.Accessory> list = dao.FindAllAccByAccCatID(accCatIDSearch, pageNumber);

            return(View("Index", list));
        }
        public IActionResult FindLatestAccessories()
        {
            AccessoryDAO         dao  = new AccessoryDAO(_context);
            List <DTO.Accessory> list = dao.FindLatestAccessories();

            return(new JsonResult(list));
        }
        public IActionResult FindAccById(string accIdSearch)
        {
            AccessoryDAO dao = new AccessoryDAO(_context);

            DTO.Accessory dto = dao.FindByPrimaryKey(accIdSearch);
            if (dto != null)
            {
                FavoriteDAO          fDAO     = new FavoriteDAO(_context);
                int                  countFav = fDAO.CountFavoriteByAccId(accIdSearch);
                AccessoryCategoryDAO acDAO    = new AccessoryCategoryDAO(_context);
                string               accCat   = acDAO.FindByPrimaryKey(dto.AccCatId);
                if (accCat.Equals(""))
                {
                    ViewData["msg"] = "Load category of accessory failed";
                    return(View("Error Page"));
                }
                ViewData["countFav"]    = countFav;
                ViewData["accCatName"]  = accCat;
                ViewData["accIdSearch"] = accIdSearch;
                return(View(dto));
            }
            else
            {
                ViewData["msg"] = "Accessory load failed";
                return(View("Error Page"));
            }
        }
Ejemplo n.º 8
0
        public IActionResult RestoreStorage([FromBody] string accTranID)
        {
            AccessoryDAO      accDAO = new AccessoryDAO(_context);
            TransactionRelDAO trDAO  = new TransactionRelDAO(_context);
            List <AccessoryTransactionRel> tranList = trDAO.FindByAccTranID(accTranID);
            List <DTO.Accessory>           accList  = new List <DTO.Accessory>();

            foreach (AccessoryTransactionRel tranRel in tranList)
            {
                DTO.Accessory accDTO = accDAO.FindByPrimaryKey(tranRel.AccId);
                accDTO.Quantity += tranRel.Quantity + accDTO.AvailableQuantity;
                accList.Add(accDTO);
            }
            string msg;

            if (accDAO.Restore(accList))
            {
                msg = "Restore all canceled accessories success";
            }
            else
            {
                msg = "Restore all canceled accessories failed";
            }
            return(new JsonResult(msg));
        }
        public IActionResult Index()
        {
            PrincipalDAO dao      = new PrincipalDAO(_context);
            string       username = HttpContext.Session.GetString("USER");
            Principal    dto      = dao.FindByUsername(username);

            if (dto != null)
            {
                ViewData["deliveryAddress"] = dto.Address;
                ViewData["deliveryPhone"]   = dto.Phone;
            }
            else
            {
                ViewData["msg"] = "Load checkout failed";
                return(View("Error Page"));
            }
            Dictionary <string, DTO.Accessory> shoppingCart = HttpContext.Session.GetCollectionFromJson <Dictionary <string, DTO.Accessory> >("cart");
            Dictionary <string, DTO.Accessory> cart         = new Dictionary <string, DTO.Accessory>();

            foreach (var item in shoppingCart)
            {
                string        id         = item.Key;
                DTO.Accessory dtoSession = item.Value;
                AccessoryDAO  accDAO     = new AccessoryDAO(_context);
                DTO.Accessory accDTO     = accDAO.FindByPrimaryKey(id);
                accDTO.Quantity = dtoSession.Quantity;
                cart.Add(id, accDTO);
            }
            return(View(cart));
        }
 public async Task <IActionResult> GetAllAccessory()
 {
     using (var accessoryDAO = new AccessoryDAO())
     {
         return(Json((await accessoryDAO.ReadAll(false))
                     .ToArray()));
     }
 }
 public async Task <IActionResult> GetaccessorySearchResult(string keyword)
 {
     using (var accessoryDAO = new AccessoryDAO()){
         return(Json((accessoryDAO.Context.Accessory
                      .Include(x => x.Product)
                      .Where(x => x.Product.Name.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) != -1))
                     .ToArray()));
     }
 }
        public IActionResult LoadCart()
        {
            Dictionary <string, DTO.Accessory> shoppingCart = HttpContext.Session.GetCollectionFromJson <Dictionary <string, DTO.Accessory> >("cart");
            Dictionary <string, DTO.Accessory> cart         = new Dictionary <string, DTO.Accessory>();

            foreach (var item in shoppingCart)
            {
                string        id         = item.Key;
                DTO.Accessory dtoSession = item.Value;
                AccessoryDAO  dao        = new AccessoryDAO(_context);
                DTO.Accessory accDTO     = dao.FindByPrimaryKey(id);
                accDTO.Quantity = dtoSession.Quantity;
                cart.Add(id, accDTO);
            }
            return(new JsonResult(cart));
        }
        public IActionResult FindAccByLikeName([FromBody] DTO.AccSearchObj accSearch)
        {
            AccessoryDAO         dao = new AccessoryDAO(_context);
            List <DTO.Accessory> list;

            if (accSearch.IsDeleteSearch.Equals("All"))
            {
                list = dao.FindAllAccByLikeName(accSearch.AccNameSearch);
            }
            else if (accSearch.IsDeleteSearch.Equals("True"))
            {
                list = dao.FindAccByLikeName(accSearch.AccNameSearch, true);
            }
            else
            {
                list = dao.FindAccByLikeName(accSearch.AccNameSearch, false);
            }
            return(new JsonResult(list));
        }
        public IActionResult UpdateAcc([FromBody] DTO.AccessoryJSON acc)
        {
            AccessoryDAO dao = new AccessoryDAO(_context);
            Accessory    dto = new Accessory
            {
                AccId             = acc.AccId,
                AccName           = acc.AccName,
                AccCatId          = acc.AccCatId,
                Brand             = acc.Brand,
                Description       = acc.Description,
                Price             = Double.Parse(acc.Price),
                StartSellingDate  = DateTime.Parse(acc.StartSellingDate),
                Image             = acc.Image,
                AvailableQuantity = int.Parse(acc.AvailableQuantity),
                SalePercent       = double.Parse(acc.SalePercent),
                IsDelete          = acc.IsDelete.Equals("true") ? true : false
            };
            bool result = dao.Update(dto);

            return(new JsonResult(result));
        }
Ejemplo n.º 15
0
 public AccessoryDaoDemo()
 {
     accessoryDAO = new AccessoryDAO();
 }
        public IActionResult CheckOut([Bind("DeliveryAddress", "DeliveryPhone")] DTO.Transaction tran)
        {
            string generateAccTranID()
            {
                string         id;
                Random         rd  = new Random();
                TransactionDAO dao = new TransactionDAO(_context);

                do
                {
                    id = "AT";
                    for (int i = 0; i < 4; i++)
                    {
                        id += rd.Next(10);
                    }
                } while (dao.CheckExisted(id));
                return(id);
            }

            AccessoryDAO accDAO   = new AccessoryDAO(_context);
            string       userName = HttpContext.Session.GetString("USER");
            Dictionary <string, DTO.Accessory> shoppingCart = HttpContext.Session.GetCollectionFromJson <Dictionary <string, DTO.Accessory> >("cart");

            foreach (var item in shoppingCart)
            {
                string        id         = item.Key;
                DTO.Accessory dtoSession = item.Value;
                DTO.Accessory accDTO     = accDAO.FindByPrimaryKey(id);
                if (accDTO.IsDelete || accDTO.AvailableQuantity == 0 || accDTO.AvailableQuantity < dtoSession.Quantity)
                {
                    return(RedirectToAction("Index", "ShoppingCart"));
                }
            }
            TransactionDAO tranDAO   = new TransactionDAO(_context);
            string         accTranID = generateAccTranID();

            DTO.Transaction tranDTO = new DTO.Transaction(accTranID, userName, tran.DeliveryPhone, tran.DeliveryAddress, 0);
            tranDAO.Insert(tranDTO);
            double total = 0;
            List <DTO.Accessory> list = new List <DTO.Accessory>();

            foreach (var item in shoppingCart)
            {
                string             id         = item.Key;
                DTO.Accessory      dtoSession = item.Value;
                DTO.Accessory      accDTO     = accDAO.FindByPrimaryKey(id);
                DTO.TransactionRel tranRelDTO = new DTO.TransactionRel(id, accTranID, accDTO.AccName, accDTO.AccCatId, accDTO.Brand, accDTO.Description, accDTO.Image, accDTO.Price, accDTO.SalePercent, accDTO.StartSellingDate, dtoSession.Quantity, accDTO.AccCatName);
                TransactionRelDAO  tranRelDAO = new TransactionRelDAO(_context);
                tranRelDAO.Insert(tranRelDTO);
                accDTO.AvailableQuantity -= dtoSession.Quantity;
                total += dtoSession.Quantity * accDTO.Price * (1 - accDTO.SalePercent);
                list.Add(accDTO);
            }
            accDAO.Update(list);
            total = (double)Math.Round(total * 100) / 100;
            tranDTO.TotalPrice = total;
            tranDAO.UpdateTotalPrice(total, accTranID);
            shoppingCart.Clear();
            HttpContext.Session.SetCollectionAsJson("cart", shoppingCart);
            return(RedirectToAction("UserDetails", "Principal"));
        }
        public IActionResult Index(int?pageNumber)
        {
            AccessoryDAO dao = new AccessoryDAO(_context);

            return(View(dao.FindAllAcc(pageNumber)));
        }
        public IActionResult FindByLikeName(string accSearch, int?pageNumber)
        {
            AccessoryDAO dao = new AccessoryDAO(_context);

            return(View("Index", dao.FindAccByLikeName(accSearch, false, pageNumber)));
        }