コード例 #1
0
        public PostsController(PostsContext context)
        {
            _context = context;

            if (_context.posts.Count() == 0)
            {
                _context.posts.Add(new Post()
                {
                    Title = "Cras interdum. Nunc sollicitudin commodo", Body = "lorem ipsum sodales purus, in molestie tortor nibh sit amet orci.", Date = "06/01/18, 1:08:54 PM", Author = "Slade"
                });
                _context.posts.Add(new Post()
                {
                    Title = "sollicitudin commodo ipsum. Suspendisse non", Body = "Proin sed turpis nec mauris blandit mattis. Cras eget nisi dictum augue", Date = "28/01/18, 10:05:34 AM", Author = "Griffith"
                });
                _context.posts.Add(new Post()
                {
                    Title = "risus odio, auctor vitae, aliquet", Body = "Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec tincidunt. Donec", Date = "21/10/18, 3:00:50 PM", Author = "Tobias"
                });
                _context.posts.Add(new Post()
                {
                    Title = "risus a ultricies adipiscing, enim", Body = "nec, eleifend non, dapibus rutrum, justo. Praesent luctus. Curabitur egestas nunc", Date = "23/03/19", Author = "Allistair"
                });
                _context.posts.Add(new Post()
                {
                    Title = "vestibulum, neque sed dictum eleifend,", Body = "velit eget laoreet posuere, enim nisl elementum purus, accumsan interdum libero dui nec", Date = "26/04/19, 11:08:54 PM", Author = "Brett"
                });
                _context.posts.Add(new Post()
                {
                    Title = "blandit at, nisi. Cum sociis", Body = "nisl. Quisque fringilla euismod enim. Etiam gravida molestie arcu. Sed eu nibh vulputate", Date = "25/07/19, 3:15:24 PM", Author = "Blake"
                });
                _context.SaveChanges();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: DautbegovicDavid/Posts
 public static void Main(string[] args)
 {
     using (var context = new PostsContext())
     {
         DbInitializer.Initialize(context);
     }
     CreateHostBuilder(args).Build().Run();
 }
コード例 #3
0
 public ActionResult History(Post_ViewModel microblogs)
 {
     using (var db = new PostsContext())
     {
         var microblog = db.Posts.Where(p => p.Author == ControllerContext.HttpContext.User.Identity.Name).ToList().OrderByDescending(b => b.Id);
         return(View(microblog));
     }
 }
コード例 #4
0
 public ActionResult MatchUser(string user)
 {
     using (var db = new PostsContext())
     {
         var users = db.Accounts.Where(u => u.Username == user).ToList();
         return(View(users));
     }
 }
コード例 #5
0
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (db != null)
         {
             db.Dispose();
             db = null;
         }
     }
 }
コード例 #6
0
ファイル: UserApi.cs プロジェクト: zeleniucvladislav/LAB_TW
 internal PostsResp AddPosts(PostsTable post)
 {
     using (var db = new PostsContext())
     {
         db.Posts.Add(post);
         db.SaveChanges();
         return(new PostsResp()
         {
             Status = true, StatusMsg = ""
         });
     }
 }
コード例 #7
0
 public ActionResult Follow(int Id)
 {
     using (var db = new PostsContext())
     {
         db.Follows.Add(new Follow
         {
             Following = Id,
             Followers = ((LocalIdentity)ControllerContext.HttpContext.User.Identity).Id
         });
         db.SaveChanges();
     }
     return(View());
 }
コード例 #8
0
        public ActionResult AddPost(string imgPath, string title, string text)
        {
            using (var db = new PostsContext())
            {
                db.Posts.Add(new Post {
                    ImgPath = imgPath, Title = title, Text = text
                });
                db.SaveChanges();
            }


            return(RedirectToAction("index"));
        }
コード例 #9
0
 public ActionResult Post(Post_ViewModel microblogs)
 {
     using (var db = new PostsContext())
     {
         db.Posts.Add(new Microblog
         {
             Author    = ControllerContext.HttpContext.User.Identity.Name,
             Content   = microblogs.Content,
             Published = DateTime.Now
         });
         db.SaveChanges();
         return(View("Index"));
     }
 }
