Beispiel #1
0
        public async Task <HomeAnnounceForKiosksForReturnDto> GetHomeAnnounceByIdAsync(int announceId)
        {
            var spec         = new HomeAnnounceWithPhotoAndUserSpecification(announceId);
            var homeannounce = await homeAnnounceDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <HomeAnnounce, HomeAnnounceForKiosksForReturnDto>(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));
        }
        //[SecuredOperation("Sudo,HomeAnnounces.List,HomeAnnounces.All", Priority = 1)]
        public async Task <Pagination <HomeAnnounceForReturnDto> > GetListAsync(HomeAnnounceParams queryParams)
        {
            var spec         = new HomeAnnounceWithPhotoAndUserSpecification(queryParams);
            var listFromRepo = await homeAnnounceDal.ListEntityWithSpecAsync(spec);

            var countSpec = new HomeAnnounceWithFilterForCountSpecification(queryParams);
            var totalItem = await homeAnnounceDal.CountAsync(countSpec);



            var data = mapper.Map <List <HomeAnnounce>, List <HomeAnnounceForReturnDto> >(listFromRepo);

            return(new Pagination <HomeAnnounceForReturnDto>
                   (
                       queryParams.PageIndex,
                       queryParams.PageSize,
                       totalItem,
                       data
                   ));
        }
        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));
        }