public async Task <IListResponse <long> > DeleteByArticleId(long articleId)
        {
            ListResponse <long> response = new ListResponse <long>()
            {
                IsSuccess = false
            };

            try
            {
                var connections = _dbContext.ArticleTagConnections.Where(at => at.ArticleId == articleId);

                if (connections.Any())
                {
                    _dbContext.ArticleTagConnections.AttachRange(connections);
                    _dbContext.ArticleTagConnections.RemoveRange(connections);

                    await _dbContext.SaveChangesAsync();

                    response.Items     = connections.Select(at => at.Id);
                    response.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                response.Message = e.Message;
            }

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <ISingleResponse <Article> > CreateArticle(Article article)
        {
            SingleResponse <Article> response = new SingleResponse <Article>()
            {
                IsSuccess = false
            };

            try
            {
                _dbContext.Articles.Add(article);
                await _dbContext.SaveChangesAsync();

                response.IsSuccess = true;
                response.Item      = article;
            }
            catch (Exception e)
            {
                response.Message = e.Message;
            }

            return(response);
        }