Exemplo n.º 1
0
        public BlogsTest()
        {
            var option = new DbContextOptionsBuilder <blogsContext>()
                         .UseInMemoryDatabase(databaseName: "blogs")
                         .Options;

            var _context = new blogsContext(option);

            userController = new UsersController(_context);
        }
Exemplo n.º 2
0
 public static async Task SendInitialDataAsync(WebSocket webSocket)
 {
     using (blogsContext dbContext = new blogsContext())
     {
         foreach (var blog in dbContext.Blogs)
         {
             await SendObjectAsync(webSocket, blog, BlogObjects.BLOG);
         }
         foreach (var author in dbContext.People)
         {
             await SendObjectAsync(webSocket, author, BlogObjects.AUTHOR);
         }
         foreach (var post in dbContext.Blogposts)
         {
             await SendObjectAsync(webSocket, post, BlogObjects.POST);
         }
     }
 }
Exemplo n.º 3
0
 public AccountController(blogsContext context)
 {
     _context = context;
 }
Exemplo n.º 4
0
 public UsersController(blogsContext _Context)
 {
     this._Context = _Context;
 }
Exemplo n.º 5
0
 public CommentsController(blogsContext _Context)
 {
     this._Context = _Context;
 }
Exemplo n.º 6
0
 public PostsController(blogsContext _Context)
 {
     this._Context = _Context;
 }
Exemplo n.º 7
0
 public AccounttransactionController(blogsContext context)
 {
     _context = context;
 }
Exemplo n.º 8
0
 public IEnumerable <Blogs> Get()
 {
     using (blogsContext dbContext = new blogsContext()){
         return(dbContext.Blogs.ToList());
     }
 }
Exemplo n.º 9
0
        public static async Task ReceiveStruturedWebSocketObjectAsync(WebSocket webSocket, JObject webSocketJson)
        {
            switch ((MessageType)Enum.Parse(typeof(MessageType), webSocketJson["messageType"].ToString()))
            {
            case MessageType.BUSINESS_OBJECT:
                switch ((BlogObjects)Enum.Parse(typeof(BlogObjects), webSocketJson["className"].ToString()))
                {
                case BlogObjects.BLOG:
                    var x = webSocketJson.ToObject <WebSocketObjectWrapper <Blogs> >();      //JsonConvert.DeserializeObject<WebSocketObjectWrapper<Blogs>>(receiveString);
                    if (x.Action == Actions.CREATE)
                    {
                        Blogs blog = x.Obj;
                        blog.Id = Guid.NewGuid();
                        using (blogsContext dbContext = new blogsContext())
                        {
                            dbContext.Blogs.Add(blog);
                            await dbContext.SaveChangesAsync();
                            await SendObjectAsync(webSocket, blog, BlogObjects.BLOG);
                        }
                    }
                    break;

                case BlogObjects.AUTHOR:
                    var authorWrapper = webSocketJson.ToObject <WebSocketObjectWrapper <People> >();      //JsonConvert.DeserializeObject<WebSocketObjectWrapper<Blogs>>(receiveString);
                    if (authorWrapper.Action == Actions.CREATE)
                    {
                        People person = authorWrapper.Obj;
                        person.Id = Guid.NewGuid();
                        using (blogsContext dbContext = new blogsContext())
                        {
                            dbContext.People.Add(person);
                            await dbContext.SaveChangesAsync();
                            await SendObjectAsync(webSocket, person, BlogObjects.AUTHOR);
                        }
                    }
                    break;

                case BlogObjects.POST:
                    var postWrapper = webSocketJson.ToObject <WebSocketObjectWrapper <Blogposts> >();
                    if (postWrapper.Action == Actions.CREATE)
                    {
                        Blogposts post = postWrapper.Obj;
                        post.Id         = Guid.NewGuid();
                        post.DatePosted = DateTime.Now;
                        using (blogsContext dbContext = new blogsContext())
                        {
                            dbContext.Blogposts.Add(post);
                            await dbContext.SaveChangesAsync();
                            await SendObjectAsync(webSocket, post, BlogObjects.POST);
                        }
                    }
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
        }