コード例 #10
0
 public ActionResult Index(Follow Id)
 {
     using (var db = new PostsContext())
     {
         var connections = db.Follows.Where(l => l.Id == Id).ToList();
         //var username = db.Accounts.Where(e => connections.Contains(e.Id));
         List <Follow> finalList = new List <Follow>();
         foreach (var id in connections)
         {
             finalList.Add(db.Follows.FirstOrDefault(e => e.Id == id));
         }
         //At this point finalList has all the entries whose Ids appear in the list listOfIds
         return(View());
     }
 }
コード例 #11
0
ファイル: UserApi.cs プロジェクト: zeleniucvladislav/LAB_TW
        internal List <string> PostsListLogic2()
        {
            List <PostsTable> posts;
            List <string>     local = new List <string>();

            using (var db = new PostsContext())
            {
                posts = db.Posts.ToList();
            }

            foreach (var p in posts)
            {
                local.Add(p.Image);
            }
            return(local);
        }
コード例 #12
0
        public ActionResult Register(RegistrationForm form)
        {
            if (string.IsNullOrWhiteSpace(form.Username) || string.IsNullOrWhiteSpace(form.Password) ||
                string.IsNullOrWhiteSpace(form.PasswordConfirm) || string.IsNullOrWhiteSpace(form.EmailAddress))
            {
                form.ErrorMessage = "All fields are required!";
                return(View(form));
            }

            if (form.Password != form.PasswordConfirm)
            {
                form.ErrorMessage = "Password and confirmation do not match!";
                return(View(form));
            }

            if (form.Password.Length < 8)
            {
                form.ErrorMessage = "Passwords must be at least 8 characters long";
                return(View(form));
            }

            using (var db = new PostsContext())
            {
                // For a real setup, uncomment the email check, to require unique email addresses and usernames
                var account = db.Accounts.FirstOrDefault(a => a.Username == form.Username.ToLower() /* || a.EmailAddress == form.EmailAddress.ToLower() */);
                if (account != null)
                {
                    form.ErrorMessage = "There is already an account with these details";
                    return(View(form));
                }

                // Create the new account
                db.Accounts.Add(new Account
                {
                    Username       = form.Username.ToLower(),
                    HashedPassword = Crypto.HashPassword(form.Password),
                    EmailAddress   = form.EmailAddress
                });
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #13
0
        public ActionResult Login(AuthenticationForm form)
        {
            if (string.IsNullOrWhiteSpace(form.Username) || string.IsNullOrWhiteSpace(form.Password))
            {
                form.ErrorMessage = "Username and password are both required!";
                return(View(form));
            }

            using (var db = new PostsContext())
            {
                var user = db.Accounts.FirstOrDefault(a => a.Username == form.Username.ToLower());
                if (user == null || !Crypto.VerifyHashedPassword(user.HashedPassword, form.Password))
                {
                    form.ErrorMessage = "Incorrect username or password!";
                    return(View(form));
                }

                // Store the (now) logged-in user in session
                Session["user"] = user;
            }

            return(RedirectToAction("Index", "Post"));
        }
コード例 #14
0
 public PostsController(PostsContext ctx)
 {
     _ctx = ctx;
 }
コード例 #15
0
 public CryptoCurrencyController(PostsContext ctx)
 {
     _ctx = ctx;
 }
コード例 #16
0
 public FileService(PostsContext postsContext)
 {
     this.context = postsContext;
 }
コード例 #17
0
 public PostsRepository(PostsContext context)
 {
     _context = context;
 }
コード例 #18
0
 public PostsController(PostsContext postsContext, ISiteSettings siteSettings)
 {
     _postsContext = postsContext;
     _siteSettings = siteSettings;
 }
コード例 #19
0
 public TagsController(IMapper mapper, PostsContext context)
 {
     _mapper  = mapper;
     _context = context;
 }
コード例 #20
0
 public PostsController(PostsContext context)
 {
     _context = context;
 }
コード例 #21
0
ファイル: PostService.cs プロジェクト: arinkarus/RESTSqlLite
 public PostService(PostsContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
コード例 #22
0
 public PostsController(PostsContext context, ILogger <PostsController> logger)
 {
     this.logger = logger;
     db          = context;
 }
コード例 #23
0
 public CommentsController(PostsContext context)
 {
     _context = context;
 }
コード例 #24
0
 public MsSqlRepository(PostsContext _context)
 {
     dbContext = _context;
 }