public async Task <ActionResult> SetMenu(string groupId, string menuId) { try { if (!(await _serviceGroupTest.GetByIDAsync(groupId) is GroupTest memberGroup)) { return(BadRequest("Nhóm quyền không tồn tại hoặc đã bị thay đổi.")); } if (!(await _serviceMenuTest.GetByIDAsync(menuId) is MenuTest menuTest)) { return(BadRequest("Mã menu không tồn tại hoặc đã bị thay đổi.")); } List <string> permission; if (memberGroup.ArrMenuId != null && memberGroup.ArrMenuId.Length > 0) { permission = new List <string>(memberGroup.ArrMenuId); } else { permission = new List <string>(); } if (permission == null || permission.Count == 0) { permission.Add(menuId); } else { //nếu có thì xóa if (permission.Contains(menuId)) { permission.Remove(menuId); } //nếu chưa có thì thêm vào else { permission.Add(menuId); } } memberGroup.ArrMenuId = permission.Distinct().ToArray(); //lưu DB var updateResult = await _serviceGroupTest.UpdateAsync(memberGroup.Id, memberGroup); if (updateResult.IsAcknowledged) { return(Ok()); } else { return(BadRequest("Gán menu thất bại")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> GetDetails(string id) { try { var result = await _service.GetByIDAsync(id); if (result is not null) { return(Ok(result)); } return(NotFound()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <UserTest> Get(string id) { UserTest user = await _serviceUserTest.GetByIDAsync(id).ConfigureAwait(false); if (user != null) { user.Password = String.Empty; } return(user); }
public async Task <Book> GetDetails(string id) { Book book = await _serviceBook.GetByIDAsync(id); return(book); }
public async Task <Category> GetDetails(string id) { Category category = await _serviceCategory.GetByIDAsync(id); return(category); }
public async Task <GroupTest> GetDetails(string id) { GroupTest GroupTest = await _serviceGroupTest.GetByIDAsync(id); return(GroupTest); }
public async Task <SystemFunctionTest> GetDetails(string id) { SystemFunctionTest _data = await _serviceSysFuctionTest.GetByIDAsync(id); return(_data); }
public async Task <CustomerTest> GetDetails(string id) { CustomerTest _data = await _serviceCustomerTest.GetByIDAsync(id); return(_data); }
public async Task <MenuTest> GetDetails(string id) { MenuTest data = await _serviceMenuTest.GetByIDAsync(id); return(data); }