public async Task <AnnouncePhotoForReturnDto> Create(FileUploadDto uploadDto) { var checkAnnounceById = await announceDal.GetAsync(x => x.Id == uploadDto.AnnounceId); if (checkAnnounceById == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFoundAnnounce }); } if (checkAnnounceById.ContentType.ToLower() != uploadDto.FileType.ToLower()) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = "Lütfen duyuru tipine uygun bir dosya yükleyin" }); } var uploadFile = new UploadedFileResultDto(); if (uploadDto.FileType.ToLower() == "image") { uploadFile = await upload.Upload(uploadDto.File, "announce"); } if (uploadDto.FileType.ToLower() == "video") { uploadFile = await upload.UploadVideo(uploadDto.File, "announce"); } var mapForCreate = new AnnouncePhotoForCretionDto(); mapForCreate.Name = uploadFile.Name; mapForCreate.FullPath = uploadFile.FullPath; mapForCreate.AnnounceId = uploadDto.AnnounceId; mapForCreate.FileType = uploadFile.FileType; mapForCreate.Duration = uploadDto.Duration; mapForCreate.IsConfirm = false; mapForCreate.UnConfirm = false; var mapForDb = mapper.Map <AnnouncePhoto>(mapForCreate); var createPhoto = await announcePhotoDal.Add(mapForDb); return(mapper.Map <AnnouncePhoto, AnnouncePhotoForReturnDto>(createPhoto)); }
public async Task <AnnounceForReturnDto> Create(AnnounceForCreationDto creationDto) { var claimId = int.Parse(httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value); var checkByNameFromRepo = await announceDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower()); if (checkByNameFromRepo != null) { throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist }); } var mapForCreate = mapper.Map <Announce>(creationDto); var slideId = Guid.NewGuid(); mapForCreate.SlideId = slideId; if (creationDto.UserId > 0) { mapForCreate.UserId = creationDto.UserId; } else { mapForCreate.UserId = claimId; } mapForCreate.Created = DateTime.Now; mapForCreate.AnnounceType = "announce"; var createAnnounce = await announceDal.Add(mapForCreate); var spec = new AnnounceWithUserSpecification(createAnnounce.Id); var getAnnounceFromRepo = await announceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <Announce, AnnounceForReturnDto>(getAnnounceFromRepo)); }
public async Task <AnnounceSubScreenForReturnDto> Create(AnnounceSubScreenForCreationDto creationDto) { var checkById = await announceSubScreenDal.GetAsync(x => x.SubScreenId == creationDto.SubScreenId && x.AnnounceId == creationDto.AnnounceId); 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 announceDal.GetAsync(x => x.Id == creationDto.AnnounceId); 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 AnnounceSubScreen() { SubScreenId = subScreenFromRepo.Id, ScreenId = screenFromRepo.Id, AnnounceId = checkAnnounceFromRepo.Id, SubScreenName = subScreenFromRepo.Name, SubScreenPosition = subScreenFromRepo.Position }; var createSubScreen = await announceSubScreenDal.Add(subScreenForReturn); var spec = new AnnounSubScreenWithSubScreenForReturnSpecification(createSubScreen.Id); var getFromRepo = await announceSubScreenDal.GetEntityWithSpecAsync(spec); return(mapper.Map <AnnounceSubScreen, AnnounceSubScreenForReturnDto>(getFromRepo)); }