Exemple #1
0
        protected void EmployeeGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            using (HREntities hr = new HREntities())
            {
                GridViewRow row           = EmployeeGrid.Rows[e.RowIndex];
                TextBox     textmployeeId = row.Cells[1].Controls[0] as TextBox;
                int         employeeId    = int.Parse(textmployeeId.Text);
                TextBox     textFirstName = row.Cells[2].Controls[0] as TextBox;
                string      firstName     = textFirstName.Text;
                TextBox     textLastName  = row.Cells[3].Controls[0] as TextBox;
                string      lastName      = textLastName.Text;
                TextBox     textEmail     = row.Cells[4].Controls[0] as TextBox;
                string      email         = textEmail.Text;

                COPY_EMP employee = new COPY_EMP {
                    EMPLOYEE_ID = employeeId,
                    FIRST_NAME  = firstName,
                    LAST_NAME   = lastName,
                    EMAIL       = email
                };
                hr.Entry(employee).State = System.Data.Entity.EntityState.Modified;
                hr.SaveChanges();
            }
            EmployeeGrid.EditIndex = -1;
            UpdateDataGrid();
        }
Exemple #2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                using (HREntities hr = new HREntities())
                {
                    int    employeeId = int.Parse(txtEmployeeId.Text);
                    string firstName  = txtFirstName.Text;
                    string lastName   = txtLastName.Text;
                    string email      = txtEmail.Text;

                    COPY_EMP employee = new COPY_EMP
                    {
                        EMPLOYEE_ID = employeeId,
                        FIRST_NAME  = firstName,
                        LAST_NAME   = lastName,
                        EMAIL       = email
                    };

                    hr.COPY_EMP.Add(employee);
                    hr.SaveChanges();
                }
                UpdateDataGrid();
            }
        }
 public ActionResult DeleteEmployee(int id)
 {
     using (HREntities hr = new HREntities())
     {
         COPY_EMP employee = hr.COPY_EMP.Find(id);
         hr.COPY_EMP.Remove(employee);
         hr.SaveChanges();
         return(Redirect("~/employees"));
     }
 }
Exemple #4
0
 protected void EmployeeGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     using (HREntities hr = new HREntities())
     {
         GridViewRow row        = EmployeeGrid.Rows[e.RowIndex];
         int         employeeId = int.Parse(row.Cells[1].Text);
         COPY_EMP    emp        = hr.COPY_EMP.Find(employeeId);
         hr.COPY_EMP.Remove(emp);
         hr.SaveChanges();
     }
     UpdateDataGrid();
 }
 public ActionResult AddEmployee(Employee employee)
 {
     using (HREntities hr = new HREntities()) {
         COPY_EMP addedEmp = new COPY_EMP
         {
             EMPLOYEE_ID = employee.EmployeeId,
             FIRST_NAME  = employee.FirstName,
             LAST_NAME   = employee.LastName
         };
         hr.COPY_EMP.Add(addedEmp);
         hr.SaveChanges();
         return(Redirect("~/employees"));
     }
 }
 public ActionResult UpdateEmployee(Employee edittedEmployee)
 {
     using (HREntities hr = new HREntities())
     {
         COPY_EMP addedEmp = new COPY_EMP
         {
             EMPLOYEE_ID = edittedEmployee.EmployeeId,
             FIRST_NAME  = edittedEmployee.FirstName,
             LAST_NAME   = edittedEmployee.LastName
         };
         hr.Entry(addedEmp).State = System.Data.Entity.EntityState.Modified;
         hr.SaveChanges();
         return(Redirect("~/employees"));
     }
 }
        public ActionResult GetEmployee(int id)
        {
            using (HREntities hr = new HREntities())
            {
                // Cara Kedua
                COPY_EMP empModel = hr.COPY_EMP.Find(id);
                Employee employee = new Employee {
                    EmployeeId = (int)empModel.EMPLOYEE_ID,
                    FirstName  = empModel.FIRST_NAME,
                    LastName   = empModel.LAST_NAME,
                };

                return(View("COPY_EMP", employee));
            }
        }
        public ActionResult UpdateEmployee(int id, COPY_EMP employee)
        {
            using (HREntities hr = new HREntities())
            {
                var currentEmployee = hr.COPY_EMP.Find(id);
                currentEmployee.FIRST_NAME   = employee.FIRST_NAME;
                currentEmployee.LAST_NAME    = employee.LAST_NAME;
                currentEmployee.EMAIL        = employee.EMAIL;
                currentEmployee.HIRE_DATE    = employee.HIRE_DATE;
                currentEmployee.PHONE_NUMBER = employee.PHONE_NUMBER;
                currentEmployee.SALARY       = employee.SALARY;

                hr.SaveChanges();
                return(Redirect("~/employees"));
            }
        }
 public ActionResult PostEmployee(EmployeeDTO emp)
 {
     if (ModelState.IsValid)
     {
         using (HREntities hr = new HREntities())
         {
             COPY_EMP newEmployee = new COPY_EMP()
             {
                 EMPLOYEE_ID  = emp.EmployeeId,
                 FIRST_NAME   = emp.FirstName,
                 LAST_NAME    = emp.LastName,
                 EMAIL        = emp.Email,
                 PHONE_NUMBER = emp.PhoneNumber,
                 HIRE_DATE    = emp.HiredDate
             };
             hr.COPY_EMP.Add(newEmployee);
             hr.SaveChanges();
             return(Redirect("~/employees"));
         }
     }
     return(View("EmployeeForm"));
 }