public string AddEmployee(Employee Emp) { if (Emp != null) { using (OmanERP_SahilEntities dataContext = new OmanERP_SahilEntities()) { Employee employee = new Employee(); employee.name = Emp.name; employee.DOB = Convert.ToDateTime(Emp.DOB).ToString("yyyy/MM/dd"); employee.Gender = Emp.Gender; employee.Email = Emp.Email; employee.Mobile = Emp.Mobile; employee.Address = Emp.Address; employee.JoiningDate = Convert.ToDateTime(Emp.JoiningDate).ToString("yyyy/MM/dd"); employee.DepartmentID = Emp.DepartmentID; employee.DesignationID = Emp.DesignationID; dataContext.Employees.Add(employee); dataContext.SaveChanges(); return("Employee added Successfully"); } } else { return("Addition of Employee unsucessfull !"); } }
public string UpdateEmployee(Employee Emp) { if (Emp != null) { using (OmanERP_SahilEntities dataContext = new OmanERP_SahilEntities()) { int no = Convert.ToInt32(Emp.Id); var employeeList = dataContext.Employees.Where(x => x.Id == no).FirstOrDefault(); employeeList.name = Emp.name; employeeList.DOB = Convert.ToDateTime(Emp.DOB).ToString("yyyy/MM/dd"); employeeList.Gender = Emp.Gender; employeeList.Email = Emp.Email; employeeList.Mobile = Emp.Mobile; employeeList.Address = Emp.Address; employeeList.JoiningDate = Convert.ToDateTime(Emp.JoiningDate).ToString("yyyy/MM/dd"); employeeList.DepartmentID = Emp.DepartmentID; employeeList.DesignationID = Emp.DesignationID; dataContext.SaveChanges(); return("Employee Updated Successfully"); } } else { return("Invalid Employee"); } }