Esempio n. 1
0
        private void LogoutUser()
        {
            FlowerUtility.ClearCart();
            var authenticationManager = System.Web.HttpContext.Current
                                        .GetOwinContext().Authentication;

            authenticationManager.SignOut();
        }
Esempio n. 2
0
        public IEnumerable <Order> GetCurrentOrders(string searchString, string status,
                                                    string paymentType, string start, string end)
        {
            var orders = mySQLOrderService.GetList();

            if (!String.IsNullOrEmpty(searchString))
            {
                int id;
                if (Int32.TryParse(searchString, out id))
                {
                    orders = orders.Where(s => s.Id == id);
                }
                else
                {
                    orders = orders.Where(s => (!string.IsNullOrEmpty(s.ShipName) && s.ShipName.Contains(searchString)) || (!string.IsNullOrEmpty(s.CreatedBy) && s.CreatedBy.Contains(searchString)));
                }
            }

            ViewBag.CurrentFilter = searchString;

            if (!String.IsNullOrEmpty(status))
            {
                orders            = orders.Where(s => s.Status == (OrderStatus)Enum.Parse(typeof(OrderStatus), status));
                ViewBag.DDLStatus = FlowerUtility.SelectListFor((OrderStatus)Enum.Parse(typeof(OrderStatus), status));
            }
            else
            {
                ViewBag.DDLStatus = FlowerUtility.SelectListFor <OrderStatus>();
            }

            if (!String.IsNullOrEmpty(paymentType))
            {
                orders = orders.Where(s => s.PaymentTypeId == (PaymentType)Enum.Parse(typeof(PaymentType), paymentType));
                ViewBag.DDLPaymentType = FlowerUtility.SelectListFor((PaymentType)Enum.Parse(typeof(PaymentType), paymentType));
            }
            else
            {
                ViewBag.DDLPaymentType = FlowerUtility.SelectListFor <PaymentType>();
            }

            var compareDate = new DateTimeModel();

            if (!string.IsNullOrEmpty(start))
            {
                var compareStartDate = Utility.GetNullableDate(start).Value.Date + new TimeSpan(0, 0, 0);
                orders = orders.Where(s => (s.CreatedAt >= compareStartDate));
                compareDate.startDate = compareStartDate;
            }
            if (!string.IsNullOrEmpty(end))
            {
                var compareEndDate = Utility.GetNullableDate(end).Value.Date + new TimeSpan(23, 59, 59);
                orders = orders.Where(s => (s.CreatedAt <= compareEndDate));
                compareDate.endDate = compareEndDate;
            }

            ViewBag.CompareDate = compareDate;
            return(orders);
        }
Esempio n. 3
0
        public ActionResult LoginAsAdmin([Bind(Include = "UserName,Password")] AppUser appUser, string returnUrl)
        {
            if (Request.IsAuthenticated)
            {
                FlowerUtility.ClearCart();
            }

            if (string.IsNullOrEmpty(appUser.UserName))
            {
                ModelState.AddModelError("UserName", "UserName is required.");
                return(View(appUser));
            }

            if (string.IsNullOrEmpty(appUser.Password))
            {
                ModelState.AddModelError("Password", "Password is required.");
                return(View(appUser));
            }

            var user = UserManager.Find(appUser.UserName, appUser.Password);

            if (user != null && user.EmailConfirmed == true)
            {
                var authenticationManager = System.Web.HttpContext.Current
                                            .GetOwinContext().Authentication;
                var userIdentity = UserManager.CreateIdentity(
                    user, DefaultAuthenticationTypes.ApplicationCookie);
                authenticationManager.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = false
                }, userIdentity);

                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }

                return(Redirect("/Flowers/Index"));

                //var lstRoleName = UserManager.GetRoles(user.Id);
                //string roleName = null;
                //roleName = roleName ?? (lstRoleName.Contains(Constant.Admin) ? Constant.Admin : null);
                //roleName = roleName ?? (lstRoleName.Contains(Constant.Employee) ? Constant.Employee : null);

                //switch (roleName)
                //{
                //    case Constant.Admin:
                //        return Redirect("/Flowers/Index");
                //    case Constant.Employee:
                //        return Redirect("/Flowers/Index");
                //    default:
                //        return Redirect("/Home/Index");
                //}

                //if (UserManager.IsInRole(user.Id, Constant.Admin) || UserManager.IsInRole(user.Id, Constant.Employee))
                //{
                //    return Redirect("/Products/Index");
                //} else
                //{
                //    return Redirect("/Products/IndexCustomer");
                //}
            }
            else if (user != null && user.EmailConfirmed == false)
            {
                ModelState.AddModelError("UserName", "Email chưa confirm");
            }
            else
            {
                ModelState.AddModelError("UserName", "UserName hoặc Password nhập sai");
            }

            return(View(appUser));
        }