public ActionResult AddToCart(int id)
        {
            //cek apakah user sudah login
            if (Session["username"] == null)
            {
                if (User.Identity.IsAuthenticated)
                {
                    Session["username"] = User.Identity.Name;
                }
                else
                {
                    return(Redirect("~/Account/Login"));
                }
            }

            using (ShoppingCartsDAL scService = new ShoppingCartsDAL())
            {
                var newShoppingCart = new ShoppingCart
                {
                    CartID      = Session["username"].ToString(),
                    Quantity    = 1,
                    BookID      = id,
                    DateCreated = DateTime.Now
                };
                scService.AddToCart(newShoppingCart);
            }

            return(RedirectToAction("Index"));
        }
        //OrderNow = Checkout
        public ActionResult OrderNow()
        {
            //Cek Udah login blm
            if (User.Identity.IsAuthenticated)
            {
                using (ShoppingCartsDAL service = new ShoppingCartsDAL())
                {
                    //ViewBag.session = Session["username"].ToString();
                    //ViewBag.user = User.Identity.Name;
                    string username = Session["username"] != null ? Session["username"].ToString() : string.Empty;

                    TempData["Message"] = Helper.MsgBox.GetMsg("success", "Attention! ", "Please check your order below before submitting");
                    ViewBag.msg         = TempData["Message"].ToString();
                    TempData["Message"] = Helper.MsgBox.GetMsg("info", "User ", User.Identity.Name);
                    ViewBag.msg2        = TempData["Message"].ToString();

                    //update cartID
                    if (Session["username"].ToString() != User.Identity.Name)
                    {
                        service.UpdateCartID(Session["username"].ToString(), User.Identity.Name);
                        username = User.Identity.Name;
                    }

                    return(View(service.GetAllData(username).ToList()));
                }
            }
            //Blm login
            else
            {
                TempData["AlertMessage"] = "You need to Login first to Continue";
                return(RedirectToAction("Login", "Account"));
            }
        }
