コード例 #1
0
 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);
 }
コード例 #2
0
ファイル: UserData.cs プロジェクト: sachinkumark/Tlieta.Pdms
 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;
 }
コード例 #3
0
        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);
        }
コード例 #4
0
 public bool AddEmployee(Employee employee)
 {
     try
     {
         entities.Employees.Add(employee);
         entities.SaveChanges();
         return true;
     }
     catch (Exception x)
     {
         throw x;
     }
 }
コード例 #5
0
ファイル: UserData.cs プロジェクト: sachinkumark/Tlieta.Pdms
 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;
     }
 }
コード例 #6
0
ファイル: Settings.cs プロジェクト: sachinkumark/Tlieta.Pdms
        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");
                }
            }
        }