예제 #1
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));
        }
예제 #2
0
        public async Task <ActionResult <NewsForReturnDto> > Publish(NewsForCreationDto updateDto)
        {
            var news = await newsService.Publish(updateDto);

            var screenConnectionId = await onlineScreenService.GetAllOnlineScreenConnectionId();

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

            return(news);
        }
예제 #3
0
        public async Task <ActionResult <NewsForReturnDto> > Create([FromBody] NewsForCreationDto creationDto)
        {
            var news = await newsService.Create(creationDto);

            var connIds = await userTracker.GetOnlineUser();

            if (connIds != null && connIds.Length != 0)
            {
                await hubContext.Clients.GroupExcept("News", connIds).SendAsync("ReceiveNewNews", news, true);
            }

            return(news);
        }
예제 #4
0
        public async Task <IActionResult> CreateNews([FromBody] NewsForCreationDto newsForCreationDto)
        {
            //if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            //{
            //    return Unauthorized();
            //}

            newsForCreationDto.Description = newsForCreationDto.Text.Substring(1, 100);
            var news = _mapper.Map <New>(newsForCreationDto);

            _repository.Add(news);
            if (await _repository.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest());
        }
예제 #5
0
        public async Task <ActionResult <NewsForReturnDto> > Update(NewsForCreationDto updateDto)
        {
            var news = await newsService.Update(updateDto);

            var connIds = await userTracker.GetOnlineUser();

            if (connIds != null && connIds.Length != 0)
            {
                await hubContext.Clients.GroupExcept("News", connIds).SendAsync("ReceiveUpdateNews", news);
            }

            var screenConnectionId = await onlineScreenService.GetAllOnlineScreenConnectionId();

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

            return(news);
        }
예제 #6
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));
        }
예제 #7
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));
        }