public async Task <IActionResult> UpdateNews(string Id, UpdateNewsRequest request)
        {
            if (Id != request.Id)
            {
                return(BadRequest());
            }

            return(Ok(await _newsService.UpdateNewsRequest(request)));
        }
        /// <inheritdoc/>
        public async Task <NewsDto> UpdateNewsAsync(UpdateNewsRequest request)
        {
            var News = await _context.News.FirstOrDefaultAsync(x => x.IdNews == request.IdNews);

            _context.News.Update(News);
            await _context.SaveChangesAsync();

            return(News);
        }
Ejemplo n.º 3
0
        public async Task <UpdateNewsResponse> UpdateNews(UpdateNewsRequest requestModel)
        {
            var news = await FindById(requestModel.NewsId);

            news = UpdateNewsRequest.UpdateToNews(requestModel, news);

            news = await _repoWrapper.News.UpdateAsync(news, news.NewsId);

            return(UpdateNewsResponse.CreateFromNews(news));
        }
Ejemplo n.º 4
0
        public void UpdateValidate_Author_Tests(string id, string title, string content, bool result)
        {
            var author = new AuthorRequest {
                UserName = "******", Name = "Gilmar"
            };

            var authorReq = new UpdateNewsRequest {
                Id = Guid.Parse(id), Title = title, Content = content, Author = author
            };
            var validate = new UpdateNewsRequestValidator().Validate(authorReq);

            validate.IsValid.Should().Be(result);
        }
Ejemplo n.º 5
0
        public object Put(UpdateNewsRequest request)
        {
            var news = Db.SingleById <News>(request.Id);

            news.Throw404NotFoundIfNull("News not found");

            news.PopulateWith(request);
            news.UserAuthId = request.User.Id;

            Db.Update(news);

            return(Get(new GetNewsByIdRequest {
                Id = request.Id
            }));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <UpdateNewsResponse> > UpdateNews(UpdateNewsRequest request)
        {
            //Check Model State
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Check News Status
            if (!NewsStatus.IsNewsStatus(request.Status))
            {
                return(BadRequest("News status is not valid, must be: " + string.Join(", ", NewsStatus.NewsStatusList)));
            }

            //Call Service
            return(await _newsServices.UpdateNews(request));
        }
Ejemplo n.º 7
0
        public async Task <Response <string> > UpdateNewsRequest(UpdateNewsRequest request)
        {
            var news = await _unitOfWork.NewsRepository.FirstAsync(x => x.Id == request.Id && x.DelFlag == false);

            if (news == null)
            {
                return(new Response <string>(null, $"Không tìm thấy news id \'{request.Id}\'"));
            }

            news.Title               = request.Title;
            news.NewsContent         = request.NewsContent;
            news.ImageUrl            = request.ImageURL;
            news.EstimatedFinishTime = request.EstimatedFinishTime;
            news.LastModifiedBy      = request.LastModifiedBy;
            news.LastModifiedTime    = DateTimeOffset.Now.ToOffset(new TimeSpan(7, 0, 0)).DateTime;
            news.TypeId              = request.TypeId;

            _unitOfWork.NewsRepository.UpdateAsync(news);
            await _unitOfWork.SaveAsync();

            return(new Response <string>(news.Id, "Cập nhật news thành công"));
        }
Ejemplo n.º 8
0
 public async Task <Response <NewsResponse> > UpdateNews([FromRoute] Guid newsId, [FromBody] UpdateNewsRequest request)
 {
     return(await _newsService.UpdateNewsAsync(newsId, request));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Cập nhật tin tức, thêm xóa danh mục khỏi tin tức
        /// </summary>
        /// <param name="newsId"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <Response <NewsResponse> > UpdateNewsAsync(Guid newsId, UpdateNewsRequest request)
        {
            var news = await _newsContext.News.FindAsync(newsId);

            if (news == null)
            {
                _logger.LogError("Not find news with id");
                return(new Response <NewsResponse>(Constant.STATUS_ERROR, new List <string> {
                    "Not find news with id"
                }));
            }
            if (!string.IsNullOrEmpty(request.Title))
            {
                news.Title = request.Title;
            }

            if (!string.IsNullOrEmpty(request.Content))
            {
                news.Content = request.Content;
            }

            if (!string.IsNullOrEmpty(request.UrlImage))
            {
                news.UrlImage = request.UrlImage;
            }

            //thêm danh mục vào tin tức
            foreach (var categoryId in request.AddCategoryIds ?? new List <Guid> {
            })
            {
                var category = await _newsContext.Categories.FindAsync(categoryId);

                if (category != null)
                {
                    var categoryNews = _newsContext.CategoryNews.Where(x => x.CategoryId.Equals(category.Id) && x.NewsId.Equals(news.Id)).ToList();

                    if (categoryNews.Count() <= 0)
                    {
                        await _newsContext.CategoryNews.AddAsync(new CategoryNews
                        {
                            Id         = Guid.NewGuid(),
                            CategoryId = category.Id,
                            NewsId     = news.Id
                        });
                    }
                }
            }

            //xóa danh mục khỏi tin tức
            foreach (var categoryId in request.RemoveCategoryIds ?? new List <Guid> {
            })
            {
                var category = await _newsContext.Categories.FindAsync(categoryId);

                if (category != null)
                {
                    var categoryNews = _newsContext.CategoryNews.Where(x => x.CategoryId.Equals(categoryId));
                    if (categoryNews != null && categoryNews.Any())
                    {
                        _newsContext.CategoryNews.RemoveRange(categoryNews);
                    }
                }
            }

            var result = await _newsContext.SaveChangesAsync();

            var dataResponse = new NewsResponse
            {
                Id         = news.Id,
                Title      = news.Title,
                Content    = news.Content,
                CreateTime = news.CreateTime,
                UpdateTime = news.UpdateTime,
                Categories = await GetCategoryModels(news.Id),
                UrlImage   = news.UrlImage
            };

            if (result >= 0)
            {
                _logger.LogInformation("Update news sucess");
                return(new Response <NewsResponse>(Constant.STATUS_SUCESS, null, dataResponse, 1));
            }

            _logger.LogError("Update news failed");
            return(new Response <NewsResponse>(Constant.STATUS_ERROR, new List <string> {
                "Error when save"
            }));
        }
 public async Task <ServiceResponse <NewsDto> > UpdateNews(UpdateNewsRequest request)
 {
     return(await _executeService.TryExecute(() => _service.UpdateNewsAsync(request)));
 }
Ejemplo n.º 11
0
 public Task <DelMediaResponse> UpdateNewsAsync(UpdateNewsRequest request)
 {
     return(WeChatOfficialApiRequester.RequestAsync <DelMediaResponse>(UpdateNewsUrl,
                                                                       HttpMethod.Post,
                                                                       request));
 }