Exemplo n.º 1
0
        /// <summary>
        /// 获取权限组数据
        /// </summary>
        /// <returns>返回管理员日志数据集</returns>
        public List <MasterRole> GetAllMasterRole()
        {
            List <MasterRole> list = new List <MasterRole>();

            try
            {
                string sql = "select * from manager_role";
                using (SqlDataReader reder = db.GetReader(sql))
                {
                    while (reder.Read())
                    {
                        MasterRole ml = new MasterRole();
                        ml.RoleId   = (int)reder["id"];
                        ml.RoleName = reder["role_name"].ToString();
                        list.Add(ml);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw new Exception("数据库异常!原因:" + ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("未知异常!原因:" + ex.Message);
            }
            return(list);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 通过分页获取权限组数据
        /// </summary>
        /// <param name="PageSize">页大小</param>
        /// <param name="PageNum">页码</param>
        /// <param name="WhereStr">条件</param>
        /// <param name="OrderBy">排序</param>
        /// <returns>返回管理员日志数据集</returns>
        public List <MasterRole> GetAllMasterRole(int PageSize, int PageNum, string WhereStr, string OrderBy)
        {
            List <MasterRole> list = new List <MasterRole>();

            try
            {
                SqlParameter[] sp = new SqlParameter[] {
                    new SqlParameter("@PageSize", PageSize),
                    new SqlParameter("@PageNum", PageNum),
                    new SqlParameter("@TableName", "manager_role"),
                    new SqlParameter("@WhereStr", WhereStr),
                    new SqlParameter("@OrderBy", OrderBy)
                };
                using (SqlDataReader reder = db.GetReaderByProc("Proc_Page", sp))
                {
                    while (reder.Read())
                    {
                        MasterRole ml = new MasterRole();
                        ml.RoleId   = (int)reder["id"];
                        ml.RoleName = reder["role_name"].ToString();
                        list.Add(ml);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw new Exception("数据库异常!原因:" + ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("未知异常!原因:" + ex.Message);
            }
            return(list);
        }
Exemplo n.º 3
0
        protected void gvRoles_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditRow")
            {
                ClearPageData();

                GridViewRow selectedRow = gvRoles.Rows[Convert.ToInt32(e.CommandArgument)];
                selectedRow.Style["background-color"] = "skyblue";

                Label lblRolename = (Label)selectedRow.Cells[1].FindControl("lblRolename");

                MasterRole objMasterRole = new MasterRole();
                objMasterRole.RoleID      = Convert.ToInt32(gvRoles.DataKeys[selectedRow.RowIndex]["RoleID"]);
                objMasterRole.RoleName    = lblRolename.Text;
                objMasterRole.Description = selectedRow.Cells[2].Text;
                objMasterRole.RoleStatus  = new UsersRoleDAL().GetRoles().Where(x => x.RoleID == objMasterRole.RoleID).Select(y => y.RoleStatus).FirstOrDefault();

                Session["SelectedMasterRole"] = objMasterRole;

                ddlRole.SelectedValue   = Convert.ToString(objMasterRole.RoleID);
                txtDesc.Text            = objMasterRole.Description;
                ddlStatus.SelectedIndex = -1;
                ddlStatus.Items.FindByValue(new Helper().GetItemStatusEnumName(Convert.ToChar(objMasterRole.RoleStatus))).Selected = true;
                GetDualListData(objMasterRole);

                EditForm.Visible = true;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取用户组
        /// </summary>
        /// <param name="RoleId">用户组Id</param>
        /// <returns>返回用户组</returns>
        public MasterRole GetRole(int RoleId)
        {
            MasterRole role = null;

            try
            {
                string         sql = "select * from manager_role where id=@RoleId";
                SqlParameter[] sp  = new SqlParameter[]
                {
                    new SqlParameter("@RoleId", RoleId)
                };
                using (SqlDataReader reder = db.GetReader(sql, sp))
                {
                    while (reder.Read())
                    {
                        role = new MasterRole((int)reder["id"], reder["role_name"].ToString());
                    }
                }
            }
            catch (SqlException ex)
            {
                throw new Exception("数据库异常!原因:" + ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("未知异常!原因:" + ex.Message);
            }
            return(role);
        }
        // GET: CourseManager
        public ActionResult Index()
        {
            ViewBag.Items = dbc.MasterRoles.ToList();
            var model = new MasterRole();

            ViewBag.RoleId   = new SelectList(dbc.Roles, "Id", "Name");
            ViewBag.MasterId = new SelectList(dbc.Masters, "Id", "Username");
            return(View(model));
        }
Exemplo n.º 6
0
 public void Save(MasterRole data)
 {
     if (data.RoleId == 0)
     {
         data.InstitutionId = _securityService.GetCurrentInstitutionId();
     }
     _roleRepository.Save(data);
     _roleRepository.Commit();
 }
        public ActionResult InsertRole(MasterRole model)
        {
            dict.Clear();
            dict.Add("@Role", model.RoleName);
            dict.Add("@mode", "InsertRole");
            int i      = common_Class.return_nonquery(dict, "Proc_role");
            var Result = i > 0 ? Convert.ToBoolean(true).ToString() : Convert.ToBoolean(false).ToString();

            return(Json(Result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddRole()
        {
            List <MasterRole>       RolesList = new List <MasterRole>();
            List <StateMasterModal> StateList = new List <StateMasterModal>();
            List <ZoneMastermodal>  ZoneList  = new List <ZoneMastermodal>();
            List <DropdownLit>      DropList  = new List <DropdownLit>();

            dict.Clear();
            dict.Add("@mode", "GetRoleRecord");
            DataSet dt = common_Class.return_dataset(dict, "Proc_role");
            int     r  = Convert.ToInt32(dt.Tables.Count);

            if (r > 0)
            {
                for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
                {
                    MasterRole master = new MasterRole();
                    master.Id           = Convert.ToInt32(dt.Tables[0].Rows[i]["id"]);
                    master.RoleName     = dt.Tables[0].Rows[i]["Role"].ToString();
                    master.active       = Convert.ToInt32(dt.Tables[0].Rows[i]["Active"]).ToString() == "1" ? "Active" : "Deactive";
                    master.InsertedDate = dt.Tables[0].Rows[i]["inserted_on"].ToString();
                    RolesList.Add(master);
                }
                for (int j = 0; j < dt.Tables[1].Rows.Count; j++)
                {
                    StateMasterModal state = new StateMasterModal();
                    state.Id        = Convert.ToInt32(dt.Tables[1].Rows[j]["id"]);
                    state.StateName = dt.Tables[1].Rows[j]["state"].ToString();
                    state.Active    = Convert.ToInt32(dt.Tables[1].Rows[j]["Active"]).ToString() == "1" ? "Active" : "Deactive";
                    StateList.Add(state);
                }
                for (int k = 0; k < dt.Tables[2].Rows.Count; k++)
                {
                    ZoneMastermodal zone = new ZoneMastermodal();
                    zone.Id        = Convert.ToInt32(dt.Tables[2].Rows[k]["id"]);
                    zone.StateId   = Convert.ToInt32(dt.Tables[2].Rows[k]["State_id"]);
                    zone.ZoneName  = dt.Tables[2].Rows[k]["Zone"].ToString();
                    zone.StateName = dt.Tables[2].Rows[k]["state"].ToString();
                    zone.Active    = Convert.ToInt32(dt.Tables[2].Rows[k]["active"]).ToString() == "1" ? "Active" : "Deactive";
                    ZoneList.Add(zone);
                }
                for (int l = 0; l < dt.Tables[3].Rows.Count; l++)
                {
                    DropdownLit DDLState = new DropdownLit();
                    DDLState.Id       = Convert.ToInt32(dt.Tables[3].Rows[l]["id"]);
                    DDLState.DropName = dt.Tables[3].Rows[l]["state"].ToString();
                    DropList.Add(DDLState);
                }
                ViewBag.DropListState = DropList;
                ViewBag.GetZoneList   = ZoneList;
                ViewBag.GetRoleList   = RolesList;
                ViewBag.GetStateList  = StateList;
            }
            return(View());
        }
Exemplo n.º 9
0
        protected void LocalDBCheck()
        {
            SqlConnection  conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["BPSecurity"].ConnectionString);
            SqlDataAdapter da   = new SqlDataAdapter("SELECT * FROM Roles", conn);
            DataTable      dt   = new DataTable();

            da.Fill(dt);

            for (int r = 0; r < dt.Rows.Count; r++)
            {
                Guid   roleid   = (Guid)dt.Rows[r]["RoleId"];
                string rolename = dt.Rows[r]["RoleName"].ToString();

                if (!new UsersRoleDAL().GetRoles().Select(x => x.RoleName).Contains(rolename))
                {
                    MasterRole roleObj = new MasterRole();
                    roleObj.RUID       = roleid;
                    roleObj.RoleName   = rolename;
                    roleObj.RoleStatus = "A";

                    if (rolename == "Admin")
                    {
                        roleObj.Description = "Control the setting of the system.";
                    }
                    if (rolename == "Preparer")
                    {
                        roleObj.Description = "Prepare the budget.";
                    }
                    if (rolename == "Reviewer")
                    {
                        roleObj.Description = "Review the prepared budget.";
                    }
                    if (rolename == "Approver")
                    {
                        roleObj.Description = "Approved the budget after prepared or reviewed.";
                    }
                    if (rolename == "Viewer")
                    {
                        roleObj.Description = "Display the result.";
                    }
                    //add role. backend process - start
                    if (!new UsersRoleDAL().InsertMasterRole(roleObj))
                    {
                        ((SiteMaster)this.Master).ShowMessage("Failure", "An error occurred while saving User Role");
                    }
                    //add role. backend process - end
                }
            }
        }
        public ActionResult AddOrDelete(MasterRole model)
        {
            try
            {
                var MasterRole = dbc.MasterRoles
                                 .Single(mr => mr.RoleId == model.RoleId && mr.MasterId == model.MasterId);
                dbc.MasterRoles.Remove(MasterRole);
            }
            catch
            {
                dbc.MasterRoles.Add(model);
            }
            dbc.SaveChanges();

            return(Content("Đã cập nhật vai trò"));
        }
 public ActionResult Insert(MasterRole model)
 {
     try
     {
         dbc.MasterRoles.Add(model);
         dbc.SaveChanges();
         TempData["Message"] = "Thêm mới thành công!";
         return(RedirectToAction("Index"));
     }
     catch
     {
         TempData["Message"] = "Thêm mới thất bại!";
         ViewBag.Items       = dbc.MasterRoles.ToList();
         return(View("Index", model));
     }
 }
Exemplo n.º 12
0
 public IHttpActionResult Delete(MasterRole data)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         _roleService.Delete(data);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
 public ActionResult Update(MasterRole model)
 {
     try
     {
         dbc.Entry(model).State = EntityState.Modified;
         dbc.SaveChanges();
         TempData["Message"] = "Cập nhật thành công!";
         return(RedirectToAction("Edit", new { model.Id }));
     }
     catch
     {
         TempData["Message"] = "Cập nhật thất bại!";
         ViewBag.Items       = dbc.MasterRoles.ToList();
         return(View("Index", model));
     }
 }
        public ActionResult AddOrDelete(MasterRole model)
        {
            var message = "";

            try
            {
                var ms = dbc.MasterRoles.Single(mr => mr.MasterId == model.MasterId && mr.RoleId == model.RoleId);
                dbc.MasterRoles.Remove(ms);
                message = "Xoa Thanh Cong";
            }
            catch
            {
                dbc.MasterRoles.Add(model);
                message = "Them Thanh Cong";
            }

            dbc.SaveChanges();
            return(Content(message));
        }
Exemplo n.º 15
0
        public void GetDualListData(MasterRole _Role)
        {
            try
            {
                List <int> RoleUserId = new UsersRoleDAL().ListUserRole().Where(x => x.RoleID == _Role.RoleID).Select(y => Convert.ToInt32(y.UserID)).ToList();

                var SelectedItems = new List <DualListClass>();

                for (int i = 0; i < RoleUserId.Count(); i++)
                {
                    SelectedItems.Add(
                        new DualListClass
                    {
                        Id   = RoleUserId[i],
                        Name = DAL.UsersDAL.StaticUserId(RoleUserId[i], "").UserName
                    });
                }

                Session["SelectedDualList"] = SelectedItems;

                List <MasterUser> lst = new UsersDAL().GetUsers();
                var items             = new List <DualListClass>();

                for (int i = 0; i < lst.Count(); i++)
                {
                    items.Add(
                        new DualListClass
                    {
                        Id   = lst[i].UserID,
                        Name = lst[i].UserName
                    });
                }

                Session["DualList"] = items;
                BindDualList();
            }
            catch (Exception ex)
            {
                ((SiteMaster)this.Master).ShowMessage("Error", "An error occurred", ex, true);
            }
        }
 public ActionResult EditRole(MasterRole model)
 {
     dict.Clear();
     dict.Add("@id", model.Id);
     if (model.Id > 0 && model.RoleName != null)
     {
         dict.Add("@Role", model.RoleName);
         dict.Add("@mode", "UpdateRole");
         int i      = common_Class.return_nonquery(dict, "Proc_role");
         var Result = i > 0 ? Convert.ToBoolean(true).ToString() : Convert.ToBoolean(false).ToString();
         return(Json(Result, JsonRequestBehavior.AllowGet));
     }
     else if (model.Id > 0 && model.RoleName == null)
     {
         dict.Add("@mode", "RoleActive/Diactivate");
         DataTable dt      = common_Class.return_datatable(dict, "Proc_role");
         int       Result2 = Convert.ToInt32(dt.Rows[0][0].ToString());
         return(Json(Result2, JsonRequestBehavior.AllowGet));
     }
     return(Json(3, JsonRequestBehavior.AllowGet));
 }
Exemplo n.º 17
0
        public async Task <ActionResult> Delete(MasterRole model)
        {
            try
            {
                RoleRepository Repository = new RoleRepository();
                var            result     = await Repository.DeleteRoleMMaster(model.RoleID, User.Identity.Name);

                if (result == true)
                {
                    return(await GetList());
                }
                else
                {
                    return(View(result));
                }
            }
            catch
            {
                return(View(false));
            }
        }
Exemplo n.º 18
0
 public Boolean DoAddMasterRole()
 {
     if (Session[Keys.SESSION_ADMIN_INFO] == null)
     {
         return(false);
     }
     else
     {
         Master master = Session[Keys.SESSION_ADMIN_INFO] as Master;
         if (rcm.GetRoleCompetence(master.RoleId, 1452))
         {
             string RItem    = Request["RItem"];
             string RoleName = Request["RoleName"];
             if (mm.AddMasterRole(RoleName))
             {
                 MasterRole mr = new MasterRole();
                 mr = mm.GetMasterRole(RoleName);
                 Boolean  IsSuccess = false;
                 string[] re        = RItem.Split(',');
                 foreach (string rc in re)
                 {
                     IsSuccess = rcm.AddCompentence(mr.RoleId, int.Parse(rc));
                     if (!IsSuccess)
                     {
                         rcm.DelAllCom(mr.RoleId);
                     }
                 }
                 return(IsSuccess);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 19
0
        public async Task <ActionResult> Create(MasterRole model)
        {
            try
            {
                RoleRepository Repository = new RoleRepository();
                var            result     = await Repository.CreateRoleMaster(model.Name, User.Identity.Name);

                if (result == true)
                {
                    return(await GetList());
                }
                else
                {
                    return(View(result));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                return(View(false));
            }
        }
Exemplo n.º 20
0
 public ActionResult EditRole(int R)
 {
     if (Session[Keys.SESSION_ADMIN_INFO] == null)
     {
         return(RedirectToAction("Login", "Admin"));
     }
     else
     {
         Master master = Session[Keys.SESSION_ADMIN_INFO] as Master;
         if (rcm.GetRoleCompetence(master.RoleId, 1452))
         {
             MasterRole mr = new MasterRole();
             mr = mm.GetMasterRole(R);
             ViewData["RoleId"]   = mr.RoleId;
             ViewData["RoleName"] = mr.RoleName;
             ViewData["Function"] = "UpdateData('/Master/UpdateMasterRole')";
             return(View());
         }
         else
         {
             return(RedirectToAction("Login", "Admin"));
         }
     }
 }
        // Code By Nitin
        public ActionResult Index()
        {
            List <Area> area_list = new List <Area>();
            //Add by lucky
            List <MasterRole>       RolesList = new List <MasterRole>();
            List <StateMasterModal> StateList = new List <StateMasterModal>();
            List <ZoneMastermodal>  ZoneList  = new List <ZoneMastermodal>();
            List <DropdownLit>      DropList  = new List <DropdownLit>();

            //End
            dict.Clear();
            //dict.Add("","");
            dict.Add("@mode", "getAll_Area");
            //DataTable dt = common_class.return_datatable(dict, "proc_Area");
            DataSet dt = common_class.return_dataset(dict, "proc_Area");
            int     j  = dt.Tables.Count;

            if (j > 0)
            {
                for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
                {
                    Area area = new Area();
                    area.id        = Convert.ToInt32(dt.Tables[0].Rows[i]["id"].ToString());
                    area.Area_Name = dt.Tables[0].Rows[i]["Area_name"].ToString();
                    area.Zone_id   = dt.Tables[0].Rows[i]["Zone"].ToString();
                    area.State_id  = dt.Tables[0].Rows[i]["State"].ToString();
                    area.pincode   = Convert.ToInt32(dt.Tables[0].Rows[i]["Pincode"].ToString());
                    area_list.Add(area);
                }
                //Add by lucky
                for (int k = 0; k < dt.Tables[1].Rows.Count; k++)
                {
                    MasterRole master = new MasterRole();
                    master.Id           = Convert.ToInt32(dt.Tables[1].Rows[k]["id"]);
                    master.RoleName     = dt.Tables[1].Rows[k]["Role"].ToString();
                    master.active       = Convert.ToInt32(dt.Tables[1].Rows[k]["Active"]).ToString() == "1" ? "Active" : "Deactive";
                    master.InsertedDate = dt.Tables[1].Rows[k]["inserted_on"].ToString();
                    RolesList.Add(master);
                }
                for (int l = 0; l < dt.Tables[2].Rows.Count; l++)
                {
                    StateMasterModal state = new StateMasterModal();
                    state.Id        = Convert.ToInt32(dt.Tables[2].Rows[l]["id"]);
                    state.StateName = dt.Tables[2].Rows[l]["state"].ToString();
                    state.Active    = Convert.ToInt32(dt.Tables[2].Rows[l]["Active"]).ToString() == "1" ? "Active" : "Deactive";
                    StateList.Add(state);
                }
                for (int m = 0; m < dt.Tables[3].Rows.Count; m++)
                {
                    ZoneMastermodal zone = new ZoneMastermodal();
                    zone.Id        = Convert.ToInt32(dt.Tables[3].Rows[m]["id"]);
                    zone.StateId   = Convert.ToInt32(dt.Tables[3].Rows[m]["State_id"]);
                    zone.ZoneName  = dt.Tables[3].Rows[m]["Zone"].ToString();
                    zone.StateName = dt.Tables[3].Rows[m]["state"].ToString();
                    zone.Active    = Convert.ToInt32(dt.Tables[3].Rows[m]["active"]).ToString() == "1" ? "Active" : "Deactive";
                    ZoneList.Add(zone);
                }
                for (int n = 0; n < dt.Tables[4].Rows.Count; n++)
                {
                    DropdownLit DDLState = new DropdownLit();
                    DDLState.Id       = Convert.ToInt32(dt.Tables[4].Rows[n]["id"]);
                    DDLState.DropName = dt.Tables[4].Rows[n]["state"].ToString();
                    DropList.Add(DDLState);
                }
                ViewBag.DropListState = DropList;
                ViewBag.GetZoneList   = ZoneList;
                ViewBag.GetRoleList   = RolesList;
                ViewBag.GetStateList  = StateList;
                //End

                ViewBag.list_Area = area_list;
            }
            return(View(area_list));
        }
Exemplo n.º 22
0
 public void Delete(MasterRole data)
 {
     _roleRepository.Delete(data);
     _roleRepository.Commit();
 }
Exemplo n.º 23
0
        public static string OnSubmit(string roleid, string dlbox, string desc, string stats)
        {
            string json;
            var    ReturnObj = new { status = "", result = "" };

            try
            {
                MasterRole roleObj = new MasterRole();
                roleObj.RoleID      = Convert.ToInt32(roleid);
                roleObj.RoleName    = new UsersRoleDAL().GetRoles().Where(x => x.RoleID == Convert.ToInt32(roleid)).Select(y => y.RoleName).FirstOrDefault();
                roleObj.Description = desc.Trim();
                roleObj.RoleStatus  = new Helper().GetItemStatusEnumValueByName(stats.Trim());

                List <string> RolesUname = Roles.GetUsersInRole(roleObj.RoleName).ToList();

                string[]      usersSelected = dlbox.Split(',');
                List <string> SelectedUname = new List <string>();

                if (usersSelected.Count() == 0 || dlbox == "null")
                {
                    SelectedUname = new List <string>();
                }
                else
                {
                    for (int u = 0; u < usersSelected.Count(); u++)
                    {
                        SelectedUname.Add(new UsersDAL().GetUserDataByID(Convert.ToInt32(usersSelected[u])).UserName);
                    }
                }

                if (SelectedUname.Count() > RolesUname.Count())
                {
                    List <string> OnlyInSelectedList = SelectedUname.Except(RolesUname).ToList();
                    foreach (string username in OnlyInSelectedList)
                    {
                        string[] getRoles = Roles.GetRolesForUser(username);
                        if (getRoles.Count() > 0)
                        {
                            Roles.RemoveUserFromRoles(username, getRoles);
                            if (!new UsersRoleDAL().DeleteUserRole(username, getRoles))
                            {
                                throw new Exception("Fail to authenticated selected users-list. Please re-enter your values and try again.");
                            }
                        }
                        Roles.AddUserToRole(username, roleObj.RoleName);

                        //add to local db
                        JuncUserRole userrole = new JuncUserRole();
                        userrole.RoleID = Convert.ToInt32(roleid);
                        userrole.UserID = DAL.UsersDAL.StaticUserId(0, username).UserID;
                        userrole.Status = new Helper().GetItemStatusEnumValueByName(stats.Trim());
                        if (!new UsersRoleDAL().InsertUserRole(userrole))
                        {
                            throw new Exception("Fail to authenticated selected users-list. Please re-enter your values and try again.");
                        }
                    }

                    //Update MasterRole
                    if (new UsersRoleDAL().UpdateMasterRole(roleObj))
                    {
                        ReturnObj = new { status = "Success", result = "User successfully added to roles." };
                    }
                    else
                    {
                        throw new Exception("Fail to authenticated selected users-list & role. Please re-enter your values and try again.");
                    }
                }
                else
                {
                    if (SelectedUname.Count() == RolesUname.Count())
                    {
                        //double check
                        List <string> OnlyInSelectedList = SelectedUname.Except(RolesUname).ToList();
                        foreach (string username in OnlyInSelectedList)
                        {
                            string[] getRoles = Roles.GetRolesForUser(username);
                            if (getRoles.Count() > 0)
                            {
                                Roles.RemoveUserFromRoles(username, getRoles);
                                if (!new UsersRoleDAL().DeleteUserRole(username, getRoles))
                                {
                                    throw new Exception("Fail to authenticated selected users-list. Please re-enter your values and try again.");
                                }
                            }
                            Roles.AddUserToRole(username, roleObj.RoleName);

                            //add to local db
                            JuncUserRole userrole = new JuncUserRole();
                            userrole.RoleID = Convert.ToInt32(roleid);
                            userrole.UserID = DAL.UsersDAL.StaticUserId(0, username).UserID;
                            userrole.Status = new Helper().GetItemStatusEnumValueByName(stats.Trim());
                            if (!new UsersRoleDAL().InsertUserRole(userrole))
                            {
                                throw new Exception("Fail to authenticated selected users-list. Please re-enter your values and try again.");
                            }
                        }

                        List <string> UnusedUserList = RolesUname.Except(SelectedUname).ToList();
                        foreach (string username in UnusedUserList)
                        {
                            string[] getRoles = Roles.GetRolesForUser(username);
                            if (getRoles.Count() > 0)
                            {
                                Roles.RemoveUserFromRoles(username, getRoles);
                                if (!new UsersRoleDAL().DeleteUserRole(username, getRoles))
                                {
                                    throw new Exception("Fail to authenticated selected users-list. Please re-enter your values and try again.");
                                }
                            }
                        }
                    }
                    else
                    {
                        List <string> UnusedUserList = RolesUname.Except(SelectedUname).ToList();
                        foreach (string username in UnusedUserList)
                        {
                            string[] getRoles = Roles.GetRolesForUser(username);
                            if (getRoles.Count() > 0)
                            {
                                Roles.RemoveUserFromRoles(username, getRoles);
                                if (!new UsersRoleDAL().DeleteUserRole(username, getRoles))
                                {
                                    throw new Exception("Fail to authenticated selected users-list. Please re-enter your values and try again.");
                                }
                            }
                        }
                    }

                    //Update MasterRole
                    if (new UsersRoleDAL().UpdateMasterRole(roleObj))
                    {
                        ReturnObj = new { status = "Success", result = "User successfully added to roles." };
                    }
                    else
                    {
                        throw new Exception("Fail to authenticated selected users-list & role. Please re-enter your values and try again.");
                    }
                }
            }
            catch (Exception ex)
            {
                ReturnObj = new { status = "Fail", result = "An error occurred. Error Message: " + ex.Message };
            }

            return(json = JsonConvert.SerializeObject(ReturnObj, Formatting.Indented));
        }