public ActionResult Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (authProvider.Authenticate(model.UserName, model.Password) && model.UserName == "admin")
                {
                    return Redirect(Url.Action("Index", "Admin"));
                }

                using (EFDbContext dbc = new EFDbContext())
                {
                    var user = dbc.UserAccount.Where(u => u.Username == model.UserName && u.Password == model.Password).FirstOrDefault();
                    if (user != null)
                    {
                        FormsAuthentication.SetAuthCookie(user.Username, false);
                        return RedirectToAction("List","Product");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Incorrect username or password");
                        return View();
                    }
                }
            }
            else
            {
                return View();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            EFDbContext context = new EFDbContext();
            foreach (Product p in context.Products)
	{
        Console.WriteLine("Name: " + p.Name);
	}
            
        }
 public EFProductRepository()
 {
     _context = new EFDbContext();
 }
 public ActionResult Register(UserAccount userAccount)
 {
     if (ModelState.IsValid)
     {
         using (EFDbContext dbc = new EFDbContext())
         {
             dbc.UserAccount.Add(userAccount);
             dbc.SaveChanges();
             TempData["message"] = string.Format("{0}  {1} is successfully registered! Please Sign in", userAccount.FirstName, userAccount.LastName);
         }
         ModelState.Clear();
     }
     return RedirectToAction("List","Product");
 }
 public EFProductRepository(EFDbContext context)
 {
     _context = context;
 }
 public EFProductRepository()
 {
     _context = new EFDbContext();
 }
Beispiel #7
0
 public EFProductsRepository()
 {
     this.context = new EFDbContext();
 }
 public ProductRepository()
 {
     this.context = new EFDbContext();
 }