Exemplo n.º 1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (HttpContext.Current.Session["UserName"] == null)
            {
                var loggedInuser = "";
                var prinicpal    = (System.Security.Claims.ClaimsPrincipal)System.Threading.Thread.CurrentPrincipal;
                if (prinicpal != null && prinicpal.Claims != null)
                {
                    if (prinicpal.Claims.Where(c => c.Type == System.Security.Claims.ClaimTypes.Name).Any())
                    {
                        loggedInuser = prinicpal.Claims.Where(c => c.Type == System.Security.Claims.ClaimTypes.Name).Select(c => c.Value).FirstOrDefault();
                    }
                }
                HttpContext.Current.Session.Add("loggedInuser", loggedInuser);

                loggedInuser = loggedInuser.Replace("\\", "|");

                if (loggedInuser.Contains("|"))
                {
                    loggedInuser = loggedInuser.Split('|')[1];
                }

                loggedInuser = "******"; //Nomination User -- DH --RThangaraj
                //loggedInuser = "******"; //Nomination User DH -- RThangaraj
                //loggedInuser = "******";//Nomination User
                //loggedInuser = "******"; //DH user
                //loggedInuser = "******"; //DH user

                //loggedInuser = "******"; // Evaluation user
                //loggedInuser = "******"; // Evaluation user

                //loggedInuser = "******"; //TQC Head
                //loggedInuser = "******"; //Admin

                //loggedInuser = "******";
                //loggedInuser = "******";

                ILoginRepo         loginRepo = new LoginRepo();
                RepositoryResponse model     = loginRepo.GetLoginUserDetails(loggedInuser);

                if (model.success)
                {
                    EmpMasterModel _orGModel = model.Data;
                    if (_orGModel != null)
                    {
                        //RepositoryResponse _model = loginRepo.GetPageAccessListByUserGrade(_orGModel.Grade, loggedInuser);
                        //if (_model != null)
                        //{
                        //    HttpContext.Current.Session.Add("pageAccessList", _model.Data);
                        //    //claims.Add(new Claim(ClaimTypes.Actor, _model.Data));
                        //}
                    }

                    if (string.IsNullOrEmpty(_orGModel.ImagePath))
                    {
                        HttpContext.Current.Session.Add("UserImage", "/Images/UserImages/user-1.jpg");
                    }
                    else
                    {
                        HttpContext.Current.Session.Add("UserImage", _orGModel.ImagePath);
                    }

                    //HttpContext.Current.Session.Add("UserImage", _orGModel.ImagePath);
                    //HttpContext.Current.Session.Add("UserImage", "/Images/UserImages/user-1.jpg");
                    HttpContext.Current.Session.Add("UserName", _orGModel.UserName);
                    HttpContext.Current.Session.Add("UserFullName", _orGModel.EmployeeName);
                    HttpContext.Current.Session.Add("UserID", _orGModel.EmployeeNumber);
                    HttpContext.Current.Session.Add("UserDepartment", _orGModel.Department);
                    HttpContext.Current.Session.Add("UserGrade", _orGModel.Grade.ToString());

                    //claims.Add(new Claim(ClaimTypes.GivenName, _orGModel.UserName));
                    //claims.Add(new Claim(ClaimTypes.SerialNumber, _orGModel.EmployeeNumber));
                    //claims.Add(new Claim(ClaimTypes.Role, _orGModel.Department));
                    //claims.Add(new Claim(ClaimTypes.Surname, _orGModel.Grade));

                    //if (_orGModel.Grade == "A1")
                    //{
                    //    HttpContext.Current.Session.Add("UserGrade", _orGModel.Grade.ToString());
                    //    HttpContext.Current.Session.Add("UserRole", "Nomination");
                    //}
                    //else if (_orGModel.Grade == "DH")
                    //{
                    //    HttpContext.Current.Session.Add("UserGrade", _orGModel.Grade.ToString());
                    //    HttpContext.Current.Session.Add("UserRole", "DepartmentHead");
                    //}
                    //else if (_orGModel.Grade == "C1")
                    //{
                    //    HttpContext.Current.Session.Add("UserGrade", _orGModel.Grade.ToString());
                    //    HttpContext.Current.Session.Add("UserRole", "Evaluation");
                    //}
                    int empRole = 0;
                    RepositoryResponse _model1 = loginRepo.GetUserDetailsByUserID(_orGModel.EmployeeNumber);
                    if (_model1 != null && _model1.Data != null)
                    {
                        EmpMasterModel data = _model1.Data;
                        empRole = data.EmployeeSOMRole;
                        HttpContext.Current.Session.Add("EmpSOMRole", empRole.ToString());
                        HttpContext.Current.Session.Add("EmpSOMRoleText", data.EmployeeSOMRoleAsString);

                        string menuNames = loginRepo.getMenuForUser(_orGModel.EmployeeNumber, empRole);
                        HttpContext.Current.Session.Add("pageAccessList", menuNames);
                        //claims.Add(new Claim(ClaimTypes.StreetAddress, empRole.ToString()));
                    }

                    //Get Notification count
                    int count = loginRepo.getActionCounts(_orGModel.EmployeeNumber, empRole);

                    HttpContext.Current.Session.Add("NotifyCount", count);
                    //claims.Add(new Claim(ClaimTypes.HomePhone, count.ToString()));

                    //if (empRole == (int)EmployeeRole.Nomination)
                    //{
                    //    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Nomination" }));
                    //}
                    //else
                    //{
                    //    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Dashboard" }));
                    //}

                    //Get Star of the month details
                    IStarOfMonthRepo      starOfTheMonth = new StarOfMonthRepo();
                    List <EmpMasterModel> _data          = starOfTheMonth.GetLastThreeStarOftheMonthEmpDetails();
                    if (_data == null)
                    {
                        HttpContext.Current.Session.Add("SOM_Month_Count", "0");
                    }
                    else
                    {
                        HttpContext.Current.Session.Add("SOM_Month_Count", _data.Count);
                    }

                    for (int i = 0; i < _data.Count; i++)
                    {
                        HttpContext.Current.Session.Add("SOM_Month_" + i, _data[i].EMPMonth);
                        HttpContext.Current.Session.Add("SOM_Image_" + i, _data[i].ImagePath);
                    }
                }
                else
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "NoAccess" }));
                }
            }
            base.OnActionExecuting(filterContext);
        }
