public ActionResult Create([Bind(Include = "Email,Password")] Login login)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    AuthValidator authValidator = new AuthValidator();
                    tbl_empoyee   tbl_Empoyee   = authValidator.IsvalidUser(login);

                    Session["Email"] = tbl_Empoyee.email;
                    Session["Role"]  = tbl_Empoyee.tbl_role.role_name;
                    Session["Name"]  = tbl_Empoyee.emp_name;

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(View(login));
                }
            }
            catch (Exception exception)
            {
                ViewBag.errormeaasge = exception.Message;
                return(View());
            }
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            tbl_empoyee tbl_empoyee = db.tbl_empoyee.Find(id);

            db.tbl_empoyee.Remove(tbl_empoyee);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "emp_id,emp_name,emp_role,status,nic,email,password,created_date")] tbl_empoyee tbl_empoyee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbl_empoyee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.emp_role = new SelectList(db.tbl_role, "role_id", "role_name", tbl_empoyee.emp_role);
     return(View(tbl_empoyee));
 }
Exemple #4
0
        // GET: tbl_empoyee/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_empoyee tbl_empoyee = db.tbl_empoyee.Find(id);

            if (tbl_empoyee == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_empoyee));
        }
Exemple #5
0
        // GET: tbl_empoyee/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_empoyee tbl_empoyee = db.tbl_empoyee.Find(id);

            if (tbl_empoyee == null)
            {
                return(HttpNotFound());
            }
            ViewBag.emp_role = new SelectList(db.tbl_role, "role_id", "role_name", tbl_empoyee.emp_role);
            return(View(tbl_empoyee));
        }
        /// <summary>
        /// valiadate emmployee login
        /// </summary>
        /// <param name="login"><see cref="Login"/></param>
        /// <returns><see cref="tbl_empoyee"/> The login </returns>
        public tbl_empoyee IsvalidUser(Login login)
        {
            // cheack whether emploayee is availabale

            tbl_empoyee tbl_Empoyee = db.tbl_empoyee.Include(
                emp => emp.tbl_role).ToList().Where(
                employee => employee.email.Equals(login.Email, StringComparison.Ordinal) &&
                employee.password.Equals(login.Password, StringComparison.Ordinal)
                ).FirstOrDefault();

            if (tbl_Empoyee != null)
            {
                return(tbl_Empoyee);
            }
            else
            {
                InvalidUserException invalidUserException = new InvalidUserException("User not found in System");
                throw invalidUserException;
            }
        }