Beispiel #3
0
        public ActionResult AddToCart(int id)
        {
            //cek apakah user sudah login
            if (Session["username"] == null)
            {
                if (User.Identity.IsAuthenticated)
                {
                    Session["username"] = User.Identity.Name;
                }
                else
                {
                    //var tempUser = Guid.NewGuid().ToString();
                    //Session["username"] = tempUser;
                    return(RedirectToAction("LogIn", "Account", new { area = "" }));
                }
            }


            using (ShoppingCartsDAL scService = new ShoppingCartsDAL())
            {
                var newShoppingCart = new ShoppingCart
                {
                    CartID      = Session["username"].ToString(),
                    Quantity    = 1,
                    BookID      = id,
                    DateCreated = DateTime.Now
                };
                if (User.Identity.IsAuthenticated)
                {
                    scService.AddToCart(newShoppingCart);
                }
            }

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult AddToCart(int id)
        {
            //cek sudah login blm
            if (Session["username"] == null)
            {
                if (User.Identity.IsAuthenticated)
                {
                    Session["username"] = User.Identity.Name;
                }
                else
                {
                    var tempUser = Guid.NewGuid().ToString();
                    Session["username"] = tempUser;
                }
            }
            using (ShoppingCartsDAL scService = new ShoppingCartsDAL())
            {
                var newShoppingChart = new ShoppingCart
                {
                    CartID      = Session["username"].ToString(),
                    Quantity    = 1,
                    BookID      = id,
                    DateCreated = DateTime.Now
                };

                scService.AddToCart(newShoppingChart);
            }
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit(int id)
 {
     using (ShoppingCartsDAL service = new ShoppingCartsDAL())
     {
         var shopcart = service.GetDataByID(id);
         return(View(shopcart));
     }
 }
 public ActionResult Edit(int ID)
 {
     using (ShoppingCartsDAL service = new ShoppingCartsDAL())
     {
         var a = service.GetItemByID(ID);
         return(View(a));
     }
 }
Beispiel #7
0
 public ActionResult Edit(int id)
 {
     using (ShoppingCartsDAL services = new ShoppingCartsDAL())
     {
         var result = services.GetDataById(id);
         return(View(result));
     }
 }
 // GET: ShoppingCarts
 public ActionResult Index()
 {
     using (ShoppingCartsDAL scService = new ShoppingCartsDAL())
     {
         string username =
             Session["username"] != null ? Session["username"].ToString() : string.Empty;
         return(View(scService.GetAllData(username).ToList()));
     }
 }
Beispiel #9
0
        public ActionResult Edit(int id)
        {
            using (ShoppingCartsDAL service = new ShoppingCartsDAL())
            {
                var sc = service.GetItemById(id);
                var s  = service.GetDetailById(id);

                return(View(sc));
            }
        }
Beispiel #10
0
 public ActionResult Delete(int id)
 {
     using (ShoppingCartsDAL service = new ShoppingCartsDAL())
         try
         {
             service.Delete(id);
             TempData["Message"] = Helper.MsgBox.GetMsg("success", "Success! ", "Your data has been removed from your Cart");
         }
         catch (Exception ex)
         {
             TempData["Message"] = Helper.MsgBox.GetMsg("danger", "Error", ex.Message);
         }
     return(RedirectToAction("Index"));
 }
Beispiel #11
0
        // GET: ShoppingCarts
        public ActionResult Index()
        {
            //nampilin MSG BOX
            if (TempData["Message"] != null)
            {
                ViewBag.msg = TempData["Message"].ToString();
            }

            using (ShoppingCartsDAL service = new ShoppingCartsDAL())
            {
                string username = Session["username"] != null ? Session["username"].ToString() : string.Empty;
                return(View(service.GetAllData(username).ToList()));
            }
        }
Beispiel #12
0
 public ActionResult Edit(ShoppingCart cart)
 {
     using (ShoppingCartsDAL services = new ShoppingCartsDAL())
     {
         try
         {
             services.Edit(cart);
         }
         catch (Exception ex)
         {
         }
     }
     return(RedirectToAction("Index"));
 }
Beispiel #13
0
 public ActionResult Delete(int id)
 {
     using (ShoppingCartsDAL service = new ShoppingCartsDAL())
     {
         try
         {
             service.Delete(id);
         }
         catch (Exception ex)
         {
         }
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Checkout()
 {
     if (User.Identity.IsAuthenticated)
     {
         using (ShoppingCartsDAL service = new ShoppingCartsDAL())
         {
             string username = Session["username"] != null ? Session["username"].ToString() : string.Empty;
             return(View(service.GetAllData(username).ToList()));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }
 public ActionResult Edit(ShoppingCart a)
 {
     using (ShoppingCartsDAL service = new ShoppingCartsDAL())
     {
         try
         {
             service.Edit(a);
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message);
         }
         return(RedirectToAction("Index"));
     }
 }
Beispiel #16
0
 public ActionResult Edit(ShoppingCart sc)
 {
     using (ShoppingCartsDAL service = new ShoppingCartsDAL())
     {
         try
         {
             service.Edit(sc);
             TempData["Message"] = Helper.MsgBox.GetMsg("success", "Success! ", "Your data  has been updated");
         }
         catch (Exception ex)
         {
             TempData["Message"] = Helper.MsgBox.GetMsg("danger", "Error", ex.Message);
         }
         return(RedirectToAction("Index"));
     }
 }
 public ActionResult Delete(int?id)
 {
     if (id != null)
     {
         using (ShoppingCartsDAL service = new ShoppingCartsDAL())
         {
             try
             {
                 service.Delete(id.Value);
                 TempData["Pesan"] = Helper.KotakPesan.GetPesan("success",
                                                                "Sukses ", "Data berhasil dihapus");
             }
             catch (Exception ex)
             {
                 TempData["Pesan"] = Helper.KotakPesan.GetPesan("danger",
                                                                "Error! ", ex.Message);
             }
         }
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult EditPost(int?id, ShoppingCart shopcart)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     using (ShoppingCartsDAL service = new ShoppingCartsDAL())
     {
         try
         {
             service.Edit(id.Value, shopcart);
             TempData["Pesan"] = Helper.KotakPesan.GetPesan("success",
                                                            "Sukses ", "Quantity berhasil diubah");
         }
         catch (Exception ex)
         {
             TempData["Pesan"] = Helper.KotakPesan.GetPesan("danger",
                                                            "Error! ", ex.Message);
         }
     }
     return(RedirectToAction("Index"));
 }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                if (Session["username"] != null && !User.Identity.IsAuthenticated)
                {
                    using (ShoppingCartsDAL scService = new ShoppingCartsDAL())
                    {
                        scService.UpdateCartID(Session["username"].ToString(),
                                               model.Email);
                    }
                }
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }