public static async Task <bool> UpdateBoard(string accessToken, int boardId, UpdateBoardDTO updateBoardDTO) { using (HttpClient client = new HttpClient()) { try { string json = JsonConvert.SerializeObject(updateBoardDTO); var buffer = System.Text.Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); client.DefaultRequestHeaders.Add("Authorization", accessToken); var response = await client.PutAsync("http://localhost:52816/api/Board/" + boardId, byteContent); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var jsonString = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <bool>(jsonString); return(result); } else { return(false); } } catch (Exception e) { Debug.WriteLine(e.Message); return(false); } } }
public bool Put(int boardId, [FromBody] UpdateBoardDTO board) { if (board != null) { return(service.UpdateBoard(boardId, board, User.Identity.Name)); } return(false); }
private async void updateBoardButton_Click(object sender, EventArgs e) { string id = updateIdBoardTextbox.Text; string newName = updateNameBoardTextbox.Text; int UserId = int.Parse(userIdTextBox.Text); UpdateBoardDTO updateData = new UpdateBoardDTO() { Name = newName, BoardId = int.Parse(id) }; await BoardService.PutBoard(updateData, UserId); }
public static async Task PutBoard(UpdateBoardDTO updateData, int userId) { using (HttpClient client = new HttpClient()) { string json = JsonConvert.SerializeObject(updateData); var buffer = System.Text.Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PutAsync("http://localhost:52816/api/Board/" + userId, byteContent); } }
public bool UpdateBoard(int boardId, UpdateBoardDTO boardDTO, string username) { bool ret = false; using (UnitOfWork unit = new UnitOfWork()) { Board board = unit.BoardRepository.GetById(boardId); if (board != null) { board.Name = boardDTO.Name; unit.BoardRepository.Update(board); ret = unit.Save(); if (ret) { BoardNotificationService.ChangeBoardNotifications(board.BoardId); BasicBoardDTO dto = new BasicBoardDTO(board); RabbitMQService.PublishToExchange(board.ExchangeName, new MessageContext(new BoardMessageStrategy(dto, MessageType.Update, username))); List <User> users = unit.PermissionRepository.GetAllUsersWithPermissionOnBoard(board.BoardId); foreach (var u in users) { RabbitMQService.PublishToExchange(u.ExchangeName, new MessageContext(new BoardMessageStrategy(dto, MessageType.UserUpdate, username))); } } } } return(ret); }