public void Create(UglyCommentModel comment) { //det namn vår table ska ha string tableName = "UglyComments"; //Connection till table storage account CloudStorageAccount account = CloudStorageAccount.Parse(fuladjurstorageConnectionString); //Klient för table storage CloudTableClient tableStorage = account.CreateCloudTableClient(); //Hämta en reference till tablen, om inte finns, skapa table CloudTable table = tableStorage.GetTableReference(tableName); table.CreateIfNotExists(); var key = Guid.NewGuid().ToString(); var newComment = new UglyComment(key) { Name = comment.Name, Text = comment.Text, AnimalId = comment.AnimalId, Created = DateTime.Now }; //Sparar personen i signups table TableOperation insertOperation = TableOperation.Insert(newComment); table.Execute(insertOperation); }
public List <UglyCommentModel> GetAll(string animalId) { // Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(fuladjurstorageConnectionString); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "UglyAnimals" table. CloudTable table = tableClient.GetTableReference("UglyComments"); TableQuery <UglyComment> query = new TableQuery <UglyComment>(); if (animalId != null) { query.Where( TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "UglyComment"), TableOperators.And, TableQuery.GenerateFilterCondition("AnimalId", QueryComparisons.Equal, animalId))); } else { query.Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "UglyComment")); } List <UglyCommentModel> uglyComments = new List <UglyCommentModel>(); // Print the fields for each animal. foreach (UglyComment entity in table.ExecuteQuery(query)) { var comment = new UglyCommentModel { Id = entity.RowKey, Name = entity.Name, Text = entity.Text, AnimalId = entity.AnimalId, Created = entity.Created }; uglyComments.Add(comment); } var orderedComments = uglyComments.OrderBy(comment => comment.Created).ToList(); return(orderedComments); }
public ActionResult CreateComment(FormCollection form) { string animalId = Request.Form["djur.NewComment.AnimalId"]; string name = Request.Form["djur.NewComment.Name"]; string text = Request.Form["djur.NewComment.Text"]; UglyCommentModel newComment = new UglyCommentModel { AnimalId = animalId, Name = name, Text = text }; _uglyComments.Create(newComment); return(RedirectToAction("Index")); }
public void Create(UglyCommentModel comment) { throw new NotImplementedException(); }