Exemplo n.º 2
0
        public ActionResult Save(StarOfMonthModel model)
        {
            string _loggedInUserID = System.Web.HttpContext.Current.Session["UserID"].ToString();

            _repoResponse = new RepositoryResponse();
            _statRepo     = new StarOfMonthRepo();

            if (ModelState.IsValid)
            {
                _repoResponse = _statRepo.AddOrEditStarOfMonth(model, _loggedInUserID);
                if (_repoResponse.success)
                {
                    _loginRepo = new LoginRepo();
                    int _empSOMRole = int.Parse(System.Web.HttpContext.Current.Session["EmpSOMRole"].ToString());
                    int count       = _loginRepo.getActionCounts(_loggedInUserID, _empSOMRole);
                    HttpContext.Session["NotifyCount"] = count;

                    // reload SOM information

                    IStarOfMonthRepo      starOfTheMonth = new StarOfMonthRepo();
                    List <EmpMasterModel> _data          = starOfTheMonth.GetLastThreeStarOftheMonthEmpDetails();
                    if (_data == null)
                    {
                        HttpContext.Session.Add("SOM_Month_Count", "0");
                    }
                    else
                    {
                        HttpContext.Session.Add("SOM_Month_Count", _data.Count);
                    }

                    for (int i = 0; i < _data.Count; i++)
                    {
                        HttpContext.Session.Add("SOM_Month_" + i, _data[i].EMPMonth);
                        HttpContext.Session.Add("SOM_Image_" + i, _data[i].ImagePath);
                    }


                    return(Json(new { success = true, message = _repoResponse.message }));
                }
                else
                {
                    return(Json(new { success = false, message = _repoResponse.message }));
                }
            }
            else
            {
                List <string> fieldOrder = new List <string>(new string[] {
                    "UserName", "Password"
                })
                                           .Select(f => f.ToLower()).ToList();

                var _message1 = ModelState
                                .Select(m => new { Order = fieldOrder.IndexOf(m.Key.ToLower()), Error = m.Value })
                                .OrderBy(m => m.Order)
                                .SelectMany(m => m.Error.Errors.Select(e => e.ErrorMessage)).ToList();

                _message = string.Join("<br/>", _message1);

                return(Json(new { success = false, message = _message }));
            }
        }
        public ActionResult Access(string returnUrl = "")
        {
            if (Request.IsAuthenticated)
            {
                var loggedInuser = "";
                var prinicpal    = (System.Security.Claims.ClaimsPrincipal)System.Threading.Thread.CurrentPrincipal;
                if (prinicpal != null && prinicpal.Claims != null)
                {
                    if (prinicpal.Claims.Where(c => c.Type == System.Security.Claims.ClaimTypes.Name).Any())
                    {
                        loggedInuser = prinicpal.Claims.Where(c => c.Type == System.Security.Claims.ClaimTypes.Name).Select(c => c.Value).FirstOrDefault();
                    }
                }
                Session["User"] = loggedInuser;

                loggedInuser = loggedInuser.Replace("\\", "|");

                if (loggedInuser.Contains("|"))
                {
                    loggedInuser = loggedInuser.Split('|')[1];
                }

                loggedInuser = "******"; //Nomination User -- DH --RThangaraj
                //loggedInuser = "******"; //Nomination User DH -- RThangaraj
                //loggedInuser = "******";//Nomination User
                //loggedInuser = "******"; //DH user
                //loggedInuser = "******"; //DH user

                //loggedInuser = "******"; // Evaluation user
                //loggedInuser = "******"; // Evaluation user

                //loggedInuser = "******"; //TQC Head
                //loggedInuser = "******"; //Admin

                //loggedInuser = "******";//Nomination User
                //loggedInuser = "******";//DH
                //loggedInuser = "******";
                // loggedInuser = "******";

                ILoginRepo         loginRepo = new LoginRepo();
                RepositoryResponse model     = loginRepo.GetLoginUserDetails(loggedInuser);

                if (model.success)
                {
                    EmpMasterModel _orGModel = model.Data;
                    if (_orGModel != null)
                    {
                        //RepositoryResponse _model = loginRepo.GetPageAccessListByUserGrade(_orGModel.Grade, loggedInuser);
                        //if (_model != null)
                        //{
                        //    Session.Add("pageAccessList", _model.Data);
                        //}
                        if (string.IsNullOrEmpty(_orGModel.ImagePath))
                        {
                            Session.Add("UserImage", "/Images/UserImages/user-1.jpg");
                        }
                        else
                        {
                            Session.Add("UserImage", _orGModel.ImagePath);
                        }

                        //Session.Add("UserImage", "/Images/UserImages/user-1.jpg");
                        Session.Add("UserName", _orGModel.UserName);
                        Session.Add("UserFullName", _orGModel.EmployeeName);
                        Session.Add("UserID", _orGModel.EmployeeNumber);
                        Session.Add("UserDepartment", _orGModel.Department);
                        Session.Add("UserGrade", _orGModel.Grade.ToString());
                    }

                    int empRole = 0;
                    RepositoryResponse _model1 = loginRepo.GetUserDetailsByUserID(_orGModel.EmployeeNumber);
                    if (_model1 != null && _model1.Data != null)
                    {
                        EmpMasterModel data = _model1.Data;
                        empRole = data.EmployeeSOMRole;
                        Session.Add("EmpSOMRole", empRole.ToString());
                        Session.Add("EmpSOMRoleText", data.EmployeeSOMRoleAsString);

                        string menuNames = loginRepo.getMenuForUser(_orGModel.EmployeeNumber, empRole);
                        Session.Add("pageAccessList", menuNames);
                    }

                    //Get Notification count
                    int count = loginRepo.getActionCounts(_orGModel.EmployeeNumber, empRole);

                    Session.Add("NotifyCount", count);

                    //Get Star of the month details
                    IStarOfMonthRepo      starOfTheMonth = new StarOfMonthRepo();
                    List <EmpMasterModel> _data          = starOfTheMonth.GetLastThreeStarOftheMonthEmpDetails();
                    if (_data == null)
                    {
                        Session.Add("SOM_Month_Count", "0");
                    }
                    else
                    {
                        Session.Add("SOM_Month_Count", _data.Count);
                    }

                    for (int i = 0; i < _data.Count; i++)
                    {
                        Session.Add("SOM_Month_" + i, _data[i].EMPMonth);
                        Session.Add("SOM_Image_" + i, _data[i].ImagePath);
                    }

                    if (empRole == (int)SOMEmpRole.Nomination)
                    {
                        return(RedirectToAction("Index", "Nomination"));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Dashboard"));
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }