Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace PCServer.Data
- {
- using System;
- using System.Collections.Generic;
- public partial class Post: IEntity
- {
- public int Id { get; set; }
- public string Title { get; set; }
- public string Message { get; set; }
- public DateTime Date { get; set; }
- public virtual Post ParentPost { get; set; }
- public virtual AspNetUser Author { get; set; }
- }
- }
- public partial class Post
- {
- //This class "do" something, like adding a post or deleting a post
- public static class Do
- {
- public static void AddPost(ref ApplicationDbContext context, string postMessage)
- {
- //Create a post
- Post p = new Post();
- p.Title = "This is an example!";
- p.message = postMessage;
- p.Date = DateTime.UtcNow;
- //Adding to context
- BaseService.Add(post, out context);
- }
- public static void DeletePost(ref ApplicationDbContext context, int postId)
- {
- PostRepository postRepo = new PostRepository(context);
- postRepo.GetById(postId);
- //Removing from context
- BaseService.Remove(post, out context);
- }
- }
- //This class "Get" something, like all posts
- public static class Get
- {
- public static void GetPosts()
- {
- using(ApplicationDbContext context = new ApplicationDbContext())
- {
- PostRepository postRepo = new PostRepository(context);
- return postRepo.GetAllPosts();
- }
- }
- }
- //This class "Set" something, like title of the post or the post itself maybe
- public static class Set
- {
- public static void Title(ref ApplicationDbContext context, int postId, string title)
- {
- PostRepository postRepo = new PostRepository(context);
- Post post = postRepo.GetById(postId);
- post.Title = title;
- BaseService.Update(post, out context);
- }
- public static void ChangePost(ref ApplicationDbContext context, int postId, Post post)
- {
- PostRepository postRepo = new PostRepository(context);
- Post dbPost = postRepo.GetById(postId);
- dbPost = post;
- BaseService.Update(dbPost, out context);
- }
- }
- }
- ApplicationDbContext c = new ApplicationDbContext();
- Post.Do.AddPost(ref c,"Hi!");
- IEnumerable<Post> posts = Post.Get.GetPosts();
- Post.Set.Title(ref c,100,"Changing title!");
- await BaseService.CommitAsync<Post>(c);
Add Comment
Please, Sign In to add comment