public async Task <LiveTvBroadCastForReturnDto> Create(LiveTvBroadCastForCreationDto creationDto)
        {
            var checkByNameFromRepo = await liveTvBrodcastDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower());

            if (checkByNameFromRepo != null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist });
            }

            var userId = (int)httpContextAccessor.HttpContext.User?.ClaimsId();

            var mapForCreate = mapper.Map <LiveTvBroadCast>(creationDto);
            var slideId      = Guid.NewGuid();

            mapForCreate.SlideId           = slideId;
            mapForCreate.UserId            = userId;
            mapForCreate.SlideIntervalTime = (int)TimeSpan.FromMinutes(mapForCreate.SlideIntervalTime).TotalSeconds;
            mapForCreate.Created           = DateTime.Now;
            mapForCreate.AnnounceType      = "livetv";

            var createAnnounce = await liveTvBrodcastDal.Add(mapForCreate);

            var spec = new LiveTvBroadCastWithUserSpecification(createAnnounce.Id);

            var getAnnounceFromRepo = await liveTvBrodcastDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <LiveTvBroadCast, LiveTvBroadCastForReturnDto>(getAnnounceFromRepo));
        }
        public async Task <LiveTvBroadCastForReturnDto> Update(LiveTvBroadCastForCreationDto updateDto)
        {
            var checkFromRepo = await liveTvBrodcastDal.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.SlideIntervalTime = (int)TimeSpan.FromMinutes(mapForUpdate.SlideIntervalTime).TotalSeconds;
            await liveTvBrodcastDal.Update(mapForUpdate);

            var spec = new LiveTvBroadCastWithUserSpecification(updateDto.Id);
            var getAnnounceWithUserFromRepo = await liveTvBrodcastDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <LiveTvBroadCast, LiveTvBroadCastForReturnDto>(getAnnounceWithUserFromRepo));
        }
        public async Task <LiveTvBroadCastForReturnDto> Publish(LiveTvBroadCastForCreationDto updateDto)
        {
            var checkFromRepo = await liveTvBrodcastDal.GetAsync(x => x.Id == updateDto.Id);

            if (checkFromRepo == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound });
            }

            var checkHomeAnnounceSubScreenForPublish = await liveTvBroadCastSubScreenDal.GetListAsync(x => x.LiveTvBroadCastId == updateDto.Id);

            if (checkHomeAnnounceSubScreenForPublish.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.SlideIntervalTime = (int)TimeSpan.FromMinutes(mapForUpdate.SlideIntervalTime).TotalSeconds;
            await liveTvBrodcastDal.Update(mapForUpdate);

            var spec = new LiveTvBroadCastWithUserSpecification(updateDto.Id);
            var getAnnounceWithUserFromRepo = await liveTvBrodcastDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <LiveTvBroadCast, LiveTvBroadCastForReturnDto>(getAnnounceWithUserFromRepo));
        }