public IActionResult Share([FromBody] object value) { //check quyền trước khi share? Chỉ admin + owner mới được quyền share bool has_share_permission = (is_sys_admin || is_app_admin); DataResponse res = new DataResponse() { msg = "Không có quyền chia sẻ thông tin", success = false }; try { var obj = JToken.Parse(value.ToString()); if (obj != null) { List <string> users = obj["user"].ToObject <List <string> >(); List <string> lst_id_nha_tuyen_dung = new List <string>(); if (obj["id_nha_tuyen_dung"] != null) { string id_nha_tuyen_dung = obj["id_nha_tuyen_dung"].ToString(); try { lst_id_nha_tuyen_dung = id_nha_tuyen_dung.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(); } catch (Exception) { } } string id = obj["id"].ToString(); int type = obj["type"].ToObject <int>(); int rule = obj["rule"].ToObject <int>(); int obj_type = obj["obj_type"].ToObject <int>(); long ngay_het = 0; List <Quyen> quyen = new List <Quyen>(); List <int> teams = new List <int>(); if (obj["ngay_het"] != null) { try { ngay_het = XMedia.XUtil.TimeInEpoch(Convert.ToDateTime(ngay_het, dtfi)); } catch (Exception) { ngay_het = XMedia.XUtil.TimeInEpoch(DateTime.Now.AddYears(10)); } } if (obj["quyen"] != null) { quyen = obj["quyen"].ToObject <List <Quyen> >(); } if (!(is_sys_admin || is_app_admin)) { var obj_type_check = (PhanQuyenObjType)obj_type; switch (obj_type_check) { case PhanQuyenObjType.CONG_TY: has_share_permission = CongTyBL.IsOwner(id, user); break; case PhanQuyenObjType.USER_JOB: has_share_permission = UserJobBL.IsOwner(id, user); break; case PhanQuyenObjType.NOTE_UNG_VIEN: has_share_permission = NoteUngVienBL.IsOwner(id, user); break; case PhanQuyenObjType.UNG_VIEN: has_share_permission = UngVienBL.IsOwner(id, user); break; case PhanQuyenObjType.JOB: has_share_permission = JobBL.IsOwner(id, user); break; case PhanQuyenObjType.NOTE_UNG_VIEN_JOB: has_share_permission = NoteUngVienJobBL.IsOwner(id, user); break; case PhanQuyenObjType.MENU: has_share_permission = MenuBL.IsOwner(id, user); break; } } if (!has_share_permission) { return(Ok(res)); } if (obj["teams"] != null) { try { teams = obj["teams"].ToObject <List <int> >(); } catch { teams = new List <int>(); } } #region Xóa shared của các đối tượng cũ try { List <string> lst_id_phan_quyen_can_xoa = new List <string>(); var menu_shared = QLCUNL.BL.PhanQuyenBL.Get(string.Empty, PhanQuyenRule.ALL, PhanQuyenType.ALL, string.Empty, PhanQuyenObjType.ALL, id, quyen, 0, 0, ((is_sys_admin || is_app_admin) ? string.Empty : user), 0, 0, string.Empty, 0, 0, 1, 9999, out _); foreach (var item_shared in menu_shared) { if (item_shared.type == PhanQuyenType.GROUP_USERS) { int id_team_shared = -1; if (Int32.TryParse(item_shared.user, out id_team_shared)) { if (!teams.Contains(id_team_shared)) { lst_id_phan_quyen_can_xoa.Add(item_shared.id); } else { if (item_shared.ngay_het == ngay_het && item_shared.quyen.All(quyen.Contains) && quyen.All(item_shared.quyen.Contains)) { teams.Remove(id_team_shared); } } } } else { if (item_shared.type == PhanQuyenType.USERS) { if (!users.Contains(item_shared.user) && !lst_id_nha_tuyen_dung.Contains(item_shared.user)) { lst_id_phan_quyen_can_xoa.Add(item_shared.id); } else { if (item_shared.ngay_het == ngay_het && item_shared.quyen.All(quyen.Contains) && quyen.All(item_shared.quyen.Contains)) { users.Remove(item_shared.user); } } } } } PhanQuyenBL.RemoveByListId(lst_id_phan_quyen_can_xoa); } catch (Exception) { } #endregion #region Shared cho các đối tượng được chọn try { if (users.Count == 0 && teams.Count == 0 && lst_id_nha_tuyen_dung.Count == 0) { res.success = true; res.msg = "Không có thay đổi nào được thực hiện"; } else { foreach (var user in users) { PhanQuyen pq = new PhanQuyen(); pq.ngay_het = ngay_het; pq.user = user; pq.type = PhanQuyenType.USERS; pq.rule = (PhanQuyenRule)rule; pq.quyen = quyen; pq.obj_type = (PhanQuyenObjType)obj_type; pq.nguoi_tao = this.user; pq.obj_id = id; res.success = QLCUNL.BL.PhanQuyenBL.Index(pq); } foreach (var user in lst_id_nha_tuyen_dung) { PhanQuyen pq = new PhanQuyen(); pq.ngay_het = ngay_het; pq.user = user; pq.type = PhanQuyenType.USERS; pq.rule = (PhanQuyenRule)rule; pq.quyen = quyen; pq.obj_type = (PhanQuyenObjType)obj_type; pq.nguoi_tao = this.user; pq.obj_id = id; res.success = QLCUNL.BL.PhanQuyenBL.Index(pq); } if (teams.Count > 0) { foreach (var id_team in teams) { PhanQuyen pq = new PhanQuyen(); pq.ngay_het = ngay_het; pq.user = id_team.ToString(); pq.type = PhanQuyenType.GROUP_USERS; pq.rule = (PhanQuyenRule)rule; pq.quyen = quyen; pq.nguoi_tao = user; pq.obj_type = (PhanQuyenObjType)obj_type; pq.obj_id = id; res.success = QLCUNL.BL.PhanQuyenBL.Index(pq); } } } } catch (Exception) { } #endregion } } catch (Exception ex) { res.msg = ex.Message; res.success = false; } return(Ok(res)); }