Last active
November 6, 2015 20:42
-
-
Save CasonBarnhill/d799671771d9e76671ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Week3Day4.Controllers | |
{ | |
public class Post | |
{ | |
public string Author; | |
public string Body { get; set; } | |
public int Id { get; set; } | |
public int NumberOfComments { get; set; } | |
public DateTime Date { get; set; } | |
public string Title { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
namespace Week3Day4.Controllers | |
{ | |
public class PostsController : ApiController | |
{ | |
List<Post> posts= new List<Post> | |
{ | |
new Post { Id = 1, Title = "Friends", Body = "Hey",Author = "Joe Dirt", Date = DateTime.Parse("01/01/2015"), NumberOfComments= 0 }, | |
new Post { Id = 2, Title = "Trees", Body = "You", Author= "Blanche Lincoln", Date = DateTime.Parse("01/06/2015"), NumberOfComments= 2 }, | |
new Post { Id = 3, Title = "Style", Body = "Suck", Author= "Al Gore", Date = DateTime.Parse("10/10/2015"), NumberOfComments= 3 }, | |
new Post { Id = 4, Title = "Rocks", Body = "Guy", Author= "Jerry McGuire", Date = DateTime.Parse("10/20/2015"), NumberOfComments= 1 }, | |
}; | |
public IEnumerable<Post> GetAllPosts() | |
{ | |
return posts; | |
} | |
public Post GetPosts(int id) | |
{ | |
return posts.First(x => x.Id == id); | |
} | |
public Post CreatePost(Post x) | |
{ | |
x.Id = 3; | |
return x; | |
} | |
[HttpPut] | |
public Post RevisedPost(int id, [FromBody]Post value) | |
{ | |
return new Post(); | |
} | |
public string DeletePost(int id) | |
{ | |
var deletePost = posts.First(p => p.Id == id); | |
posts.Remove(deletePost); | |
return "Removed"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment