Exemplo n.º 1
0
        public ActionResult DeletePermission(int UserRightPermissionID)
        {
            int employeeCount = db.Employee.Where(s => s.UserRightPermissionID == UserRightPermissionID).Count();

            if (employeeCount > 0)
            {
                return(Json(new { Success = false, UserRightUsed = true }, JsonRequestBehavior.AllowGet));
            }

            UserRightPermission userRightPermission = db.UserRightPermission.Where(s => s.UserRightPermissionID == UserRightPermissionID).FirstOrDefault();

            if (userRightPermission != null)
            {
                try
                {
                    db.Entry(userRightPermission).State = EntityState.Deleted;
                    db.SaveChanges();
                    return(Json(new { Success = true, UserRightPermissionID = UserRightPermissionID }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        //public UserRIghtCheck(string s)
        //{
        //    ControllerValue = s;
        //}


        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (HttpContext.Current.Session["LoginEmpName"] == "ReallyUnknownPerson")
            {
                return;
            }
            else
            {
                var loginID = AppUtils.GetLoginUserID();
                if (AppUtils.GetLoginRoleID() != AppUtils.AdminRole || AppUtils.GetLoginRoleID() != AppUtils.SuperAdminRole || AppUtils.GetLoginRoleID() != AppUtils.SuperTalentUserRole)
                {
                    HttpContext.Current.Session["CurrentUserRightPermission"] = db.Employee.Where(s => s.EmployeeID == loginID /*AppUtils.LoginUserID*/).Select(s => s.UserRightPermissionID).FirstOrDefault().Value;
                }
                else
                {
                    HttpContext.Current.Session["CurrentUserRightPermission"] = db.CompanyVsStaff.Where(s => s.CompanyVsStaffID == loginID /*AppUtils.LoginUserID*/).Select(s => s.UserRightPermissionID).FirstOrDefault().Value;
                }
                int CurrentUserRightPermission = (int)HttpContext.Current.Session["CurrentUserRightPermission"];

                UserRightPermission userRightPermission = db.UserRightPermission.Where(s => s.UserRightPermissionID == CurrentUserRightPermission).FirstOrDefault();
                if (!string.IsNullOrEmpty(userRightPermission.UserRightPermissionDetails))
                {
                    List <string> lstAcessList = db.UserRightPermission.Where(s => s.UserRightPermissionID == CurrentUserRightPermission).Select(s => s.UserRightPermissionDetails).FirstOrDefault().Split(',').ToList();
                    HttpContext.Current.Session["lstAccessList"] = lstAcessList.Count() > 0 ? lstAcessList.ToList() : new List <string>();

                    AppUtils.GetTempNotUpdateEmployee = ConfigurationManager.AppSettings["EmployeeList"].Split(',').ToList();

                    ClaimsIdentity claimsIdentity = HttpContext.Current.User.Identity as ClaimsIdentity;

                    if (lstAcessList.Count() < 1)
                    {
                        filterContext.Result = new Http403Result();
                        //filterContext.Result = new RedirectResult("~/Account/LoginByClient");
                        return;
                    }
                    else
                    {
                        if (!AppUtils.HasAccessInTheList(ControllerValue))
                        {
                            filterContext.Result = new Http403Result();

                            //throw new UnauthorizedAccessException();
                            //   throw new HttpException((int)System.Net.HttpStatusCode.Forbidden, "Forbidden");


                            //return Content(HttpStatusCode.Forbidden, "RFID is disabled for this site.");
                            //HttpContext.Current.Session["role_id"] = null;
                            //claimsIdentity = null;
                            //    filterContext.Result = new RedirectResult("~/Account/LoginByClient");
                            //    return;
                        }
                    }
                }

                else
                {
                    filterContext.Result = new Http403Result();
                }
            }
        }
Exemplo n.º 3
0
        public JsonResult SaveCheckedNodes(List <string> checkedIds, int UserRightID)
        {
            if (checkedIds != null)
            {
                string userRightFromClient = "";

                UserRightPermission userRightPermission =
                    db.UserRightPermission.Where(s => s.UserRightPermissionID == UserRightID).FirstOrDefault();

                if (userRightPermission != null)
                {
                    //foreach (var item in checkedIds)
                    //{
                    //    userRightFromClient += item + ",";
                    //}
                    userRightFromClient = checkedIds.Aggregate(userRightFromClient, (current, item) => current + (item + ","));
                    userRightPermission.UserRightPermissionDetails = userRightFromClient;
                }

                db.Entry(userRightPermission).State = EntityState.Modified;
                db.SaveChanges();

                //// using (ApplicationDbContext context = new ApplicationDbContext())
                // {
                //     //var locations = context.Locations.ToList();
                //     //foreach (var location in locations)
                //     //{
                //     //    location.Checked = checkedIds.Contains(location.ID);
                //     //}
                //     //context.SaveChanges();
                // }
            }

            return(this.Json(true));
        }
Exemplo n.º 4
0
        public ActionResult AddUserRightName(string UserRightName)
        {
            if (string.IsNullOrEmpty(UserRightName.Trim()))
            {
                return(Json(new { Sucess = false }, JsonRequestBehavior.AllowGet));
            }
            UserRightPermission userRightPermissionDB = db.UserRightPermission.Where(s => s.UserRightPermissionName.Trim() == UserRightName.Trim()).FirstOrDefault();

            if (userRightPermissionDB != null)
            {
                return(Json(new { Exist = true }, JsonRequestBehavior.AllowGet));
            }

            try
            {
                UserRightPermission userRightPermissionForInsert = new UserRightPermission();
                userRightPermissionForInsert.UserRightPermissionName = UserRightName;
                userRightPermissionForInsert.CreateBy   = AppUtils.GetLoginEmployeeName();
                userRightPermissionForInsert.CreateDate = AppUtils.GetDateTimeNow();

                db.UserRightPermission.Add(userRightPermissionForInsert);
                db.SaveChanges();
                //.val(item.UserRightID).text(item.UserRightName));
                var lstUserRightList = db.UserRightPermission.Select(s => new { UserRightPermissionID = s.UserRightPermissionID, UserRightPermissionName = s.UserRightPermissionName }).ToList();

                return(Json(new { Success = true, lstUserRight = lstUserRightList }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Sucess = false }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 5
0
        public ActionResult SetUserPermission(List <ISPAccessList> model, int?UserRightID)
        {
            string info = "";

            foreach (var item in model)
            {
                if (item.IsGranted)
                {
                    info += item.AccessValue + ",";
                }
            }
            info = info.TrimEnd(',');
            try
            {
                UserRightPermission dbd = db.UserRightPermission.Where(s => s.UserRightPermissionID == UserRightID).FirstOrDefault();
                if (dbd != null)
                {
                    dbd.UserRightPermissionDetails = info;
                    db.Entry(dbd).State            = EntityState.Modified;
                    db.SaveChanges();
                }
                TempData["UserRightID"] = UserRightID;
                TempData["ShowMessage"] = "Permission Saved Successfully";
            }
            catch (Exception ex)
            {
                TempData["ShowMessage"] = "Failed to Save Permission. Contact With administrator.";
            }
            //ViewBag.UserRightID = new SelectList(db.UserRightPermission.Select(s => new { UserRightPermissionName = s.UserRightPermissionName, UserRightPermissionID = s.UserRightPermissionID }).ToList(), "UserRightPermissionID", "UserRightPermissionName");
            //ViewBag.EmployeeID = new SelectList(db.Employee.Select(s => new { EmployeeID = s.EmployeeID, Name = s.Name }).ToList(), "EmployeeID", "Name");

            //            List<ISPAccessList> lstISPAccessList = db.ISPAccessList.ToList();
            TempData["tmpListOfAccess"] = model;
            return(RedirectToAction("UserRightPermission", "Account"));
        }
Exemplo n.º 6
0
        private string GetButtonForPurchaseList(Purchase purchase)
        {
            string button       = "";
            bool   rowIsDeleted = purchase.Status == AppUtils.TableStatusIsDelete ? true : false;

            int CurrentUserRightPermission          = AppUtils.GetLoginUserRightPermissionID();
            UserRightPermission userRightPermission = db.UserRightPermission.Where(s => s.UserRightPermissionID == CurrentUserRightPermission).FirstOrDefault();

            List <int> lstRightPerssion = new List <int>();

            lstRightPerssion = userRightPermission.UserRightPermissionDetails.Trim(',').Split(',').Select(int.Parse).ToList();
            bool addPurchaePayment = false, updatePurchase = false, viewPurchasePayment = false, deletePurchasePayment = false;

            if (rowIsDeleted)
            {
                addPurchaePayment = true; updatePurchase = true; viewPurchasePayment = true; deletePurchasePayment = true;
                //button += "<a target='_blank' href='/purchase/PurchasePayment ? pid = " + purchase.PurchaseID + "' class='btn btn-primary btn-xs' data-original-title='View' id='ViewPurchase'><i class='fa fa-file-text-o'></i></a>   " +
                //    " <a target='_blank' href='/purchase/Edit?pid=" + purchase.PurchaseID + "' class='btn btn-info btn-xs' data-original-title='Edit' id='EditPurchase'><i class='fa fa-pencil'></i></a>" +
                //    " <a href='javascript:void(0)' class='btn btn-primary btn-xs' data-original-title='View' id='btnShowPurchasePaymentHistory'><i class='fa fa-lis'></i></a>         " +
                //    "<a href='#' class='btn btn-danger btn-xs cdelete' data-original-title='Delete' id='btnDeletePurchase' ><i class='fa fa-trash'></i></a>";
            }
            else
            {
                addPurchaePayment = true; updatePurchase = true; viewPurchasePayment = true; deletePurchasePayment = true;
            }

            if (addPurchaePayment)
            {
                if (lstRightPerssion.Contains(int.Parse(AppUtils.Add_Purchase_Payment)))
                {
                    button += "<a target='_blank' href='/purchase/PurchasePayment?pid=" + purchase.PurchaseID + "' class='btn btn-primary btn-xs' data-original-title='View' id='ViewPurchase'><i class='fa fa-file-text-o'></i></a>";
                }
            }
            if (updatePurchase)
            {
                if (lstRightPerssion.Contains(int.Parse(AppUtils.View_Purchase)))
                {
                    button += "<a target='_blank' href='/purchase/Edit?pid=" + purchase.PurchaseID + "' class='btn btn-info btn-xs' data-original-title='Edit' id='EditPurchase'><i class='fa fa-pencil'></i></a>";
                }
            }
            if (viewPurchasePayment)
            {
                if (lstRightPerssion.Contains(int.Parse(AppUtils.View_Purchase_Payment)))
                {
                    button += " <a href='javascript:void(0)' class='btn btn-primary btn-xs' data-original-title='View' id='btnShowPurchasePaymentHistory'><i class='fa fa-list'></i></a> ";
                }
            }
            if (deletePurchasePayment)
            {
                if (lstRightPerssion.Contains(int.Parse(AppUtils.Delete_Purchase_Payment)))
                {
                    button += "<a href='#' class='btn btn-danger btn-xs cdelete' data-original-title='Delete' id='btnDeletePurchase' ><i class='fa fa-trash'></i></a>";
                }
            }

            return(button);
        }
Exemplo n.º 7
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var loginID = AppUtils.GetLoginUserID();

            if (AppUtils.GetLoginRoleID() == AppUtils.ClientRole)
            {
                HttpContext.Current.Session["CurrentUserRightPermission"] = db.ClientDetails.Where(s => s.ClientDetailsID == loginID /*AppUtils.LoginUserID*/).Select(s => s.UserRightPermissionID).FirstOrDefault().Value;
            }
            else if (AppUtils.GetLoginRoleID() == AppUtils.AdminRole || AppUtils.GetLoginRoleID() == AppUtils.SuperUserRole || AppUtils.GetLoginRoleID() == AppUtils.EmployeeRole)
            {
                HttpContext.Current.Session["CurrentUserRightPermission"] = db.Employee.Where(s => s.EmployeeID == loginID /*AppUtils.LoginUserID*/).Select(s => s.UserRightPermissionID).FirstOrDefault().Value;
            }
            else
            {
                HttpContext.Current.Session["CurrentUserRightPermission"] = db.Reseller.Where(s => s.ResellerID == loginID /*AppUtils.LoginUserID*/).Select(s => s.UserRightPermissionID).FirstOrDefault().Value;
            }

            int CurrentUserRightPermission          = (int)HttpContext.Current.Session["CurrentUserRightPermission"];
            UserRightPermission userRightPermission = db.UserRightPermission.Where(s => s.UserRightPermissionID == CurrentUserRightPermission).FirstOrDefault();

            if (!string.IsNullOrEmpty(userRightPermission.UserRightPermissionDetails))
            {
                int MikrotikOptionEnable;
                int SMSOptionEnable;
                //string[] lstMikrotikReleated = { "91", "92", "93", "94", "95", "96" };
                //string[] lstSMSReleated = { "88", "89", "90" };
                List <OptionSettings> lstOptionSettings = db.OptionSettings.AsNoTracking().ToList();
                //SMSOptionEnable = lstOptionSettings[0].Status;
                //MikrotikOptionEnable = lstOptionSettings[1].Status;

                HttpContext.Current.Session["MikrotikOptionEnable"] = (lstOptionSettings[1].Status == 1) ? true : false;
                HttpContext.Current.Session["SMSOptionEnable"]      = (lstOptionSettings[0].Status == 1) ? true : false;

                List <string> lstAcessList = db.UserRightPermission.Where(s => s.UserRightPermissionID == CurrentUserRightPermission).Select(s => s.UserRightPermissionDetails).FirstOrDefault().Split(',').ToList();
                HttpContext.Current.Session["lstAccessList"] = ((bool)HttpContext.Current.Session["MikrotikOptionEnable"] == true && (bool)HttpContext.Current.Session["SMSOptionEnable"] == true) ? lstAcessList.ToList()
                    : ((bool)HttpContext.Current.Session["MikrotikOptionEnable"]) ? lstAcessList.Where(s => !AppUtils.lstSMSReleated.Contains(s)).ToList()
                        : ((bool)HttpContext.Current.Session["SMSOptionEnable"] == true) ? lstAcessList.Where(s => !AppUtils.lstMikrotikReleated.Contains(s)).ToList()
                            : lstAcessList.Where(s => (!AppUtils.lstMikrotikReleated.Contains(s) && !AppUtils.lstSMSReleated.Contains(s))).ToList();

                AppUtils.GetTempNotUpdateEmployee = ConfigurationManager.AppSettings["EmployeeList"].Split(',').ToList();

                if (AppUtils.LstAccessCount() < 1)
                {
                    filterContext.Result = new Http403Result();
                    //filterContext.Result = new RedirectResult("~/Account/LoginByClient");
                    return;
                }
            }

            else
            {
                filterContext.Result = new Http403Result();
            }

            base.OnActionExecuting(filterContext);
        }
Exemplo n.º 8
0
        public ActionResult LoginByCompanyPerson(LogInViewModel LoginViewModel, string returnUrl, int Type)
        {
            if (ModelState.IsValid)
            {
                dynamic logindetails = "";
                logindetails = db.CompanyVsStaff
                               .Where(s => s.LoginName == LoginViewModel.UserName &&
                                      s.Password == LoginViewModel.Password &&
                                      s.Status == AppUtils.TableStatusIsActive &&
                                      s.UserRightPermission != null).FirstOrDefault();
                if (logindetails != null)
                {
                    //int roleID = logindetails.RoleID;

                    this.SignInUser(logindetails.CompanyVsStaffID, logindetails.LoginName, logindetails.RoleID, false);
                    this.Session["role_id"]               = logindetails.RoleID;
                    this.Session["LoginEmpName"]          = "";
                    Session["CurrentUserRightPermission"] = logindetails.UserRightPermissionID;
                    List <AccessList> lstAccessList = new List <AccessList>();



                    int CurrentUserRightPermission = (int)Session["CurrentUserRightPermission"];

                    UserRightPermission userRightPermission =
                        db.UserRightPermission
                        .Where(s => s.UserRightPermissionID == CurrentUserRightPermission)
                        .FirstOrDefault();
                    if (!string.IsNullOrEmpty(userRightPermission.UserRightPermissionDetails))
                    {
                        List <string> lstAcessList =
                            db.UserRightPermission
                            .Where(s => s.UserRightPermissionID == CurrentUserRightPermission)
                            .Select(s => s.UserRightPermissionDetails).FirstOrDefault().Split(',').ToList();
                        //AppUtils.lstAccessList =
                        Session["lstAccessList"] = lstAcessList.ToList();
                    }

                    //AppUtils.lstAccessList  = db.UserRightPermission.Where(s=>s.)
                    return(this.RedirectToLocal(returnUrl));
                }
                else
                {
                    TempData["TempInformation"] = "Sorry InValid UserName Or Password.";
                    //ModelState.AddModelError("", "Invalid username or password.");
                }
            }
            //}
            //else
            //{
            //    TempData["TempInformation"] = "Sorry Mac Address is different.";
            //}

            ViewBag.ReturnUrl = returnUrl;
            return(View(LoginViewModel));
        }
Exemplo n.º 9
0
        public ActionResult LoginByVirtualStaff(LogInViewModel LoginViewModel, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                dynamic logindetails = "";

                logindetails = db.Employee
                               .Where(s => s.LoginName == LoginViewModel.UserName &&
                                      s.Password == LoginViewModel.Password &&
                                      s.Status == AppUtils.TableStatusIsActive &&
                                      s.UserRightPermission != null).FirstOrDefault();
                if (logindetails != null)
                {
                    //int roleID = logindetails.RoleID;

                    this.SignInUser(logindetails.EmployeeID, logindetails.LoginName, logindetails.RoleID, false);
                    this.Session["role_id"]               = logindetails.RoleID;
                    this.Session["LoginEmpName"]          = "";
                    Session["CurrentUserRightPermission"] = logindetails.UserRightPermissionID;
                    List <AccessList> lstAccessList = new List <AccessList>();

                    int CurrentUserRightPermission = (int)Session["CurrentUserRightPermission"];

                    UserRightPermission userRightPermission =
                        db.UserRightPermission
                        .Where(s => s.UserRightPermissionID == CurrentUserRightPermission)
                        .FirstOrDefault();
                    if (!string.IsNullOrEmpty(userRightPermission.UserRightPermissionDetails))
                    {
                        List <string> lstAcessList =
                            db.UserRightPermission
                            .Where(s => s.UserRightPermissionID == CurrentUserRightPermission)
                            .Select(s => s.UserRightPermissionDetails).FirstOrDefault().Split(',').ToList();
                        Session["lstAccessList"] = lstAcessList.ToList();
                    }

                    //AppUtils.lstAccessList  = db.UserRightPermission.Where(s=>s.)
                    return(RedirectToAction(returnUrl));
                }
                else
                {
                    TempData["TempInformation"] = "Sorry InValid UserName Or Password.";
                    //ModelState.AddModelError("", "Invalid username or password.");
                }
            }
            else
            {
                ModelState.AddModelError("", "SomeThing is wrong Contact with administrator.");
            }



            ViewBag.ReturnUrl = returnUrl;
            return(View(LoginViewModel));
        }
Exemplo n.º 10
0
        public ActionResult UserRightPermission(List <VM_Form_Action_UserRight> model, int?UserRightID)
        {
            ViewBag.UserRightID = new SelectList(db.UserRightPermission.Select(s => new { UserRightPermissionName = s.UserRightPermissionName, UserRightPermissionID = s.UserRightPermissionID }).ToList(), "UserRightPermissionID", "UserRightPermissionName");
            ViewBag.EmployeeID  = new SelectList(db.Employee.Select(s => new { EmployeeID = s.EmployeeID, Name = s.Name }).ToList(), "EmployeeID", "Name");

            string permissionList = "";

            foreach (var item in model)
            {
                if (item.FormNameForAuth.IsGranted == true)
                {
                    permissionList += item.FormNameForAuth.FormNameID + ",";
                    if (item.ActionNameAuthentication != null)
                    {
                        foreach (var items in item.ActionNameAuthentication)
                        {
                            if (items.IsGranted == true)
                            {
                                permissionList += items.ActionNameID + ",";
                            }
                        }
                    }
                }
            }
            if (permissionList.Length > 0)
            {
                permissionList = permissionList.TrimEnd(new char[] { ',' });

                UserRightPermission userRightPermission =
                    db.UserRightPermission.Where(s => s.UserRightPermissionID == UserRightID.Value).FirstOrDefault();
                if (userRightPermission != null)
                {
                    userRightPermission.UserRightPermissionDetails = permissionList;
                    db.Entry(userRightPermission).State            = EntityState.Modified;
                    db.SaveChanges();
                    TempData["UserPermissionSavedSuccessfull"] = "Permission Added Successfully.";
                }
                else
                {
                    TempData["Fail"] = "Something is wrong Contact With Administrator.";
                }
            }
            else
            {
                TempData["Fail"] = "Something is wrong Contact With Administrator.";
            }


            //  return this.Json(true);
            // return RedirectToAction("UserRightPermission");
            return(View(model));
        }
Exemplo n.º 11
0
        private void HasAccessOnPurchasePaymentAction(ref bool hasUpdateAccess, ref bool hasDeleteAccess)
        {
            int CurrentUserRightPermission          = AppUtils.GetLoginUserRightPermissionID();
            UserRightPermission userRightPermission = db.UserRightPermission.Where(s => s.UserRightPermissionID == CurrentUserRightPermission).FirstOrDefault();

            List <int> lstRightPerssion = new List <int>();

            lstRightPerssion = userRightPermission.UserRightPermissionDetails.Trim(',').Split(',').Select(int.Parse).ToList();
            if (lstRightPerssion.Contains(int.Parse(AppUtils.Delete_Purchase_Payment)))
            {
                hasDeleteAccess = true;
            }
            //if (lstRightPerssion.Contains(int.Parse(AppUtils.Update_ResellerPayment)))
            //{
            //    hasUpdateAccess = true;
            //}
        }
Exemplo n.º 12
0
        public ActionResult GetPermissionDetailsByUserRightID(int UserRightID)
        {
            UserRightPermission userRightPermission =
                db.UserRightPermission.Where(s => s.UserRightPermissionID == UserRightID).FirstOrDefault();

            if (userRightPermission != null)
            {
                List <string> lstUserRightPermission = string.IsNullOrEmpty(userRightPermission.UserRightPermissionDetails) ? new List <string>() : userRightPermission.UserRightPermissionDetails.ToString().Split(',').ToList();
                //List <string> lstUserRightPermission =
                //    userRightPermission.UserRightPermissionDetails.ToString().Split(',').ToList();
                lstUserRightPermission.RemoveAll(s => string.IsNullOrEmpty(s));
                return(Json(new { Success = true, PermissionList = lstUserRightPermission }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { Success = false, PermissionList = "" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 13
0
        public ActionResult UserRightPermission(int?UID) //ActionNameAuthentication() {ActionNameID = Action.FirstOrDefault().ActionID
        {
            List <ISPAccessList> lstISPAccessList = new List <ISPAccessList>();
            //AppUtils.GetTempNotUpdateEmployee = ConfigurationManager.AppSettings[""].Split(',').Cast<int>().ToList();

            int MikrotikOptionEnable;
            int SMSOptionEnable;
            //int [] lstMikrotikReleated= { 91,92,93, 94, 95, 96 };
            //int [] lstSMSReleated= { 88,89,90};
            List <OptionSettings> lstOptionSettings = db.OptionSettings.ToList();

            SMSOptionEnable      = lstOptionSettings[0].Status;
            MikrotikOptionEnable = lstOptionSettings[1].Status;


            //this is for when return the saved User Right
            if (TempData["tmpListOfAccess"] != null)
            {
                ViewBag.UserRightID = new SelectList(db.UserRightPermission.Select(s => new { UserRightPermissionName = s.UserRightPermissionName, UserRightPermissionID = s.UserRightPermissionID }).ToList(), "UserRightPermissionID", "UserRightPermissionName", (int)TempData["UserRightID"]);
                ViewBag.EmployeeID  = new SelectList(db.Employee.Select(s => new { EmployeeID = s.EmployeeID, Name = s.Name }).ToList(), "EmployeeID", "Name");

                lstISPAccessList = (List <ISPAccessList>)TempData["tmpListOfAccess"];
            }
            else
            {
                //this is for if some on want to update the User Right List then we will set the data data as checked which one is granted and select the user  permission name in view page.
                //else pass the empty data for save a new User Right permission
                ViewBag.UserRightID = UID != null ? new SelectList(db.UserRightPermission.Select(s => new { UserRightPermissionName = s.UserRightPermissionName, UserRightPermissionID = s.UserRightPermissionID }).ToList(), "UserRightPermissionID", "UserRightPermissionName", UID) : new SelectList(db.UserRightPermission.Select(s => new { UserRightPermissionName = s.UserRightPermissionName, UserRightPermissionID = s.UserRightPermissionID }).ToList(), "UserRightPermissionID", "UserRightPermissionName");
                ViewBag.EmployeeID  = new SelectList(db.Employee.Select(s => new { EmployeeID = s.EmployeeID, Name = s.Name }).ToList(), "EmployeeID", "Name");
                var lstAccessList = db.ISPAccessList.Where(x => x.ShowingStatus == 1).AsQueryable();
                int i             = lstAccessList.Count();
                lstISPAccessList = (MikrotikOptionEnable == 1 && SMSOptionEnable == 1) ? lstAccessList.ToList()
                    : (MikrotikOptionEnable == 1) ? lstAccessList.Where(s => !AppUtils.lstSMSReleated.Contains(s.AccessValue.ToString())).ToList()
                        : (SMSOptionEnable == 1) ? lstAccessList.Where(s => !AppUtils.lstMikrotikReleated.Contains(s.AccessValue.ToString())).ToList()
                            : lstAccessList.Where(s => (!AppUtils.lstMikrotikReleated.Contains(s.AccessValue.ToString()) && !AppUtils.lstSMSReleated.Contains(s.AccessValue.ToString()))).ToList();

                UserRightPermission userRightPermission = db.UserRightPermission.Where(s => s.UserRightPermissionID == UID.Value).FirstOrDefault();
                if (userRightPermission != null)
                {
                    List <string> lstStringOfAccess = userRightPermission.UserRightPermissionDetails.Split(',').ToList();
                    foreach (var item in lstISPAccessList)
                    {
                        if (lstStringOfAccess.Contains(item.AccessValue.ToString()))
                        {
                            item.IsGranted = true;
                        }
                    }
                }
            }
            //List<VM_Form_Action_UserRight> VM_Form_Action_UserRight = new List<VM_Form_Action_UserRight>();
            //VM_Form_Action_UserRight =
            //    db.Form.Where(s => !string.IsNullOrEmpty(s.FormName.Trim()) && s.ShowingStatus == 1).GroupJoin(db.Action.Where(s => !string.IsNullOrEmpty(s.ActionDescription.Trim()) && s.ShowingStatus == 1), Form => Form.FormID, Action => Action.FormID,
            //        (Form, Action) => new { Form = Form, Action = Action }).AsEnumerable().Select(s => new VM_Form_Action_UserRight
            //        {
            //            FormNameForAuth = new FormNameForAuth() { FormNameID = s.Form.FormValue, FormName = s.Form.FormDescription, IsGranted = false },
            //            ActionNameAuthentication = AddInList(s.Action)//s.Action.ForEach(ss=>new ActionNameAuthentication {})    new ActionNameAuthentication() { ActionNameID = s.Action.FirstOrDefault().ActionValue, ActionName = s.Action.FirstOrDefault().ActionDescription, IsGranted = false }//s.Action.ToList().ForEach(ss=>new ActionNameAuthentication() { ActionNameID = ss.ActionValue, ActionName = ss.ActionDescription, IsGranted = false })
            //        })
            //        //VM_Form_Action_UserRight}
            //        //{

            //        //    FormNameForAuth = new FormNameForAuth() { FormNameID = Form.FormID, FormName = Form.FormName, IsGranted = false },
            //        //    ActionNameAuthentication = new List<ActionNameAuthentication>() {Action.ToList().Select(a=>new {ActionID = a.ActionID})  }


            //        .ToList();
            //if (UID != null)
            //{
            //    UserRightPermission userRightPermission = db.UserRightPermission.Where(s => s.UserRightPermissionID == UID.Value).FirstOrDefault();
            //    if (userRightPermission != null)
            //    {
            //        if (userRightPermission.UserRightPermissionDetails != null)
            //        {
            //            List<string> lstUserRightDetails = userRightPermission.UserRightPermissionDetails.Split(',').ToList();
            //            foreach (var formAndButton in VM_Form_Action_UserRight)
            //            {
            //                if (lstUserRightDetails.Contains(formAndButton.FormNameForAuth.FormNameID))
            //                {
            //                    formAndButton.FormNameForAuth.IsGranted = true;
            //                }
            //                foreach (var button in formAndButton.ActionNameAuthentication)
            //                {
            //                    if (lstUserRightDetails.Contains(button.ActionNameID))
            //                    {
            //                        button.IsGranted = true;
            //                    }
            //                }

            //            }
            //        }

            //    }

            //}

            //return View(VM_Form_Action_UserRight);

            return(View(lstISPAccessList));
        }
Exemplo n.º 14
0
        public ActionResult ResellerLoginPage(LoginViewModel LoginViewModel, string returnUrl, int Type)
        {
            string macAddress = GetMACAddress();
            string conn       = ConfigurationManager.ConnectionStrings["ISPConnectionString"].ToString();

            ArrayList dbName = matchAll(@".*?Initial\s*Catalog\s*=\s*(.*?)\s*;", conn);

            if (dbName.Count < 1)
            {
                TempData["TempInformation"] =
                    "Sorry Connection String is not in correct format. Please contact with administrator.";
                return(View(LoginViewModel));
            }

            if (ModelState.IsValid)
            {
                dynamic logindetails = "";
                logindetails = db.Reseller
                               .Where(s => s.ResellerLoginName == LoginViewModel.UserName &&
                                      s.ResellerPassword == LoginViewModel.Password &&
                                      s.ResellerStatus == AppUtils.EmployeeStatusIsActive &&
                                      s.UserRightPermission != null).FirstOrDefault();
                if (logindetails != null)
                {
                    //int roleID = logindetails.RoleID;

                    this.SignInUser(logindetails.ResellerID, logindetails.ResellerName, logindetails.RoleID, false);
                    this.Session["role_id"]               = logindetails.RoleID;
                    this.Session["LoginEmpName"]          = "";
                    Session["CurrentUserRightPermission"] = logindetails.UserRightPermissionID;
                    List <ISPAccessList> lstISPAccessList = new List <ISPAccessList>();

                    int MikrotikOptionEnable;
                    int SMSOptionEnable;

                    List <OptionSettings> lstOptionSettings = db.OptionSettings.AsNoTracking().ToList();

                    //AppUtils.MikrotikOptionEnable = (lstOptionSettings[1].Status == 1) ? true : false;
                    //AppUtils.SMSOptionEnable = (lstOptionSettings[0].Status == 1) ? true : false;
                    Session["MikrotikOptionEnable"] = (lstOptionSettings[1].Status == 1) ? true : false;
                    Session["SMSOptionEnable"]      = (lstOptionSettings[0].Status == 1) ? true : false;



                    int CurrentUserRightPermission = (int)Session["CurrentUserRightPermission"];

                    UserRightPermission userRightPermission =
                        db.UserRightPermission
                        .Where(s => s.UserRightPermissionID == CurrentUserRightPermission)
                        .FirstOrDefault();
                    if (!string.IsNullOrEmpty(userRightPermission.UserRightPermissionDetails))
                    {
                        List <string> lstAcessList =
                            db.UserRightPermission
                            .Where(s => s.UserRightPermissionID == CurrentUserRightPermission)
                            .Select(s => s.UserRightPermissionDetails).FirstOrDefault().Split(',').ToList();
                        //AppUtils.lstAccessList =
                        Session["lstAccessList"] =
                            ((bool)Session["MikrotikOptionEnable"] == true && (bool)Session["SMSOptionEnable"] == true)
                            ? lstAcessList.ToList()
                            : ((bool)Session["MikrotikOptionEnable"] == true)
                                ? lstAcessList.Where(s => !AppUtils.lstSMSReleated.Contains(s)).ToList()
                                : ((bool)Session["SMSOptionEnable"] == true)
                                    ? lstAcessList.Where(s => !AppUtils.lstMikrotikReleated.Contains(s))
                            .ToList()
                                    : lstAcessList
                            .Where(s => (!AppUtils.lstMikrotikReleated.Contains(s) &&
                                         !AppUtils.lstSMSReleated.Contains(s))).ToList();
                    }

                    //AppUtils.lstAccessList  = db.UserRightPermission.Where(s=>s.)
                    return(this.RedirectToLocal(returnUrl, Type));
                }
                else
                {
                    TempData["TempInformation"] = "Sorry InValid UserName Or Password.";
                    //ModelState.AddModelError("", "Invalid username or password.");
                }
            }
            //}
            //else
            //{
            //    TempData["TempInformation"] = "Sorry Mac Address is different.";
            //}

            ViewBag.ReturnUrl = returnUrl;
            return(View(LoginViewModel));
        }
Exemplo n.º 15
0
        //public UserRIghtCheck(string s)
        //{
        //    ControllerValue = s;
        //}


        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (HttpContext.Current.Session["LoginEmpName"] == "ReallyUnknownPerson")
            {
                return;
            }
            else
            {
                var loginID = AppUtils.GetLoginUserID();
                if (AppUtils.GetLoginRoleID() != AppUtils.ResellerRole)
                {
                    HttpContext.Current.Session["CurrentUserRightPermission"] = db.Employee.Where(s => s.EmployeeID == loginID /*AppUtils.LoginUserID*/).Select(s => s.UserRightPermissionID).FirstOrDefault().Value;
                }
                else
                {
                    HttpContext.Current.Session["CurrentUserRightPermission"] = db.Reseller.Where(s => s.ResellerID == loginID /*AppUtils.LoginUserID*/).Select(s => s.UserRightPermissionID).FirstOrDefault().Value;
                }
                int CurrentUserRightPermission = (int)HttpContext.Current.Session["CurrentUserRightPermission"];

                UserRightPermission userRightPermission = db.UserRightPermission.Where(s => s.UserRightPermissionID == CurrentUserRightPermission).FirstOrDefault();
                if (!string.IsNullOrEmpty(userRightPermission.UserRightPermissionDetails))
                {
                    int MikrotikOptionEnable;
                    int SMSOptionEnable;
                    //string[] lstMikrotikReleated = { "91", "92", "93", "94", "95", "96" };
                    //string[] lstSMSReleated = { "88", "89", "90" };
                    List <OptionSettings> lstOptionSettings = db.OptionSettings.AsNoTracking().ToList();
                    //SMSOptionEnable = lstOptionSettings[0].Status;
                    //MikrotikOptionEnable = lstOptionSettings[1].Status;

                    HttpContext.Current.Session["MikrotikOptionEnable"] = (lstOptionSettings[1].Status == 1) ? true : false;
                    HttpContext.Current.Session["SMSOptionEnable"]      = (lstOptionSettings[0].Status == 1) ? true : false;

                    List <string> lstAcessList = db.UserRightPermission.Where(s => s.UserRightPermissionID == CurrentUserRightPermission).Select(s => s.UserRightPermissionDetails).FirstOrDefault().Split(',').ToList();
                    HttpContext.Current.Session["lstAccessList"] = ((bool)HttpContext.Current.Session["MikrotikOptionEnable"] && (bool)HttpContext.Current.Session["SMSOptionEnable"] == true) ? lstAcessList.ToList()
                        : ((bool)HttpContext.Current.Session["MikrotikOptionEnable"]) ? lstAcessList.Where(s => !AppUtils.lstSMSReleated.Contains(s)).ToList()
                            : ((bool)HttpContext.Current.Session["SMSOptionEnable"] == true) ? lstAcessList.Where(s => !AppUtils.lstMikrotikReleated.Contains(s)).ToList()
                                : lstAcessList.Where(s => (!AppUtils.lstMikrotikReleated.Contains(s) && !AppUtils.lstSMSReleated.Contains(s))).ToList();

                    AppUtils.GetTempNotUpdateEmployee = ConfigurationManager.AppSettings["EmployeeList"].Split(',').ToList();

                    ClaimsIdentity claimsIdentity = HttpContext.Current.User.Identity as ClaimsIdentity;

                    if (AppUtils.LstAccessCount() < 1)
                    {
                        filterContext.Result = new Http403Result();
                        //filterContext.Result = new RedirectResult("~/Account/LoginByClient");
                        return;
                    }
                    else
                    {
                        if (!AppUtils.HasAccessInTheList(ControllerValue))
                        {
                            filterContext.Result = new Http403Result();

                            //throw new UnauthorizedAccessException();
                            //   throw new HttpException((int)System.Net.HttpStatusCode.Forbidden, "Forbidden");


                            //return Content(HttpStatusCode.Forbidden, "RFID is disabled for this site.");
                            //HttpContext.Current.Session["role_id"] = null;
                            //claimsIdentity = null;
                            //    filterContext.Result = new RedirectResult("~/Account/LoginByClient");
                            //    return;
                        }
                    }
                }

                else
                {
                    filterContext.Result = new Http403Result();
                }
            }



            base.OnActionExecuting(filterContext);
        }