public async Task <bool> UpdateTopic(TopicUpsertion topicUpsertion, string currentLoggedUser) { try { var selectedTopic = _userDbContext.Topics.Where(x => x.Name == topicUpsertion.Name).Include(y => y.Cards).SingleOrDefault(); if (selectedTopic == null) { return(false); } selectedTopic.Name = topicUpsertion.Name; selectedTopic.Tag = topicUpsertion.Tag; if (selectedTopic.Cards == null) { selectedTopic.Cards = new List <DbCard>(); } foreach (Card card in topicUpsertion.Cards) { var currentCard = selectedTopic.Cards.Where(x => x.Index == card.Index).SingleOrDefault(); if (currentCard == null) { currentCard = new DbCard(); } currentCard.Content = card.Content; currentCard.Index = card.Index; } selectedTopic.Cards.RemoveAll(x => !topicUpsertion.Cards.Any(z => z.Index == x.Index)); await _userDbContext.SaveChangesAsync(); return(true); } catch (Exception ex) { return(false); } }
public async Task <IActionResult> UpdateTopic([FromBody] TopicUpsertion topicUpsertion) { try { var isAuthenticated = User.Identity.IsAuthenticated; if (isAuthenticated) { var currentLoggedUser = User.Identity.Name; return(Ok(await _topicServices.UpdateTopic(topicUpsertion, currentLoggedUser))); } else { return(BadRequest("Please Login!!")); } } catch (LoginException ex) { return(StatusCode(500, ex.Message)); } }
public async Task <bool> UpdateTopic(TopicUpsertion topicUpsertion, string currentLoggedUser) { return(await _topicRepository.UpdateTopic(topicUpsertion, currentLoggedUser)); }