public async Task <ImageBlobCommentResult> Post(ImageBlobComment imageBlobCommentToSave) { if (imageBlobCommentToSave == null) { return new ImageBlobCommentResult() { Comment = null, SuccessfulAdd = false } } ; if (string.IsNullOrEmpty(imageBlobCommentToSave.Comment)) { return new ImageBlobCommentResult() { Comment = null, SuccessfulAdd = false } } ; // add the imageBlobComment to imageBlobComment storage/table storage var insertedComment = await imageBlobCommentRepository.AddImageBlobComment(imageBlobCommentToSave); return(new ImageBlobCommentResult() { Comment = insertedComment, SuccessfulAdd = true }); }
public async Task <ImageBlobComment> AddImageBlobComment(ImageBlobComment imageBlobCommentToStore) { CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable imageBlobCommentsTable = tableClient.GetTableReference("ImageBlobComments"); var tableExists = await imageBlobCommentsTable.ExistsAsync(); if (!tableExists) { await imageBlobCommentsTable.CreateIfNotExistsAsync(); } ImageBlobCommentEntity imageBlobCommentEntity = new ImageBlobCommentEntity( imageBlobCommentToStore.UserId, imageBlobCommentToStore.UserName, Guid.NewGuid(), imageBlobCommentToStore.AssociatedBlobId, imageBlobCommentToStore.Comment, imageBlobCommentToStore.CreatedOn.ToShortDateString() ); TableOperation insertOperation = TableOperation.Insert(imageBlobCommentEntity); var result = imageBlobCommentsTable.Execute(insertOperation); return(ProjectToBlobComments(new List <ImageBlobCommentEntity>() { imageBlobCommentEntity }).First()); }