Untitled

 avatar
user_5070343613
plain_text
2 years ago
1.6 kB
5
Indexable
Never
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Web_Projesi_A.Models;
using Web_Projesi_A.Models.Manager;

namespace Web_Projesi_A.Controllers
{
    public class AdminPanelController : Controller
    {
        private DataContext db = new DataContext();
        // GET: AdminPanel
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Login()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Login(Admin admin)
        {
            var login=db.admin.Where(x=>x.Username == admin.Username).SingleOrDefault();
            if(login.Username==admin.Username && login.Password == admin.Password)
            {
                Session["Admin_id"] = login.Admin_id;
                Session["Username"] = login.Username;
                Session["Password"] = login.Password;
                Session["Position"] = login.Position;
                return RedirectToAction("/Index");
            }
            else
            {
                ViewBag.uyari = "Kullanıcı adınız ve şifreniz yanlıştır.";
            }
            

            return View(admin);
        }
       
        public ActionResult Logout()
        {
            Session["Admin_id"] = null;
            Session["Username"] = null;
            Session["Password"] = null;
            Session["Position"] = null;
            Session.Abandon();

            return RedirectToAction("Login", "AdminPanel");
        }
    }
}