Exemple #1
0
        public ActionResult SellingPets(User user, String id)
        {
            PetsDal         dal   = new PetsDal();
            UsersInfoDal    ufDal = new UsersInfoDal();
            ShoppingCartDal scDal = new ShoppingCartDal();
            ShoppingCart    sc    = new ShoppingCart();

            if (user.UserName == null)
            {
                TempData["PetsError"] = "Sorry, You must login to buy pets!";
                return(View("BuyPet", user));
            }

            if (id == "")
            {
                TempData["PetsError"] = "Sorry, You must enter value!";
                return(View("BuyPet", user));
            }

            if (dal.pets.Find(id) != null)
            {
                if (dal.pets.Find(id).Availability == 1)
                {
                    //Initializing the shopping cart object
                    sc.petType  = dal.pets.Find(id).petType;
                    sc.petName  = dal.pets.Find(id).petName;
                    sc.petID    = dal.pets.Find(id).petID;
                    sc.customer = user.UserName;

                    //Add the object to the shopping cart sql table
                    scDal.shoppingCart.Add(sc);
                    scDal.SaveChanges();

                    dal.pets.Find(id).Availability = 0;
                    dal.pets.Remove(dal.pets.Find(id));
                    dal.SaveChanges();
                    ufDal.usersInfo.Find(user.UserName).PurchasedPet++;
                    ufDal.SaveChanges();
                    return(View("~/Views/Home/Index.cshtml", user));
                }
                else
                {
                    TempData["PetsError"] = "Sorry, this Pets is not Availabile! Try else pets.";
                    return(View("BuyPet", user));
                }
            }
            else
            {
                TempData["PetsError"] = "The entered ID is not exist!";
                return(View("BuyPet", user));
            }
        }
Exemple #2
0
        public ActionResult GetShoppingCart(User user)
        {
            int                 listLength      = 0;
            ShoppingCartDal     scDal           = new ShoppingCartDal();
            List <ShoppingCart> objShoppingCart =
                (from x in scDal.shoppingCart
                 where x.customer == user.UserName
                 select x).ToList <ShoppingCart>();

            foreach (ShoppingCart sc in objShoppingCart)
            {
                listLength++;
            }

            if (listLength == 0)
            {
                objShoppingCart = null;
            }
            VMUser vm = new VMUser(user, objShoppingCart);

            return(View("ShowShoppingCart", vm));
        }