public static async Task <bool> UpdateCard(string accessToken, int cardId, UpdateCardDTO updateCardDTO) { using (HttpClient client = new HttpClient()) { try { string json = JsonConvert.SerializeObject(updateCardDTO); 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/Card/" + cardId, 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 id, [FromBody] UpdateCardDTO value) { if (value != null) { return(cs.UpdateCard(id, User.Identity.Name, value)); } return(false); }
public bool UpdateCard(int cardId, string username, UpdateCardDTO dto) { bool succ = false; using (UnitOfWork uw = new UnitOfWork()) { Card card = uw.CardRepository.GetById(cardId); User user = uw.UserRepository.GetUserByUsername(username); if (card != null && user != null) { card.Name = dto.Name; card.Description = dto.Description; card.DueDate = dto.DueDate; uw.CardRepository.Update(card); NotificationService notif = new NotificationService(); notif.CreateChangeNotification(new CreateNotificationDTO() { CardId = card.CardId, UserId = user.UserId, NotificationType = NotificationType.Change }); succ = uw.Save(); if (succ) { BasicCardDTO cardDto = new BasicCardDTO(card); RabbitMQService.PublishToExchange(card.List.Board.ExchangeName, new MessageContext(new CardMessageStrategy(cardDto, MessageType.Update, username))); BoardNotificationService.ChangeBoardNotifications(card.List.Board.BoardId); } } } return(succ); }