public async Task <HomeAnnouncePhotoForReturnDto> Create(FileUploadDto uploadDto)
        {
            var checkAnnounceById = await homeAnnounceDal.GetAsync(x => x.Id == uploadDto.AnnounceId);

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

            var uploadFile = await upload.Upload(uploadDto.File, "homeannounce");

            var mapForCreate = new HomeAnnouncePhotoForCreationDto();

            mapForCreate.Name           = uploadFile.Name;
            mapForCreate.FullPath       = uploadFile.FullPath;
            mapForCreate.HomeAnnounceId = uploadDto.AnnounceId;
            mapForCreate.IsConfirm      = false;
            mapForCreate.UnConfirm      = false;
            var mapForDb    = mapper.Map <HomeAnnouncePhoto>(mapForCreate);
            var createPhoto = await homeAnnouncePhotoDal.Add(mapForDb);

            return(mapper.Map <HomeAnnouncePhoto, HomeAnnouncePhotoForReturnDto>(createPhoto));
        }
Example #2
0
        public async Task <HomeAnnounceSubScreenForReturnDto> Create(HomeAnnounceSubScreenForCreationDto creationDto)
        {
            var checkById = await homeAnnounceSubScreenDal.GetAsync(x => x.SubScreenId == creationDto.SubScreenId && x.HomeAnnounceId == creationDto.HomeAnnounceId);

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

            var subScreenFromRepo = await subSCreenDal.GetAsync(x => x.Id == creationDto.SubScreenId);

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

            var checkAnnounceFromRepo = await homeAnnounceDal.GetAsync(x => x.Id == creationDto.HomeAnnounceId);

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

            var screenFromRepo = await screenDal.GetAsync(x => x.Id == creationDto.ScreenId);

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


            var subScreenForReturn = new HomeAnnounceSubScreen()
            {
                SubScreenId       = subScreenFromRepo.Id,
                ScreenId          = screenFromRepo.Id,
                HomeAnnounceId    = checkAnnounceFromRepo.Id,
                SubScreenName     = subScreenFromRepo.Name,
                SubScreenPosition = subScreenFromRepo.Position
            };

            var createSubScreen = await homeAnnounceSubScreenDal.Add(subScreenForReturn);

            var spec        = new HomeAnnounSubScreenWithSubScreenForReturnSpecification(createSubScreen.Id);
            var getFromRepo = await homeAnnounceSubScreenDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <HomeAnnounceSubScreen, HomeAnnounceSubScreenForReturnDto>(getFromRepo));
        }
        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));
        }