public async Task <IActionResult> Publish([FromBody] HulaStatusDetail status) { if (status == null) { return(BadRequest("Invalid request body")); } HulaStatus hulaStatus; try { // save images to storage at first // and get back the urls var imagesString = new StringBuilder(); int count = 0; foreach (var image in status.Images) { if (count > 0) { imagesString.Append(Consts.ImageStringDelimiter); } var imageBinary = Convert.FromBase64String(image.Base64Data); var imageContainerName = status.Publisher; var imageBlobName = $"{status.PublishDate.Year}/{status.PublishDate.Month}/{status.PublishDate.Ticks}_{count}.{image.FileName.Split('.').Last()}"; var imageUrl = await StorageOperations.UploadBlobAsync(imageContainerName, imageBlobName, imageBinary); imagesString.Append(imageUrl); count++; } // then add status to database hulaStatus = new HulaStatus() { Content = status.Content, Publisher = status.Publisher, PublishDate = status.PublishDate, Images = imagesString.ToString() }; HulaStatusRepository.Create(hulaStatus); } catch (Exception) { return(BadRequest("Failed to create")); } return(Ok(hulaStatus)); }
public IEnumerable <HulaStatus> Get(string publisher) { return(HulaStatusRepository.GetByPublisher(publisher)); }
public IEnumerable <HulaStatus> Get() { return(HulaStatusRepository.Get()); }