private async Task <string> AddPictureForProfile(IFormFile picture, string userId) { //string userId = Utilities.GetUserId(this.User); string filePath = string.Empty; var user = await _accountManager.GetUserByIdAsync(userId); if (user != null) { if (!string.IsNullOrEmpty(user.Photo)) { PictureExtensions.DeleteFile("i", user.Photo); } user.Photo = Guid.NewGuid() + Path.GetExtension(picture.FileName); await _accountManager.UpdateUserAsync(user); filePath = PicExtensions.Compress(picture, "i", 120, user.Photo); } return(filePath); }
private async Task <string> AddPictureForArticle(IFormFile picture, int id) { string Id = string.Empty; var result = await _dataStore.GetArticleDetailsAsync(id); if (result.Succeeded) { Picture pic = new Picture { Created = DateTime.Now.Date, Article = result.Article, Extension = ".jpg" }; Guid picId = await _dataStore.AddPictureAsync(pic); var path = PicExtensions.Compress(picture, "n", 640, picId + ".jpg"); //you can use this: Path.GetExtension(picture.FileName) PicExtensions.Compress(picture, "m", 360, picId + ".jpg"); // to save as orgine, for me i prefere use .jpg to optimise resources PicExtensions.Compress(picture, "s", 160, picId + ".jpg"); // because Png or bitmap consume more resources Id = picId.ToString(); } return(Id); }