public ActionResult Post(BusinessPersonal bp) { using var cmd = new MySqlCommand(); ActionResult result = BadRequest(); try { cmd.Connection = new DBConnection().connect(); cmd.Connection.Open(); cmd.CommandText = String.Format( "call addBusiness_Personal('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')", bp.email, bp.password, bp.fName, bp.lName, bp.phone, bp.gender, bp.country, bp.zip ); MySqlDataReader reader = cmd.ExecuteReader(); result = Ok(); } catch (MySqlException msql) { result = BadRequest(msql.ToString()); } catch (Exception ex) { result = BadRequest(ex.ToString()); } cmd.Connection.Close(); return(result); }
public ActionResult Put(int aid, BusinessPersonal bp) { using var cmd = new MySqlCommand(); ActionResult result = BadRequest(); try { if (aid < 0) { throw new GeneralException("Wrong parameters"); } cmd.Connection = new DBConnection().connect(); cmd.Connection.Open(); cmd.CommandText = String.Format( "call editBP({0}, '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')", aid, bp.password, bp.fName, bp.lName, bp.phone, bp.gender, bp.country, bp.zip); MySqlDataReader reader = cmd.ExecuteReader(); result = Ok(); } catch (GeneralException ex) { result = BadRequest(ex.ToString()); } catch (MySqlException msql) { result = BadRequest(msql.ToString()); } catch (Exception ex) { result = BadRequest(ex.ToString()); } cmd.Connection.Close(); return(result); }
private Account getAccountFactory(MySqlDataReader reader, int id) { int type = 0; try { type = (int)reader.GetValue(2); } catch (Exception ex) { return(null); } Account returnAcc; //business pers if (type == 0) { returnAcc = new BusinessPersonal { email = reader.GetValue(0).ToString(), password = reader.GetValue(1).ToString(), type = (int)reader.GetValue(2), numOfCamps = (int)reader.GetValue(3), numOfConts = (int)reader.GetValue(4), numOfSent = (int)reader.GetValue(5), fName = reader.GetValue(6).ToString(), lName = reader.GetValue(7).ToString(), phone = reader.GetValue(8).ToString(), gender = reader.GetValue(9).ToString(), country = reader.GetValue(10).ToString(), zip = reader.GetValue(11).ToString(), id = id }; } else if (type == 1) //company { returnAcc = new Company { email = reader.GetValue(0).ToString(), password = reader.GetValue(1).ToString(), type = (int)reader.GetValue(2), numOfCamps = (int)reader.GetValue(3), numOfConts = (int)reader.GetValue(4), numOfSent = (int)reader.GetValue(5), name = reader.GetValue(6).ToString(), phone = reader.GetValue(8).ToString(), country = reader.GetValue(7).ToString(), zip = reader.GetValue(10).ToString(), phyAddress = reader.GetValue(9).ToString(), id = id, }; } else { return(null); } return(returnAcc); }