예제 #1
0
 public ActionResult Login(tblUsers userModel)
 {
     using (DemirStoreDBEntities db = new DemirStoreDBEntities())
     {
         if (new LoginCheck().IsLoginSuccess(userModel))
         {
             var user = db.tblUsers.Where(x => x.Email == userModel.Email).FirstOrDefault();
             if (user.isVerified == true)
             {
                 Session["isAdmin"] = user.isVerified;
             }
             Session["userID"]   = user.Id;
             Session["userName"] = user.Name;
             List <tblShoppingCart> sCart = db.tblShoppingCart.Where(x => x.UserId == userModel.Id && x.OrderId == null).ToList();
             if (sCart.Count() != 0)
             {
                 List <ShoppingCart> cart = new List <ShoppingCart>();
                 foreach (var item in sCart)
                 {
                     cart.Add(new ShoppingCart(db.tblProduct.Find(item.ProductId), item.Amount));
                 }
                 Session["cart"] = cart;
             }
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ViewBag.LoginErrorMessage = "Hatalı E-Mail ve ya Şifre";
             return(View("Login", userModel));
         }
     }
 }
예제 #2
0
 public ActionResult LogOut()
 {
     using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities())
     {
         int userId = (int)Session["userID"];
         List <tblShoppingCart> oldSCart = dbModel.tblShoppingCart.Where(x => x.UserId == userId && x.OrderId == null).ToList();
         foreach (var item in oldSCart)
         {
             dbModel.tblShoppingCart.Remove(item);
         }
         if (Session["cart"] != null)
         {
             foreach (ShoppingCart item in (List <ShoppingCart>)Session["cart"])
             {
                 tblShoppingCart sCart = new tblShoppingCart();
                 sCart.UserId     = (int)Session["userID"];
                 sCart.ProductId  = item.Product.Id;
                 sCart.Amount     = item.Quantity;
                 sCart.TotalPrice = (item.Product.Price * item.Quantity);
                 dbModel.tblShoppingCart.Add(sCart);
             }
         }
         dbModel.SaveChanges();
     }
     Session.Abandon();
     return(RedirectToAction("Login", "Home"));
 }
예제 #3
0
        public ActionResult Register(tblUsers userModel)
        {
            using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities())
            {
                if (dbModel.tblUsers.Any(x => x.Email == userModel.Email))
                {
                    ViewBag.DuplicateMessage = "Bu e mail daha önceden alındı.";
                    return(View("Register", userModel));
                }
                else if (dbModel.tblUsers.Any(x => x.PhoneNumber == userModel.PhoneNumber))
                {
                    ViewBag.DuplicateMessage = "Bu telefon numarası daha önceden alındı.";
                    return(View("Register", userModel));
                }
                var    crypto        = new SimpleCrypto.PBKDF2();
                string encryptedPswd = crypto.Compute(userModel.Pswd);
                userModel.Pswd        = encryptedPswd;
                userModel.ConfirmPswd = encryptedPswd;
                userModel.PswdSalt    = crypto.Salt;
                userModel.isVerified  = false;

                dbModel.tblUsers.Add(userModel);
                dbModel.SaveChanges();
                return(View("Login"));
            }
        }
예제 #4
0
 public ActionResult ShowCategories()
 {
     using (DemirStoreDBEntities db = new DemirStoreDBEntities())
     {
         List <tblCategory> categories = db.tblCategory.OrderByDescending(x => x.Id).Take(3).ToList();
         return(PartialView(db.tblCategory.ToList()));
     }
 }
예제 #5
0
 public ActionResult Address()
 {
     using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities())
     {
         int userId = (int)Session["userID"];
         List <tblAddress> address = dbModel.tblAddress.Where(x => x.UserId == userId).ToList();
         return(View(address));
     }
 }
예제 #6
0
        public ActionResult EditAccount(int id)
        {
            using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities())
            {
                tblUsers userModel = dbModel.tblUsers.FirstOrDefault(x => x.Id == id);

                return(View(userModel));
            }
        }
예제 #7
0
 public ActionResult ProductDetails(int?id)
 {
     using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities())
     {
         tblProduct productModel = dbModel.tblProduct.FirstOrDefault(x => x.Id == id);
         ViewBag.categoryName = dbModel.tblCategory.FirstOrDefault(x => x.Id == productModel.CategoryId).Name;
         return(View(productModel));
     }
 }
예제 #8
0
 public ActionResult AddAddress(tblAddress addressModel)
 {
     using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities())
     {
         addressModel.UserId = (int)Session["userID"];
         dbModel.tblAddress.Add(addressModel);
         dbModel.SaveChanges();
         return(RedirectToAction("Address"));
     }
 }
예제 #9
0
 public ActionResult ShowProducts()
 {
     using (DemirStoreDBEntities db = new DemirStoreDBEntities())
     {
         var products = (from p in db.tblProduct join c in db.tblCategory on p.CategoryId equals c.Id select new ShowProducts {
             ProductId = p.Id,
             ProductName = p.Name,
             ProductPicture = p.PictureLink,
             ProductDescription = p.Description,
             ProductPrice = p.Price,
             ProductStock = p.Stock,
             ProductCategoryId = c.Id,
             ProductCategoryName = c.Name,
         }).OrderByDescending(x => x.ProductId).Take(10).ToList();
         return(PartialView(products));
     }
 }
예제 #10
0
        public ActionResult Store(int?id, int page = 1)
        {
            using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities())
            {
                ViewBag.categories = dbModel.tblCategory.ToList();
                PagedList.IPagedList <tblProduct> productModel;
                if (id != null)
                {
                    productModel = dbModel.tblProduct.Where(x => x.CategoryId == id).OrderByDescending(x => x.Id).ToPagedList <tblProduct>(page, 9);
                }
                else
                {
                    productModel = dbModel.tblProduct.OrderByDescending(x => x.Id).ToPagedList <tblProduct>(page, 9);
                }

                return(View(productModel));
            }
        }
예제 #11
0
        public ActionResult AddToCart(int id, FormCollection fc)
        {
            int quantity;

            if (fc.GetValue("quantity") != null)
            {
                quantity = Int32.Parse(fc["quantity"]);
            }
            else
            {
                quantity = 1;
            }
            using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities())
            {
                if (Session["cart"] == null)
                {
                    List <ShoppingCart> cart    = new List <ShoppingCart>();
                    tblProduct          product = dbModel.tblProduct.Find(id);
                    if (product.Stock > 0 && quantity < product.Stock)
                    {
                        cart.Add(new ShoppingCart(dbModel.tblProduct.Find(id), quantity));
                        Session["cart"] = cart;
                    }
                }
                else
                {
                    List <ShoppingCart> cart = (List <ShoppingCart>)Session["cart"];
                    int index = isExisting(id);
                    if (index == -1)
                    {
                        cart.Add(new ShoppingCart(dbModel.tblProduct.Find(id), quantity));
                    }
                    else
                    {
                        cart[index].Quantity = cart[index].Quantity + quantity;
                    }
                    Session["cart"] = cart;
                }
                return(View("Cart"));
            }
        }
예제 #12
0
 public LoginCheck()
 {
     dbModel = new DemirStoreDBEntities();
 }