public async Task<IHttpActionResult> Post(NewsArticleRequestModel model) { string newsArticleUserId = this.User.Identity.Name; var newsArticleImages = new List<Image>(); if (model.Images != null) { foreach (var image in model.Images) { var imageUrl = await images.UploadAsync(image.ByteArrayContent, image.FileExtension); newsArticleImages.Add(new Image { Url = imageUrl }); } } int articleId = this.newsArticles .Add(model.Name, model.Content, model.CategoryId, newsArticleImages, newsArticleUserId); return this.Ok(1); }
public IHttpActionResult Post(NewsArticleRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } ////var client = StorageAuthentication.GetUserCredentials(); ////DriveService service = StorageAuthentication.AuthenticateOauth(client.ClientId, client.ClientSecret, "root"); var imagesCollection = model.Images; if (imagesCollection != null) { var client = StorageAuthentication.GetUserCredentials(); DriveService service = StorageAuthentication.AuthenticateOauth(client.ClientId, client.ClientSecret, "root"); } //// the case when image files are uploaded and saved on server hdd (Article should be referenced) ////foreach (var image in imagesCollection) ////{ //// var upload = StorageOperation.UploadFile(service, image.Name, StorageOperation.ParentFolder); //// image.Url = string.Format("https://drive.google.com/uc?id={0}", upload.Id); ////} // //// the case when image files are byte arrays ////foreach (var image in imagesCollection) ////{ //// var upload = StorageOperation.UploadFile(service, new byte[100], StorageOperation.ParentFolder); //// image.Url = string.Format("https://drive.google.com/uc?id={0}", upload.Id); ////} var dataModel = Mapper.Map<NewsArticle>(model); var newArticleId = this.newsArticles.Add(dataModel, this.User.Identity.Name); this.pubnub.SendNotification(NotifyConstants.PubnubChannelActivityFeed, string.Format("News article {0} created", dataModel.Name)); return this.Ok(newArticleId); }