public List <Employee> GetAllEmployees() { try { String SqlQuery = "Select ID, Name, City, Address From Employees "; var EmpList = DBSqlContext.ReturnList <Employee>(SqlQuery); return(EmpList.ToList()); } catch (Exception Ex) { throw Ex; } }
//To delete Employee details public bool DeleteEmployee(int Id) { try { String SqlQuery = "Delete from Employee Where ID = @ID"; DBSqlContext.ExecuteWithoutReturn(SqlQuery, new { ID = Id }); return(true); } catch (Exception ex) { //Log error as per your need throw ex; } }
//To Update Employee details public bool UpdateEmployee(Employee employee) { try { String SqlQuery = "Update Employee set Name = @Name, City = @City,Address=@Address Where ID = @ID"; DBSqlContext.ExecuteWithoutReturn(SqlQuery, new { employee.ID, employee.Name, employee.City, employee.Address }); return(true); } catch (Exception Ex) { throw Ex; } }
public bool AddEmployee(Employee employee) { //Additing the employess try { String SqlQuery = "Insert into Employee(Name, City, Address) values(@Name, @City,@Address)"; DBSqlContext.ExecuteWithoutReturn(SqlQuery, new{ employee.Name, employee.City, employee.Address }); return(true); } catch (Exception ex) { throw ex; } }