// GET: Employee public async Task <ActionResult> Orders(string userID) { OrderView order = new OrderView(); DbLevel db = new DbLevel(); ApplicationUser AppUser = await UserManager.FindByIdAsync(userID); if (AppUser == null) { AppUser = UserManager.FindByName(User.Identity.GetUserId()); } if (AppUser != null) { order.orders = db.GetOrders(AppUser); order.employee = db.GetEmployee(AppUser); order.OrderDetails = db.GetOrderDetails(AppUser); } else { ModelState.AddModelError("", "Something gone wrong"); } return(View(order)); }
public async Task <ActionResult> Register(Register login_) { if (ModelState.IsValid) { DbLevel NW = new DbLevel(); Employees empl = NW.GetEmployee(login_); ApplicationUser user = new ApplicationUser() { UserName = login_.Email, FirstName = login_.FirstName, LastName = login_.LastName }; NorthwindModel db = new NorthwindModel(); if (empl != null) { IdentityResult result = await UserManager.CreateAsync(user, login_.Password); if (result.Succeeded) { login_.Message = empl.FirstName + @" your account created. Login with your credentials"; TempData["Message"] = login_.Message; TempData["EmployeeID"] = empl.EmployeeID; return(RedirectToAction("Login", "Validation")); } if (result.Errors != null && result.Errors.Count() != 0) { //String buillder ommitted for simplicity. foreach (string error_ in (from s in result.Errors select s)) { login_.Message += " " + error_; } TempData["Message"] = login_.Message; return(RedirectToAction("Register", "Validation")); } } else { TempData["Message"] = @"Employee not found. Are you working here?"; login_.Message = TempData["Message"] as string; } } return(View(login_)); }
public async Task <ActionResult> Login(Login login_) { if (ModelState.IsValid) { ApplicationUser user = await UserManager.FindAsync(login_.Email, login_.Password); if (user != null) { List <Claim> claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.NameIdentifier, login_.Email)); //, user.FirstName,user.LastName)); var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(identity); if (AuthenticationManager.AuthenticationResponseGrant.Identity.IsAuthenticated) { DbLevel NW = new DbLevel(); Employees empl = NW.GetEmployee(user); if (empl != null) { TempData["Message"] = @"Welcome" + empl.FirstName + "!"; return(RedirectToAction("Orders", "Edit", new { userID = user.Id })); } else { TempData["Message"] = @"Something werid happened. No employee."; return(View("Register", "Validation")); } } else { TempData["Message"] = @"User not signed in"; } } else { TempData["Message"] = @"Wrong password or username"; } } login_.Message = TempData["Message"] as string; return(View(login_)); }