Пример #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 <NewsPhotoForReturnDto> Create(FileUploadDto uploadDto)
        {
            var checkAnnounceById = await newsDal.GetAsync(x => x.Id == uploadDto.AnnounceId);

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



            var uploadFile = new UploadedFileResultDto();

            if (uploadDto.FileType.ToLower() == "image")
            {
                uploadFile = await upload.Upload(uploadDto.File, "news");
            }

            var mapForCreate = new NewsPhotoForCreationDto();

            mapForCreate.Name      = uploadFile.Name;
            mapForCreate.FullPath  = uploadFile.FullPath;
            mapForCreate.NewsId    = uploadDto.AnnounceId;
            mapForCreate.FileType  = uploadFile.FileType;
            mapForCreate.IsConfirm = false;
            mapForCreate.UnConfirm = false;
            var mapForDb    = mapper.Map <NewsPhoto>(mapForCreate);
            var createPhoto = await newsPhotoDal.Add(mapForDb);

            return(mapper.Map <NewsPhoto, NewsPhotoForReturnDto>(createPhoto));
        }
        public async Task <NewsSubScreenForReturnDto> Create(NewsSubScreenForCreationDto creationDto)
        {
            var checkById = await newsSubScreenDal.GetAsync(x => x.SubScreenId == creationDto.SubScreenId && x.NewsId == creationDto.NewsId);

            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 newsDal.GetAsync(x => x.Id == creationDto.NewsId);

            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 NewsSubScreen()
            {
                SubScreenId       = subScreenFromRepo.Id,
                ScreenId          = screenFromRepo.Id,
                NewsId            = checkAnnounceFromRepo.Id,
                SubScreenName     = subScreenFromRepo.Name,
                SubScreenPosition = subScreenFromRepo.Position
            };

            var createSubScreen = await newsSubScreenDal.Add(subScreenForReturn);

            var spec        = new NewsSubScreenWithSubScreenForReturnSpecification(createSubScreen.Id);
            var getFromRepo = await newsSubScreenDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <NewsSubScreen, NewsSubScreenForReturnDto>(getFromRepo));
        }
Пример #4
0
        public async Task <IActionResult> AddImage(IFormFile image)
        {
            var tolga = await _newsDal.GetAsync(x => x.Id == 1);

            tolga.Image = await image.GetBytes();

            //var result = _newsDal.UpdateAsync(tolga);

            //News news = new News
            //{
            //    Title = "Deneme",
            //    SubTitle = "Deneme",
            //    Description = "Deneme",
            //    Image = image.GetBytes().Result
            //};
            //_newsDal.AddAsync(news);

            return(Content("Ok"));
        }