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();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            EFDbContext context = new EFDbContext();
            foreach (Product p in context.Products)
	{
        Console.WriteLine("Name: " + p.Name);
	}
            
        }
Пример #3
0
 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");
 }
Пример #5
0
 public EFProductRepository(EFDbContext context)
 {
     _context = context;
 }
Пример #6
0
 public EFProductRepository()
 {
     _context = new EFDbContext();
 }
Пример #7
0
 public EFProductsRepository()
 {
     this.context = new EFDbContext();
 }
Пример #8
0
 public ProductRepository()
 {
     this.context = new EFDbContext();
 }