public async Task <HomeAnnounceForUserDto> UpdateForPublicAsync(HomeAnnounceForCreationDto 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 checkFromRepo = await homeAnnounceDal.GetAsync(x => x.Id == creationDto.Id); if (checkFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound }); } var mapForUpdate = mapper.Map(creationDto, checkFromRepo); mapForUpdate.Updated = DateTime.Now; mapForUpdate.IsNew = true; mapForUpdate.AnnounceType = "home"; mapForUpdate.IsPublish = false; mapForUpdate.Reject = false; await homeAnnounceDal.Update(mapForUpdate); var spec = new HomeAnnounceByUserIdSpecification(userId, creationDto.Id); var getAnnounceWithUserFromRepo = await homeAnnounceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <HomeAnnounce, HomeAnnounceForUserDto>(getAnnounceWithUserFromRepo)); }
public async Task <ActionResult <HomeAnnounceForReturnDto> > Publish(HomeAnnounceForCreationDto updateDto) { var homeAnnounce = await homeAnnounceService.Publish(updateDto); var onlineScreensConnectionId = await onlineScreenService.GetAllOnlineScreenConnectionId(); if (onlineScreensConnectionId != null && onlineScreensConnectionId.Length != 0) { await kiosksHub.Clients.Clients(onlineScreensConnectionId).SendAsync("ReloadScreen", true); } return(homeAnnounce); }
public async Task <ActionResult <HomeAnnounceForReturnDto> > Create([FromBody] HomeAnnounceForCreationDto creationDto) { var homeAnnounce = await homeAnnounceService.Create(creationDto); var connIds = await userTracker.GetOnlineUser(); if (connIds != null && connIds.Length != 0) { await hubContext.Clients.GroupExcept("Home", connIds).SendAsync("ReceiveNewHomeAnnounce", homeAnnounce, true); } return(homeAnnounce); }
public async Task <ActionResult <HomeAnnounceForUserDto> > UpdateForPublic(HomeAnnounceForCreationDto updateDto, int userId) { var homeAnnounce = await homeAnnounceService.UpdateForPublicAsync(updateDto, userId); var connIds = await userTracker.GetOnlineUser(); if (connIds != null && connIds.Length != 0) { await hubContext.Clients.GroupExcept("Home", connIds).SendAsync("ReceiveUpdateHomeAnnounce", homeAnnounce, true); } return(homeAnnounce); }
public async Task <HomeAnnounceForReturnDto> Update(HomeAnnounceForCreationDto updateDto) { var checkFromRepo = await homeAnnounceDal.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 = "home"; await homeAnnounceDal.Update(mapForUpdate); var spec = new HomeAnnounceWithPhotoAndUserSpecification(updateDto.Id); var getAnnounceWithUserFromRepo = await homeAnnounceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <HomeAnnounce, HomeAnnounceForReturnDto>(getAnnounceWithUserFromRepo)); }
public async Task <ActionResult <HomeAnnounceForReturnDto> > Update(HomeAnnounceForCreationDto updateDto) { var homeAnnounce = await homeAnnounceService.Update(updateDto); var connIds = await userTracker.GetOnlineUser(); if (connIds != null && connIds.Length != 0) { await hubContext.Clients.GroupExcept("Home", connIds).SendAsync("ReceiveUpdateHomeAnnounce", homeAnnounce); } var onlineScreensConnectionId = await onlineScreenService.GetAllOnlineScreenConnectionId(); if (onlineScreensConnectionId != null && onlineScreensConnectionId.Length != 0) { await kiosksHub.Clients.Clients(onlineScreensConnectionId).SendAsync("ReloadScreen", true); } return(homeAnnounce); }
public async Task <HomeAnnounceForUserDto> CreateForPublicAsync(HomeAnnounceForCreationDto 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 homeAnnounceDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower()); if (checkByNameFromRepo != null) { throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist }); } var mapForCreate = mapper.Map <HomeAnnounce>(creationDto); var slideId = 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.AnnounceType = "home"; mapForCreate.SlideId = slideId; mapForCreate.Created = DateTime.Now; var createHomeAnnounce = await homeAnnounceDal.Add(mapForCreate); var spec = new HomeAnnounceByUserIdSpecification(userId, createHomeAnnounce.Id); var getAnnounceFromRepo = await homeAnnounceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <HomeAnnounce, HomeAnnounceForUserDto>(getAnnounceFromRepo)); }
public async Task <HomeAnnounceForReturnDto> Publish(HomeAnnounceForCreationDto updateDto) { var checkFromRepo = await homeAnnounceDal.GetAsync(x => x.Id == updateDto.Id); if (checkFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound }); } var checkHomeAnnounceSubScreenForPublish = await homeAnnounceSubScreenDal.GetListAsync(x => x.HomeAnnounceId == 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 = "home"; await homeAnnounceDal.Update(mapForUpdate); var spec = new HomeAnnounceWithPhotoAndUserSpecification(updateDto.Id); var getAnnounceWithUserFromRepo = await homeAnnounceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <HomeAnnounce, HomeAnnounceForReturnDto>(getAnnounceWithUserFromRepo)); }
public async Task <HomeAnnounceForReturnDto> Create(HomeAnnounceForCreationDto creationDto) { var checkByNameFromRepo = await homeAnnounceDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower()); if (checkByNameFromRepo != null) { throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist }); } var mapForCreate = mapper.Map <HomeAnnounce>(creationDto); var slideId = Guid.NewGuid(); mapForCreate.AnnounceType = "home"; mapForCreate.SlideId = slideId; mapForCreate.Created = DateTime.Now; var createHomeAnnounce = await homeAnnounceDal.Add(mapForCreate); var spec = new HomeAnnounceWithPhotoAndUserSpecification(createHomeAnnounce.Id); var getAnnounceFromRepo = await homeAnnounceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <HomeAnnounce, HomeAnnounceForReturnDto>(getAnnounceFromRepo)); }