public JsonResult Save(Employee employee)
 {
     try
     {
         if (employee.EmployeeId > 0)
             new UserData().Update(employee);
         else
         {
             employee.Password = Encryption.Encrypt(Keys.EncryptionKey, Keys.DefaultPassword);
             new UserData().Add(employee);
         }
     }
     catch (Exception x)
     {
     }
     return Json(employee, JsonRequestBehavior.AllowGet);
 }
Beispiel #2
0
 public Employee Authenticate(Employee model)
 {
     model.RoleId = 0;
     try
     {
         Employee employee = entities.Employees.Where(x => x.UserId == model.UserId).SingleOrDefault();
         if (employee != null)
         {
             if(employee.Password == model.Password)
                 return employee;
         }
     }
     catch (Exception x)
     {
         throw x;
     }
     return model;
 }
        public JsonResult Authenticate(Employee employee)
        {
            try
            {
                string key = Keys.EncryptionKey;
                employee.Password = Encryption.Encrypt(key, employee.Password);

                employee = new UserData().Authenticate(employee);

                if (employee.RoleId > 0)
                {
                    Session["userid"] = employee.UserId;
                    Session["email"] = employee.EmailId;
                    Session["role"] = employee.RoleId;
                    Session["employeename"] = employee.FirstName + " " + employee.LastName;
                    Session["employeid"] = employee.EmployeeId;

                    FormsAuthentication.SetAuthCookie(employee.UserId, true);
                }
            }
            catch { }

            return Json(employee, JsonRequestBehavior.AllowGet);
        }
Beispiel #4
0
 public bool AddEmployee(Employee employee)
 {
     try
     {
         entities.Employees.Add(employee);
         entities.SaveChanges();
         return true;
     }
     catch (Exception x)
     {
         throw x;
     }
 }
Beispiel #5
0
 public bool Update(Employee model)
 {
     try
     {
         Employee employee = entities.Employees.Where(x => x.EmployeeId == model.EmployeeId).SingleOrDefault();
         if (employee != null)
         {
             entities.Entry(employee).CurrentValues.SetValues(model);
             entities.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception x)
     {
         throw x;
     }
 }
Beispiel #6
0
        private void btnAddEmployee_Click(object sender, EventArgs e)
        {
            string name = txtEmployee.Text.Trim();
            int role = Convert.ToInt32(ddlRole.SelectedValue);

            if (name == "")
            {
                MessageBox.Show("Enter employee name");
                return;
            }
            else if (role == 0)
            {
                MessageBox.Show("Select role");
                return;
            }
            else
            {
                Employee employee = new Employee() { FirstName = name, RoleId = role, CreatedOn = DateTime.Now };
                employee.Password = Encryption.Encrypt(Resources.EncryptionKey, Resources.DefaultPassword);
                bool result = new MasterData().AddEmployee(employee);

                if (result)
                {
                    txtEmployee.Text = "";
                    ddlRole.SelectedIndex = ddlRole.FindString("Select");
                    MessageBox.Show("Employee added successfully");
                }
                else
                {
                    MessageBox.Show("Cannot add employee : contact Admin");
                }
            }
        }