Esempio n. 1
0
        public async Task <NewsForKiosksToReturnDto> GetNewsById(int newsId)
        {
            var spec = new NewsWithUserSpecification(newsId);
            var news = await newsDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <News, NewsForKiosksToReturnDto>(news));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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));
        }