/// <summary> /// Adds the comments. /// </summary> /// <param name="commentValue">The comment value.</param> /// <returns></returns> public bool AddComments(CommentData commentValue) { bool IsCommentAdded = false; try { // Retrieve the storage account from the connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=socratacomments;AccountKey=CPUzxusfkGMWv+3cStItzMOjJna7Qyugz/dQDsSzxCg/1oFMaxcWtp7qsC5wb2guaDaSjqubNZ5Qw8f18lV6MQ==");//ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Create the table if it doesn't exist. CloudTable table = tableClient.GetTableReference("Comments"); table.CreateIfNotExists(); // Create the TableOperation that inserts the customer entity. TableOperation insertOperation = TableOperation.Insert(commentValue); // Execute the insert operation. table.Execute(insertOperation); IsCommentAdded = true; } catch (Exception) { IsCommentAdded = false; } return IsCommentAdded; }
public HttpResponseMessage AddComment(string key, CommentData comment) { if (key == secertKey) { if (comment != null) { if (repository.AddComments(comment)) { return Request.CreateResponse(HttpStatusCode.Created, comment); } else { return Request.CreateResponse(HttpStatusCode.ExpectationFailed, "Comment not added"); } } else { return Request.CreateResponse(HttpStatusCode.NoContent, "Pass valid comment to be added"); } } else { return Request.CreateResponse(HttpStatusCode.Unauthorized, "Secret key is invalid"); } }