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