public async Task <NewsForKiosksToReturnDto> GetNewsById(int newsId) { var spec = new NewsWithUserSpecification(newsId); var news = await newsDal.GetEntityWithSpecAsync(spec); return(mapper.Map <News, NewsForKiosksToReturnDto>(news)); }
public async Task <NewsForReturnDto> Create(NewsForCreationDto creationDto) { var checkByNameFromRepo = await newsDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower()); if (checkByNameFromRepo != null) { throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist }); } var claimId = int.Parse(httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value); var mapForCreate = mapper.Map <News>(creationDto); var slideId = Guid.NewGuid(); mapForCreate.SlideId = slideId; mapForCreate.UserId = claimId; mapForCreate.Created = DateTime.Now; mapForCreate.AnnounceType = "news"; var createNews = await newsDal.Add(mapForCreate); var spec = new NewsWithUserSpecification(createNews.Id); var getNewsFromRepo = await newsDal.GetEntityWithSpecAsync(spec); return(mapper.Map <News, NewsForReturnDto>(getNewsFromRepo)); }
public async Task <NewsForReturnDto> Update(NewsForCreationDto updateDto) { var checkFromRepo = await newsDal.GetAsync(x => x.Id == updateDto.Id); if (checkFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound }); } var mapForUpdate = mapper.Map(updateDto, checkFromRepo); mapForUpdate.Updated = DateTime.Now; mapForUpdate.AnnounceType = "news"; await newsDal.Update(mapForUpdate); var spec = new NewsWithUserSpecification(updateDto.Id); var getAnnounceWithUserFromRepo = await newsDal.GetEntityWithSpecAsync(spec); return(mapper.Map <News, NewsForReturnDto>(getAnnounceWithUserFromRepo)); }
public async Task <NewsForReturnDto> Publish(NewsForCreationDto updateDto) { var checkFromRepo = await newsDal.GetAsync(x => x.Id == updateDto.Id); if (checkFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound }); } var checkHomeNewsSubScreenForPublish = await newsSubScreenDal.GetListAsync(x => x.NewsId == updateDto.Id); if (checkHomeNewsSubScreenForPublish.Count <= 0) { throw new RestException(HttpStatusCode.BadRequest, new { NotSelectSubScreen = Messages.NotSelectSubScreen }); } if (updateDto.IsPublish) { var checkDateExpire = DateTime.Compare(DateTime.Now, checkFromRepo.PublishFinishDate); if (checkDateExpire > 0) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.PublishDateExpire }); } } var mapForUpdate = mapper.Map(updateDto, checkFromRepo); mapForUpdate.Updated = DateTime.Now; mapForUpdate.AnnounceType = "news"; await newsDal.Update(mapForUpdate); var spec = new NewsWithUserSpecification(updateDto.Id); var getAnnounceWithUserFromRepo = await newsDal.GetEntityWithSpecAsync(spec); return(mapper.Map <News, NewsForReturnDto>(getAnnounceWithUserFromRepo)); }