/** * Method validates staff member model * * @param staffMember stafFModel * @param staffType default value indicating that no staffType is passed * @return list of errors */ public static List <string> validateStaffMember(StaffModel staffMember, int staffType = -1) { List <string> errors = new List <string>(); if (String.IsNullOrEmpty(staffMember.getFirstName())) { errors.Add("first name"); } if (staffMember.getFirstName().Length < 4) { errors.Add("first name (at least 3 characters)"); } if (String.IsNullOrEmpty(staffMember.getLastName())) { errors.Add("last name"); } if (staffMember.getLastName().Length < 4) { errors.Add("last name (at least 3 characters)"); } if (staffType == 0) { errors.Add("staff type"); } return(errors); }
/** * Saves staff model to the database and returns result (true/false) * * @param staffMember * @return result of saving */ public bool addStaffMember(StaffModel staffMember) { string query = "INSERT INTO " + table + "(`firstName`, `lastName`, `phoneNumber`, `staffType`) VALUES( " + this.getStringInMySqlInsertableFormat(staffMember.getFirstName()) + ", " + this.getStringInMySqlInsertableFormat(staffMember.getLastName()) + ", " + (staffMember.getPhoneNumber() == "NULL" ? staffMember.getPhoneNumber() : this.getStringInMySqlInsertableFormat(staffMember.getPhoneNumber())) + ", " + this.getStringInMySqlInsertableFormat(staffMember.getStaffType()) + " )"; return(this.db.Execute(query)); }