Beispiel #1
0
        public async Task <AnnounceForUserDto> UpdateForPublicAsync(AnnounceForCreationDto 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 announceDal.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 = "announce";
            mapForUpdate.IsNew        = true;
            mapForUpdate.IsPublish    = false;
            mapForUpdate.Reject       = false;
            await announceDal.Update(mapForUpdate);

            var spec = new AnnounceByUserIdSpecification(userId, checkFromRepo.Id);
            var getAnnounceWithUserFromRepo = await announceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <Announce, AnnounceForUserDto>(getAnnounceWithUserFromRepo));
        }
Beispiel #2
0
        public async Task <AnnounceForReturnDto> Create(AnnounceForCreationDto creationDto)
        {
            var claimId = int.Parse(httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value);

            var checkByNameFromRepo = await announceDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower());

            if (checkByNameFromRepo != null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist });
            }
            var mapForCreate = mapper.Map <Announce>(creationDto);
            var slideId      = Guid.NewGuid();

            mapForCreate.SlideId = slideId;
            if (creationDto.UserId > 0)
            {
                mapForCreate.UserId = creationDto.UserId;
            }
            else
            {
                mapForCreate.UserId = claimId;
            }
            mapForCreate.Created      = DateTime.Now;
            mapForCreate.AnnounceType = "announce";

            var createAnnounce = await announceDal.Add(mapForCreate);

            var spec = new AnnounceWithUserSpecification(createAnnounce.Id);

            var getAnnounceFromRepo = await announceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <Announce, AnnounceForReturnDto>(getAnnounceFromRepo));
        }
        public async Task <ActionResult <AnnounceForUserDto> > CreateForPublic([FromBody] AnnounceForCreationDto creationDto, int userId)
        {
            var announce = await announceService.CreateForPublicAsync(creationDto, userId);

            var connIds = await userTracker.GetOnlineUser();

            if (connIds != null && connIds.Length != 0)
            {
                await hubContext.Clients.GroupExcept("Announce", connIds).SendAsync("ReceiveNewAnnounce", announce, true);
            }
            return(announce);
        }
        public async Task <ActionResult <AnnounceForReturnDto> > Publish(AnnounceForCreationDto updateDto)
        {
            var announce = await announceService.Publish(updateDto);

            var screenConnectionId = await onlineScreenService.GetAllOnlineScreenConnectionId();

            if (screenConnectionId != null && screenConnectionId.Length != 0)
            {
                await kiosksHub.Clients.Clients(screenConnectionId).SendAsync("ReloadScreen", true);
            }
            return(announce);
        }
Beispiel #5
0
        public async Task <AnnounceForReturnDto> Update(AnnounceForCreationDto updateDto)
        {
            var checkFromRepo = await announceDal.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 = "announce";
            await announceDal.Update(mapForUpdate);

            var spec = new AnnounceWithUserSpecification(updateDto.Id);
            var getAnnounceWithUserFromRepo = await announceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <Announce, AnnounceForReturnDto>(getAnnounceWithUserFromRepo));
        }
        public async Task <ActionResult <AnnounceForReturnDto> > Update(AnnounceForCreationDto updateDto)
        {
            var announce = await announceService.Update(updateDto);

            var connIds = await userTracker.GetOnlineUser();

            if (connIds != null && connIds.Length != 0)
            {
                await hubContext.Clients.GroupExcept("Announce", connIds).SendAsync("ReceiveUpdateAnnounce", announce);
            }

            var onlineScreens = await onlineScreenService.GetAllOnlineScreenConnectionId();

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

            return(announce);
        }
Beispiel #7
0
        public async Task <AnnounceForUserDto> CreateForPublicAsync(AnnounceForCreationDto 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 announceDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower());

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

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

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

            var createAnnounce = await announceDal.Add(mapForCreate);

            var spec = new AnnounceByUserIdSpecification(userId, createAnnounce.Id);

            var getAnnounceFromRepo = await announceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <Announce, AnnounceForUserDto>(getAnnounceFromRepo));
        }
Beispiel #8
0
        public async Task <AnnounceForReturnDto> Publish(AnnounceForCreationDto updateDto)
        {
            var checkFromRepo = await announceDal.GetAsync(x => x.Id == updateDto.Id);

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

            var checkHomeAnnounceSubScreenForPublish = await announceSubScreenDal.GetListAsync(x => x.AnnounceId == 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.AnnounceType = "announce";
            await announceDal.Update(mapForUpdate);

            var spec = new AnnounceWithUserSpecification(updateDto.Id);
            var getAnnounceWithUserFromRepo = await announceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <Announce, AnnounceForReturnDto>(getAnnounceWithUserFromRepo));
        }