public ActionResult Create(employee emp) { if (!LoginController.IsAdmin()) { return(View("~/Views/Login/Index.cshtml")); } if (emp == null) { return(HttpNotFound()); } using (glsoverviewdbEntities db = new glsoverviewdbEntities()) { emp.Password = Sha1.Encode(emp.Password); db.employees.Add(emp); try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine( "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"", ve.PropertyName, eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName), ve.ErrorMessage); } } throw; } } return(RedirectToAction("Index", "AdminEmployees")); }
public ActionResult Edit(employee emp) { if (!LoginController.IsAdmin()) { return(View("~/Views/Login/Index.cshtml")); } if (emp == null) { return(HttpNotFound()); } using (glsoverviewdbEntities db = new glsoverviewdbEntities()) { emp.Password = Sha1.Encode(emp.Password); db.Entry(emp).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Index(employee employee) { if (employee == null) { return(HttpNotFound()); } employee.Password = Sha1.Encode(employee.Password); var login = _db.employees .FirstOrDefault(e => e.EmpNo == employee.EmpNo && e.Password == employee.Password); if (login == null) { ModelState.AddModelError("password", "The username or password is incorrect"); return(View()); } Session["User"] = login; return(RedirectToAction("Index", "Admin")); }