Exemple #1
0
        public ActionResult Add()
        {
            if (Session["sepet"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ProductCart cart = Session["sepet"] as ProductCart;

            Order newOrder = new Order();

            AppUser currentUser = _appUserService.FindByEmail(HttpContext.User.Identity.Name);

            newOrder.AppUserID = currentUser.ID;

            foreach (var item in cart.CartProductList)
            {
                Product nextCartProduct = _productService.GetById(item.ID);
                newOrder.OrderDetails.Add(new OrderDetail
                {
                    ProductID = nextCartProduct.ID,
                    Quantity  = item.Quantity,
                    UnitPrice = item.UnitPrice
                });
            }

            _orderService.Add(newOrder);


            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Login()
        {
            if (User.Identity.IsAuthenticated)
            {
                AppUser currentUser = _appUserService.FindByEmail(HttpContext.User.Identity.Name);

                if (currentUser.Role == Role.Admin)
                {
                    return(RedirectToAction("Index", "Home", new { area = "Admin" }));
                }
                else if (currentUser.Role == Role.Member)
                {
                    return(RedirectToAction("Index", "Home", new { area = "Member" }));
                }
                else
                {
                    return(RedirectToAction("SignUp"));
                }
            }


            return(View());
        }
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            //FormsAuth cookie içerisine atılan mail adresini yakalama yöntemi.
            string email = HttpContext.Current.User.Identity.Name;

            if (!string.IsNullOrWhiteSpace(email))
            {
                AppUser currentUser = _appUserService.FindByEmail(email);
                foreach (string role in _roles)
                {
                    if (currentUser.Role.ToString().Trim().ToLower() == role.Trim().ToLower())
                    {
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                //İstersek Error Controller açar ve unauthorized sayfasını hazırlarız.
                HttpContext.Current.Response.Redirect("~/Error/Unauthorized");
                return(false);
            }
        }