示例#1
0
        public IActionResult AddAccount(string name, string email, string password)
        {
            Adsdb db = new Adsdb(_connection);

            db.AddUser(name, email, password);
            return(Redirect("/account/login"));
        }
示例#2
0
        public IActionResult MyAccount(int id)
        {
            Adsdb db     = new Adsdb(_connection);
            int   userId = db.GetIdByEmail(User.Identity.Name);

            return(View(db.GetAds(userId)));
        }
示例#3
0
        public IActionResult CreateAd(Ad ad)
        {
            Adsdb db = new Adsdb(_connection);

            db.NewAd(ad);
            return(Redirect("/"));
        }
示例#4
0
        public IActionResult Delete(int id)
        {
            Adsdb db     = new Adsdb(_connection);
            int   userId = db.GetIdByEmail(User.Identity.Name);

            db.Delete(id, userId);
            return(Redirect("/"));
        }
示例#5
0
        public IActionResult Index()
        {
            Adsdb  db         = new Adsdb(_connection);
            AdView view       = new AdView();
            bool   IsLoggedIn = User.Identity.IsAuthenticated;

            if (IsLoggedIn)
            {
                string email = User.Identity.Name;
                view.Id = db.GetIdByEmail(email);
            }
            view.Ads = db.GetAds();
            return(View(view));
        }
示例#6
0
        public IActionResult Login(string password, string email)
        {
            Adsdb db = new Adsdb(_connection);
            User  u  = db.Login(password, email);

            if (u == null)
            {
                TempData["Error"] = "Invalid Login Please Try Again";
                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/createad"));
        }