Пример #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            ViewBag.IsEdit = false;
            ViewBag.BodyId = string.Empty;

            if (User.Identity.IsAuthenticated)
            {
                var currentAccount = AccountViewHelper.GetCurrentAccount();

                if (currentAccount == null || !currentAccount.Enabled)
                {
                    // If currentAccount hasn't isnt enabled we sign out the user and then redirect to login page.
                    Authentication.SignOut();
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                        { "controller", "Account" }, { "action", "Login" }
                    });
                }
                else if (currentAccount.IsAdmin)
                {
                    ViewBag.IsAdmin = currentAccount.IsAdmin;
                }
                else
                {
                    ViewBag.IsAdmin = false;
                }
            }
            else
            {
                ViewBag.IsAdmin = false;
            }
            base.OnActionExecuting(filterContext);
        }
Пример #2
0
        public ActionResult Index()
        {
            var viewModel = new DashboardViewModel
            {
                NewEnterprises      = new List <Enterprise>(),
                ModifiedEnterprises = new List <Enterprise>(),
                Account             = AccountViewHelper.ModelToViewModel(CurrentAccount)
            };

            if (CurrentAccount.IsAdmin)
            {
                var modifiedAndNewEnterprises = Db.Enterprises.GetModifiedAndNewEnterprises().ToList();

                var newEnterprises      = modifiedAndNewEnterprises.Where(e => e.IsNew);
                var modifiedEnterprises = modifiedAndNewEnterprises.Where(e => e.LockedFromEdit);

                viewModel.NewEnterprises      = newEnterprises.ToList();
                viewModel.ModifiedEnterprises = modifiedEnterprises.ToList();
                viewModel.AllEnterprises      = Db.Enterprises.GetAllEnterprises().OrderBy(e => e.Name);

                viewModel.ProductCount = Db.Products.ProductTotalCount();
            }
            else
            {
                //if (CurrentAccount.Enterprise == null)
                //{
                //    return View(model);
                //}

                //var enterprise = Repository.GetEnterpriseById(CurrentAccount.Enterprise);

                //if (enterprise.Menu != null)
                //{
                //    var menu = Repository.GetMenuById(enterprise.Menu);
                //    var products = Repository.GetProducts(menu.Products.ToList());

                //var s = ViewModelHelper.CreateStandardViewModel(enterprise, products);
                //model.StandardViewModel = s;
                //}
            }
            return(View(viewModel));
        }