예제 #1
0
        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");
        }
예제 #2
0
        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");
        }
예제 #3
0
        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");
        }