public ActionResult TestReg(string imie, string nazwisko, string Dataurodzenia, string Miejscowosc, bool?plec, string login, string email) { try { var Date = Convert.ToDateTime(Dataurodzenia); int wiek = Date.Year - DateTime.Now.Year; string i = imie + nazwisko; using (var db = new DbUsersEntities()) { db.users1.Add(new users1 { login = login, data_urodzenia = Date, email = email, // haslo = haslo, imie = imie, wiek = wiek, miejscowosc = Miejscowosc, nazwisko = nazwisko, plec = plec, }); db.SaveChanges(); }; var data = new { Message = i }; return(Json(data, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw; } // return View(); }
public ActionResult TestLogin(string login, string haslo) { using (var db = new DbUsersEntities()) { var users = db.users1.Any(x => x.login == login && x.haslo == haslo); var user = db.users1.FirstOrDefault(x => x.login == login && x.haslo == haslo); //Store the products to a session Session["Users"] = user; //To get what you have stored to a session //var products = Session["products"] as List<Product>; // to clear the session value //Session["products"] = null; if (user != null) { return(View()); } else { return(Json("nie rafdfsf", JsonRequestBehavior.AllowGet)); } } }
public ActionResult Login(string login, string password) { using (var db = new DbUsersEntities()) { if (login != null && password != null) { var user = db.users1.FirstOrDefault(x => x.login == login && x.haslo == password); if (user != null) { Session["Users"] = user; Session["UserName"] = user.imie + " " + user.nazwisko; Session["TopBar"] = 2; return(RedirectToAction("Index", "Post"));// View("~/Views/Post/index.cshtml", post); } else { return(Json("nie rafdfsf", JsonRequestBehavior.AllowGet)); } return(View()); } else { ViewData["err"] = "nie poprawny login lub hasło"; return(View()); } } }
// GET: Post public ActionResult Index() { using (var db = new DbUsersEntities()) { Posts posts = new Posts(); posts.SessionUser = (users1)Session["Users"]; Session["TopBar"] = 2; posts.AddFriends(2); return(View(posts.GetPosts())); } }
public ActionResult AddFriends(int idFriends) { using (var db = new DbUsersEntities()) { var u = (users1)Session["Users"]; db.Friends.Add(new Friends { idFriends = idFriends, id = u.id }); db.SaveChanges(); return(View()); } }
public ActionResult FrendsListPage() { using (var db = new DbUsersEntities()) { // var u = (users1)Session["Users"]; //db.Friends.Add(new Friends { idFriends = idFriends ,id=u.id}); //db.SaveChanges(); Posts posts = new Posts(); posts.SessionUser = (users1)Session["Users"]; Session["TopBar"] = 2; var a = posts.GetFriends(/*posts.SessionUser.id*/ 1); MainPageViewModel mainPageViewModel = new MainPageViewModel(); mainPageViewModel.Frends = a; return(View(mainPageViewModel)); } }
public ActionResult Like(int idPost) { using (var db = new DbUsersEntities()) { // var u = (users1)Session["Users"]; var post = db.Post.FirstOrDefault(x => x.id == idPost); if (post.likes == null) { post.likes = 1; } else { post.likes += 1; } db.SaveChanges(); return(View()); } }
public ActionResult Comment(int idPost, string text) { using (var db = new DbUsersEntities()) { try { var u = (users1)Session["Users"]; var post = db.Comments.Add(new Comments { //TODO POprawić baze Post id i relacje content = text, postIdTrue = idPost, createDate = DateTime.Now, username = u.imie.Trim() + " " + u.nazwisko.Trim() }); db.SaveChanges(); return(RedirectToAction("Index", "Post")); } catch (Exception ex) { return(View(ex)); } } }