public List<Designation> GetDesignation() { List<Designation>designations=new List<Designation>(); SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM tbl_Designation"; connection.Open(); SqlCommand command = new SqlCommand(query, connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Designation aDesignation=new Designation(); aDesignation.Id = int.Parse(reader["Id"].ToString()); aDesignation.Code = reader["Code"].ToString(); aDesignation.Title = reader["Title"].ToString(); designations.Add(aDesignation); } reader.Close(); connection.Close(); return designations; }
public string Save(Designation aDesignation) { if (aDesignation.Code == string.Empty) { return "Designation Code is missing"; } else if (aDesignation.Title == string.Empty) { return " Designation Title is missing"; } else if (gateway.IsDesignationCode(aDesignation.Code)) { return "This Code Already Exists, Try Again!!"; } else if (gateway.IsDesignationTitle(aDesignation.Title)) { return "This Title Already Exists, Try Again!!"; } else { int value = gateway.Save(aDesignation); if (value > 0) { return "Saved successfully"; } else { return "Saved Failed."; } } }
public int Save(Designation designation) { SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO tbl_Designation Values('" + designation.Code + "','" + designation.Title + "')"; connection.Open(); SqlCommand command = new SqlCommand(query, connection); int rowsEffected = command.ExecuteNonQuery(); connection.Close(); return rowsEffected; }