public async Task <VehicleAnnounceForUserDto> UpdateForPublicAsync(VehicleAnnounceForCreationDto updateDto, int userId)
        {
            var claimId = int.Parse(httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value);

            if (claimId != userId)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.OperationDenied });
            }
            var checkFromRepo = await vehicleAnnounceDal.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 = "Car";
            mapForUpdate.IsNew        = true;
            mapForUpdate.IsPublish    = false;
            mapForUpdate.Reject       = false;
            await vehicleAnnounceDal.Update(mapForUpdate);

            var spec        = new VehicleAnnounceByUserIdSpecification(userId, checkFromRepo.Id);
            var getWithUser = await vehicleAnnounceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <VehicleAnnounce, VehicleAnnounceForUserDto>(getWithUser));
        }
        public async Task <ActionResult <VehicleAnnounceForReturnDto> > Publish(VehicleAnnounceForCreationDto creationDto)
        {
            var vehicleAnnounce = await vehicleAnnounceService.Publish(creationDto);

            var screenConnectionId = await onlineScreenService.GetAllOnlineScreenConnectionId();

            if (screenConnectionId != null && screenConnectionId.Length != 0)
            {
                await kiosksHub.Clients.Clients(screenConnectionId).SendAsync("ReloadScreen", true);
            }

            return(vehicleAnnounce);
        }
        public async Task <ActionResult <VehicleAnnounceForReturnDto> > Create(VehicleAnnounceForCreationDto creationDto)
        {
            var vehicleAnnounce = await vehicleAnnounceService.Create(creationDto);

            var connIds = await userTracker.GetOnlineUser();

            if (connIds != null && connIds.Length != 0)
            {
                await hubContext.Clients.GroupExcept("Car", connIds).SendAsync("ReceiveNewVehicleannounce", vehicleAnnounce, true);
            }

            return(vehicleAnnounce);
        }
        public async Task <VehicleAnnounceForReturnDto> Update(VehicleAnnounceForCreationDto updateDto)
        {
            var checkFromRepo = await vehicleAnnounceDal.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 = "Car";
            await vehicleAnnounceDal.Update(mapForUpdate);

            var spec        = new VehicleAnnounceWithPagingSpecification(checkFromRepo.Id);
            var getWithUser = await vehicleAnnounceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <VehicleAnnounce, VehicleAnnounceForReturnDto>(getWithUser));
        }
        public async Task <ActionResult <VehicleAnnounceForReturnDto> > Update(VehicleAnnounceForCreationDto creationDto)
        {
            var vehicleAnnounce = await vehicleAnnounceService.Update(creationDto);

            var connIds = await userTracker.GetOnlineUser();

            if (connIds != null && connIds.Length != 0)
            {
                await hubContext.Clients.GroupExcept("Car", connIds).SendAsync("ReceiveUpdateVehicleannounce", vehicleAnnounce);
            }

            var screenConnectionId = await onlineScreenService.GetAllOnlineScreenConnectionId();

            if (screenConnectionId != null && screenConnectionId.Length != 0)
            {
                await kiosksHub.Clients.Clients(screenConnectionId).SendAsync("ReloadScreen", true);
            }

            return(vehicleAnnounce);
        }
        public async Task <VehicleAnnounceForReturnDto> Create(VehicleAnnounceForCreationDto creationDto)
        {
            var checkByNameFromRepo = await vehicleAnnounceDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower());

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

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

            mapForCreate.SlideId      = slideId;
            mapForCreate.Created      = DateTime.Now;
            mapForCreate.AnnounceType = "Car";

            var createHomeAnnounce = await vehicleAnnounceDal.Add(mapForCreate);

            var spec             = new VehicleAnnounceWithPagingSpecification(createHomeAnnounce.Id);
            var vehicleAnnounces = await vehicleAnnounceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <VehicleAnnounce, VehicleAnnounceForReturnDto>(vehicleAnnounces));
        }
        public async Task <VehicleAnnounceForUserDto> CreateForPublicAsync(VehicleAnnounceForCreationDto creationDto, int userId)
        {
            var claimId = int.Parse(httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value);

            if (claimId != userId)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.OperationDenied });
            }
            var checkByNameFromRepo = await vehicleAnnounceDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower());

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

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

            mapForCreate.UserId            = claimId;
            mapForCreate.IsNew             = true;
            mapForCreate.IsPublish         = false;
            mapForCreate.Reject            = false;
            mapForCreate.SlideIntervalTime = 8;
            mapForCreate.PublishFinishDate = DateTime.Now;
            mapForCreate.PublishStartDate  = DateTime.Now;
            mapForCreate.SlideId           = slideId;
            mapForCreate.Created           = DateTime.Now;
            mapForCreate.AnnounceType      = "Car";

            var createHomeAnnounce = await vehicleAnnounceDal.Add(mapForCreate);

            var spec = new VehicleAnnounceByUserIdSpecification(userId, createHomeAnnounce.Id);

            var getAnnounceFromRepo = await vehicleAnnounceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <VehicleAnnounce, VehicleAnnounceForUserDto>(getAnnounceFromRepo));
        }
        public async Task <VehicleAnnounceForReturnDto> Publish(VehicleAnnounceForCreationDto updateDto)
        {
            var checkFromRepo = await vehicleAnnounceDal.GetAsync(x => x.Id == updateDto.Id);

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

            var checkAnnounceSubScreenForPublish = await vehicleAnnounceSubScreenDal.GetListAsync(x => x.VehicleAnnounceId == updateDto.Id);

            if (checkAnnounceSubScreenForPublish.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 = "Car";
            var updateToDb = await vehicleAnnounceDal.Update(mapForUpdate);

            var spec            = new VehicleAnnounceWithPagingSpecification(updateDto.Id);
            var vehicleAnnounce = await vehicleAnnounceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <VehicleAnnounce, VehicleAnnounceForReturnDto>(vehicleAnnounce));
        }