Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 3
0
 public async Task <bool> UpdateTopic(TopicUpsertion topicUpsertion, string currentLoggedUser)
 {
     return(await _topicRepository.UpdateTopic(topicUpsertion, currentLoggedUser));
 }