Esempio n. 1
0
        public void SetLoginSession()
        {
            if (Session[Core.Constans.SessionKey.CurrentUser] == null)
            {
                var      userId  = User.Identity.Name.Split('\\')[User.Identity.Name.Split('\\').Length - 1]; //User.Identity.Name.Remove(0, 4);
                IUserBLL userBll = MvcApplication.GetInstance <UserBLL>();
                IPOABLL  poabll  = MvcApplication.GetInstance <POABLL>();
                IUserAuthorizationBLL userAuthorizationBll = MvcApplication.GetInstance <UserAuthorizationBLL>();
                var loginResult = userBll.GetLogin(userId);

                if (loginResult != null)
                {
                    //CurrentUser = loginResult;
                    loginResult.UserRole       = poabll.GetUserRole(loginResult.USER_ID);
                    loginResult.AuthorizePages = userAuthorizationBll.GetAuthPages(loginResult.USER_ID);
                    loginResult.NppbckPlants   = userAuthorizationBll.GetNppbckPlants(loginResult.USER_ID);
                    loginResult.ListUserPlants = new List <string>();
                    loginResult.ListUserNppbkc = new List <string>();
                    switch (loginResult.UserRole)
                    {
                    case Enums.UserRole.User:
                    case Enums.UserRole.Viewer:
                    case Enums.UserRole.Controller:
                        loginResult.ListUserPlants =
                            userAuthorizationBll.GetListPlantByUserId(loginResult.USER_ID);
                        loginResult.ListUserNppbkc =
                            userAuthorizationBll.GetListNppbkcByUserId(loginResult.USER_ID);
                        break;

                    case Enums.UserRole.POA:
                        loginResult.ListUserPlants = new List <string>();
                        foreach (var nppbkcPlantDto in loginResult.NppbckPlants)
                        {
                            foreach (var plantDto in nppbkcPlantDto.Plants)
                            {
                                loginResult.ListUserPlants.Add(plantDto.WERKS);
                            }
                        }
                        loginResult.ListUserNppbkc = loginResult.NppbckPlants.Select(c => c.NppbckId).ToList();
                        break;
                    }
                }
                Session[Core.Constans.SessionKey.CurrentUser] = loginResult;
            }
        }
        public ActionResult Index(LoginFormModel model)
        {
            var loginResult = _userBll.GetLogin(model.Login.UserId);

            if (loginResult != null)
            {
                //CurrentUser = loginResult;
                CurrentUser.UserRole       = _poabll.GetUserRole(loginResult.USER_ID);
                CurrentUser.AuthorizePages = _userAuthorizationBll.GetAuthPages(loginResult.USER_ID);
                CurrentUser.NppbckPlants   = _userAuthorizationBll.GetNppbckPlants(loginResult.USER_ID);
                CurrentUser.ListUserPlants = new List <string>();
                CurrentUser.ListUserNppbkc = new List <string>();
                switch (CurrentUser.UserRole)
                {
                case Enums.UserRole.User:
                case Enums.UserRole.Controller:
                case Enums.UserRole.Viewer:
                    CurrentUser.ListUserPlants =
                        _userAuthorizationBll.GetListPlantByUserId(loginResult.USER_ID);
                    CurrentUser.ListUserNppbkc =
                        _userAuthorizationBll.GetListNppbkcByUserId(loginResult.USER_ID);
                    break;

                case Enums.UserRole.POA:
                    CurrentUser.ListUserPlants = new List <string>();
                    foreach (var nppbkcPlantDto in CurrentUser.NppbckPlants)
                    {
                        foreach (var plantDto in nppbkcPlantDto.Plants)
                        {
                            CurrentUser.ListUserPlants.Add(plantDto.WERKS);
                        }
                    }
                    CurrentUser.ListUserNppbkc = CurrentUser.NppbckPlants.Select(c => c.NppbckId).ToList();
                    break;
                }


                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Unauthorized", "Error"));
        }