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 Submit()
        {
            UserInfo uf = new UserInfo()
            {
                UserName  = Request.Form["userInfo.UserName"].ToString(),
                Password  = Request.Form["userInfo.Password"].ToString(),
                FirstName = Request.Form["userInfo.FirstName"].ToString(),
                LastName  = Request.Form["userInfo.LastName"].ToString(),
                LovedPet  = Request.Form["userInfo.LovedPet"].ToString()
            };

            //
            User objUser = new User()
            {
                UserName = uf.UserName,
                Password = uf.Password
            };

            UsersInfoDal UIDal = new UsersInfoDal();
            UserDal      dal   = new UserDal();

            if (ModelState.IsValid)
            {
                if (dal.Users.Find(objUser.UserName) != null)
                {
                    TempData["Eror"] = "there is already user with this name";
                    return(View("Register", uf));
                }
                else
                {
                    dal.Users.Add(objUser);
                    dal.SaveChanges();
                    UIDal.usersInfo.Add(uf);
                    UIDal.SaveChanges();
                    return(View("~/Views/Home/Index.cshtml", objUser));
                }
            }
            else
            {
                TempData["Eror"] = "there value is not valid";
                return(View("Register", uf));
            }
        }