public HttpResponseMessage GetFormPermissionMenuRole([FromBody] Models.role role) { try { var controlList = controlRepository.GetAllControlForPermission(); var userPermissionList = userPermissionRepository.GetAllUserPermissionByRoleId(role.role_id); List <UserPermissionModel> models = new List <UserPermissionModel>(); if (role.role_id == null) { foreach (control con in controlList) { UserPermissionModel tempUserPermission = new UserPermissionModel(); tempUserPermission.control_id = con.control_id; tempUserPermission.control_name = con.control_name; tempUserPermission.control_type_id = con.control_type_id; tempUserPermission.control_parent_id = con.control_parent_id; tempUserPermission.control_controller = con.control_controller; tempUserPermission.control_action = con.control_action; tempUserPermission.control_status = false; tempUserPermission.icon = con.icon; tempUserPermission.control_alias = con.control_alias; models.Add(tempUserPermission); } } else { foreach (control con in controlList) { UserPermissionModel tempUserPermission = new UserPermissionModel(); tempUserPermission.control_id = con.control_id; tempUserPermission.control_name = con.control_name; tempUserPermission.control_type_id = con.control_type_id; tempUserPermission.control_parent_id = con.control_parent_id; tempUserPermission.control_controller = con.control_controller; tempUserPermission.control_action = con.control_action; tempUserPermission.icon = con.icon; tempUserPermission.control_alias = con.control_alias; foreach (user_permission usp in userPermissionList) { if (usp.user_control_id == con.control_id) { tempUserPermission.control_status = true; } } models.Add(tempUserPermission); } } var format_type = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, models, format_type)); } catch (Exception ex) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = ex.ToString() }, formatter)); } }
public HttpResponseMessage Post([FromBody] Models.StronglyType.UserPermissionModel userPermissionModel) { try { bool insertuserPermission = false; if (userPermissionModel.user_role_id == null && userPermissionModel.user_au_id == null) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Role is Empty Or User is Empty.Please select a role or user" }, formatter)); } else { if (userPermissionModel.user_au_id != null) { long userid = long.Parse(userPermissionModel.user_au_id.ToString()); var uPermissionList = userPermissionRepository.GetAllUserPermissionByUserId(userid); if (uPermissionList.Count > 1) { userPermissionRepository.DeleteUserPermissionByUser(userid, uPermissionList); } } if (userPermissionModel.user_role_id != null) { long roleid = long.Parse(userPermissionModel.user_role_id.ToString()); var permissionList = userPermissionRepository.GetAllUserPermissionByRoleId(roleid); if (permissionList.Count > 1) { userPermissionRepository.DeleteUserPermissionByRole(roleid, permissionList); } } foreach (string per in userPermissionModel.permissions) { decimal cont_id = Convert.ToDecimal(per); Models.user_permission insert_userPermission = new user_permission { user_au_id = userPermissionModel.user_au_id, user_control_id = long.Parse(per), user_role_id = userPermissionModel.user_role_id, }; insertuserPermission = userPermissionRepository.InsertUserPermission(insert_userPermission); } if (insertuserPermission == true) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "success", msg = "User Permission is saved Successfully" }, formatter)); } else { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Some thing Wrong with user permission entry" }, formatter)); } } } catch (Exception ex) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Some thing Wrong with user permission entry" }, formatter)); } }