public IActionResult SignUp(User user, string password) { SimpleAdsDb db = new SimpleAdsDb(_connectionString); db.AddUser(user, password); return(Redirect("/")); }
public IActionResult DeleteAd(int id) { SimpleAdsDb db = new SimpleAdsDb(_connectionString); db.DeleteAd(id); return(Redirect("/")); }
public IActionResult NewAd(Ad ad) { var db = new SimpleAdsDb(_connectionString); db.AddAd(ad); return(Redirect("/")); }
public IActionResult MyAccount() { if (!User.Identity.IsAuthenticated) { return(Redirect("/account/logIn")); } SimpleAdsDb db = new SimpleAdsDb(_connectionString); var email = User.Identity.Name; var CurrentUser = db.GetByEmail(email); MyAccountViewModel vm = new MyAccountViewModel { Ads = db.MyAccount(CurrentUser.Id) }; return(View(vm)); }
public IActionResult Index() { SimpleAdsDb db = new SimpleAdsDb(_connectionString); HomeViewModel vm = new HomeViewModel { Ads = db.GetAllAds(), IsAuthenticated = User.Identity.IsAuthenticated }; if (User.Identity.IsAuthenticated) { var email = User.Identity.Name; vm.CurrentUser = db.GetByEmail(email); } return(View(vm)); }
public IActionResult NewAd() { if (!User.Identity.IsAuthenticated) { return(Redirect("/account/login")); } else { var email = User.Identity.Name; var db = new SimpleAdsDb(_connectionString); NewAdViewModel vm = new NewAdViewModel { User = db.GetByEmail(email) }; return(View(vm)); } }
public IActionResult LogIn(string email, string password) { SimpleAdsDb db = new SimpleAdsDb(_connectionString); var user = db.LogIn(email, password); if (user == null) { TempData["errorMessage"] = "Invalid email and password combo"; return(Redirect("/account/login")); } var claims = new List <Claim> { new Claim("user", email) }; HttpContext.SignInAsync(new ClaimsPrincipal( new ClaimsIdentity(claims, "Cookies", "user", "role"))).Wait(); return(Redirect("/home/newad")); }