public AddPhotoResponse AddPhoto(AddPhotoRequest request) { action = "/{0}/Photos.{1}"; method = "POST"; var response = SendRequest <PhotoResponse>(request.photo); return(new AddPhotoResponse(response)); }
public async Task <AddPhotoResponse> Add(AddPhotoRequest request, CancellationToken cancellationToken = default) { await _amazonS3Client.PutObjectAsync(new PutObjectRequest { BucketName = BucketName, Key = request.PhotoName, InputStream = request.Content, ContentType = request.ContentType }, cancellationToken); var resourceUrl = $"{_publicUrl}/{BucketName}/{request.PhotoName}"; return(new AddPhotoResponse(resourceUrl)); }
private async void photoList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count == 1) { var photo = e.AddedItems[0] as FacebookAlbumPhotoViewModel; AddPhotoRequest request = new AddPhotoRequest(); request.Transmit = "fb"; Asset asset = new Asset() { Id = photo.ID, Main = _main, XdistancePercent = 1, YdistancePercent = 1, XoffsetPercent = 0, YoffsetPercent = 0 }; request.Assets = new Asset[] { asset }; TinderSession.CurrentSession.CurrentProfile.Photos = await ContentClient.PostAsync<List<Photo>>("media", request).ConfigureAwait(false); NavigationService.GoBack(); } }
public async Task <PhotoDto> Handle(AddPhotoCommand request, CancellationToken cancellationToken) { var user = await _userRepository.Single( u => u.Id == request.AuthenticatedUser.Id, cancellationToken ); var newPhotoName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(request.Photo.FileName)}"; var addPhotoRequest = new AddPhotoRequest(newPhotoName, request.Photo.OpenReadStream(), request.Photo.ContentType); var addPhotoResponse = await _photoStorage.Add(addPhotoRequest, cancellationToken); var photo = new Photo(newPhotoName, addPhotoResponse.Url); user.AddPhoto(photo); return(_mapper.Map <Photo, PhotoDto>(photo)); }
public ActionResult <PhotoResponse> AddPhoto([Bind("ImageId,Title,ImageName")] AddPhotoRequest model) { // only admins can create albums if (Account.Role != Role.Admin) { return(Unauthorized(new { message = "Unauthorized" })); } var photo = _mapper.Map <Photo>(model); _repository.Photo.CreatePhoto(ref photo, Account.Id); // only admins can create albums var photoResponse = _mapper.Map <PhotoResponse>(photo); _logger.LogInfo("Added Photo to Photo Album"); return(Ok(photoResponse)); }
private async void photoList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count == 1) { var photo = e.AddedItems[0] as FacebookAlbumPhotoViewModel; AddPhotoRequest request = new AddPhotoRequest(); request.Transmit = "fb"; Asset asset = new Asset() { Id = photo.ID, Main = _main, XdistancePercent = 1, YdistancePercent = 1, XoffsetPercent = 0, YoffsetPercent = 0 }; request.Assets = new Asset[] { asset }; TinderSession.CurrentSession.CurrentProfile.Photos = await ContentClient.PostAsync <List <Photo> >("media", request).ConfigureAwait(false); NavigationService.GoBack(); } }
private async Task <SaveImageWrapper> SavePhotos(AddPhotoViewModel addPhotoViewModel, PostedItem postedItem) { var saveImageWrapper = new SaveImageWrapper(); if (addPhotoViewModel.StreamData == null) { return(saveImageWrapper); } var photoStreams = new List <Stream> { addPhotoViewModel.StreamData }; var photoDimentionInfos = new List <PhotoDimensionInfo>() { new PhotoDimensionInfo { Width = 450, Height = 450, IsOriginal = false, ReSizeAndCrop = true } }; var addPhotoRequest = new AddPhotoRequest(photoStreams, photoDimentionInfos, postedItem.Slug); var results = await _photoService.AddPhotoAsync(addPhotoRequest); //If any error found during uploading process we will not add anything to database. (ATOMIC) if (results.NewlyAddedPhotoErrorInfos != null && results.NewlyAddedPhotoErrorInfos.Count == 0) { //2. Add photo objects to News Feed object if (results != null && results.NewlyAddedPhotoInfoDetails.Count > 0) { foreach (var photo in results.NewlyAddedPhotoInfoDetails) { var newPhoto = new Photo { Name = photo.AddedPhotoName, FileExtention = photo.ImageFormat, Width = photo.Width, Height = photo.Height, Inserted = DateTime.UtcNow, PhotoType = PhotoType.PostedItem, Container = "photo" }; _applicationDbContext.Photos.Add(newPhoto); postedItem.Photo = newPhoto; } } //5. Save them to database var saveResults = await _applicationDbContext.SaveChangesAsync(); } else if (results.NewlyAddedPhotoErrorInfos.Count > 0) { saveImageWrapper.ErrorMessage = results.NewlyAddedPhotoErrorInfos[0].ErrorMessage; } //var response = new AddUserAvatarResponse(); //6. Lets get the full path on the blob for the new photo var originalPhotoDetails = results.NewlyAddedPhotoInfoDetails.FirstOrDefault(p => p.IsOriginal); var photoName = String.Format(ImageName_450x450_StringFormat, originalPhotoDetails.AddedPhotoName, postedItem.Slug, originalPhotoDetails.ImageFormat); var fullPhotoUrlOnAzureBlobServer = _photoService.GetFullPath(photoName); saveImageWrapper.Url = fullPhotoUrlOnAzureBlobServer; return(saveImageWrapper); }
public bool SaveImageNameAndText(SaveImageNameAndTextRequest request) { IList <string> srcArr = new List <string>(); //获取当前用户 string username = HttpContext.Session.GetString("username"); var txt = request.TextContent.Trim(); //以【】来区分标题 int start = txt.IndexOf('【'); int end = txt.IndexOf('】'); var title = txt.Substring(start, end + 1); //切割字符串获取内容 string[] strs = txt.Split(title); var context = strs[1].Trim(); if (context == null) { return(false); } //初始化Article var article = new AddArticleRequest() { ClassId = request.ClassId, TagId = request.TagId, ArticleTitle = title, ArticleContext = context, IsDelete = false, CreateTime = DateTime.Now.Date, UserName = username, ViewCount = 0, CommmentCount = 0, Context = request.Source }; var articleId = _articleService.AddArticle(AutoMapper.Mapper.Map <ArticleModel>(article)); string strRegExPattern = @"<img[^>]+(src)\s*=\s*""?([^ "">]+)""?(?:[^>]+(width|height)\s*=\s*""?([^ "">]+)""?\s+(height|width)\s*=\s*""?([^ "">]+)""?)?(?:[^>]+(alt)\s*=\s*""?([^"">]+)""?)?"; Regex re = new Regex(strRegExPattern, RegexOptions.IgnoreCase); Match m = re.Match(request.Source); while (m.Success) { srcArr.Add(m.Groups[2].Value); m = m.NextMatch(); } if (srcArr.Count() > 0) { foreach (var src in srcArr) { var photo = new AddPhotoRequest() { ArticleId = articleId, Url = src }; _photoService.AddPhoto(AutoMapper.Mapper.Map <PhotoModel>(photo)); } } else { var photo = new AddPhotoRequest() { ArticleId = articleId, Url = "images/pic_home_news_1.jpg" }; _photoService.AddPhoto(AutoMapper.Mapper.Map <PhotoModel>(photo)); } return(true); }
public virtual async Task <AddPhotoResponse> AddPhotoAsync(AddPhotoRequest addPhotoRequest) { var addPhotoResponse = new AddPhotoResponse(); foreach (var photoStream in addPhotoRequest.PhotoStreams) { var result = ValidateImage(photoStream); if (result.IsValid) { var image = GetImage(photoStream); var fileExtension = image.Format.ToString().ToLower(); var fileName = Guid.NewGuid().ToString(); var fileNameAzure = String.Format("{0}.{1}", fileName, fileExtension); addPhotoResponse.NewlyAddedPhotoInfoDetails.Add(new PhotoInfoDetails { AddedPhotoName = fileName, ImageFormat = fileExtension, Width = image.Width, Height = image.Height, IsOriginal = true, PhotoNameInAzure = fileNameAzure }); //1. Lets add the original image first await UploadToBlobAzureStorage(fileNameAzure, image); foreach (var photoDimentionInfo in addPhotoRequest.PhotoDimentionInfos) { var clonedImage = image.Clone(); if (photoDimentionInfo.ReSizeAndCrop) { //1.Resize var newImageInfo = CalculateAspectRatioFit(clonedImage.Width, clonedImage.Height, photoDimentionInfo.Width, photoDimentionInfo.Height); if (Math.Abs(photoDimentionInfo.Height - (int)newImageInfo.height) <= 1) { clonedImage.Resize(0, photoDimentionInfo.Height); } else { clonedImage.Resize(photoDimentionInfo.Width, 0); } //2. Crop it //var newImageInfo = CalculateAspectRatioFit(clonedImage.Width, clonedImage.Height, photoDimentionInfo.Width, photoDimentionInfo.Height); var x = Math.Abs((int)((photoDimentionInfo.Width - clonedImage.Width) / 2)); var y = Math.Abs((int)((photoDimentionInfo.Height - clonedImage.Height) / 2)); var mG = new MagickGeometry(x, y, photoDimentionInfo.Width, photoDimentionInfo.Height); clonedImage.Crop(mG); } else { clonedImage.Resize(photoDimentionInfo.Width, 0); } //2. lets add the resized images here var fileNameWithDimension = String.Format("{0}_{1}-{2}x{3}.{4}", fileName, addPhotoRequest.Slug, photoDimentionInfo.Width, photoDimentionInfo.Height, fileExtension); await UploadToBlobAzureStorage(fileNameWithDimension, clonedImage); } } else { addPhotoResponse.NewlyAddedPhotoErrorInfos.Add(result); } } return(addPhotoResponse); }