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(); } }
public static void Main(string[] args) { using (var context = new PostsContext()) { DbInitializer.Initialize(context); } CreateHostBuilder(args).Build().Run(); }
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)); } }
public ActionResult MatchUser(string user) { using (var db = new PostsContext()) { var users = db.Accounts.Where(u => u.Username == user).ToList(); return(View(users)); } }
protected void Dispose(bool disposing) { if (disposing) { if (db != null) { db.Dispose(); db = null; } } }
internal PostsResp AddPosts(PostsTable post) { using (var db = new PostsContext()) { db.Posts.Add(post); db.SaveChanges(); return(new PostsResp() { Status = true, StatusMsg = "" }); } }
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()); }
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")); }
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")); } }
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()); } }
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); }
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")); }
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")); }
public PostsController(PostsContext ctx) { _ctx = ctx; }
public CryptoCurrencyController(PostsContext ctx) { _ctx = ctx; }
public FileService(PostsContext postsContext) { this.context = postsContext; }
public PostsRepository(PostsContext context) { _context = context; }
public PostsController(PostsContext postsContext, ISiteSettings siteSettings) { _postsContext = postsContext; _siteSettings = siteSettings; }
public TagsController(IMapper mapper, PostsContext context) { _mapper = mapper; _context = context; }
public PostsController(PostsContext context) { _context = context; }
public PostService(PostsContext context, IMapper mapper) { this.context = context; this.mapper = mapper; }
public PostsController(PostsContext context, ILogger <PostsController> logger) { this.logger = logger; db = context; }
public CommentsController(PostsContext context) { _context = context; }
public MsSqlRepository(PostsContext _context) { dbContext = _context; }