public async Task <ActionResult <CardViewDTO> > UpdateContent([FromBody] CardContentDTO card) { Guid userId = GetUserId(); var updateResult = await _cardsService.UpdateContent(card, userId); return(Ok(updateResult)); }
public async Task <CardViewDTO> UpdateContent(CardContentDTO updatedCard, Guid userId) { var validationResult = _cardContentValidator.Validate(updatedCard); if (!validationResult.IsValid) { throw new Exception(validationResult.ToString()); } else { Card card = await _cardRepository.GetOne(updatedCard.Id); Column column = await _columnRepository.GetOne(card.ColumnId); var oldCard = await _cardRepository.GetOne(updatedCard.Id); card.UpdatedDate = DateTime.Now; if (oldCard.Text == null && updatedCard.Text != null) { card.Text = updatedCard.Text; var historyObject = await _historyService.CreateHistoryObject( UserActions.AddedDescription, userId, card.Title, null, null, column.BoardId ); } if (oldCard.Text != null && updatedCard.Text != oldCard.Text) { card.Text = updatedCard.Text; var historyObject = await _historyService.CreateHistoryObject( UserActions.EditedDescription, userId, card.Title, null, null, column.BoardId ); } if (oldCard.ExecutionPeriod != updatedCard.ExecutionPeriod) { card.ExecutionPeriod = updatedCard.ExecutionPeriod; var historyObject = await _historyService.CreateHistoryObject( UserActions.ChangeExecutionPeriod, userId, card.Title, null, null, column.BoardId ); } var result = await _cardRepository.Update(card); var mapperResult = _mapper.Map <Card, CardViewDTO>(result); return(mapperResult); } }