public static Guid AddEffect(MedicineTemplate med, string name, SqlConnection connection) { Guid id = CreateID(); string query = "INSERT INTO dbo.Effect (ID,Name,ValidFrom,ValidTo) VALUES (@ID,@Name,@ValidFrom,@ValidTo) "; bool exists = EffectInDb(name, connection); if (!exists) { using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@ID", id); command.Parameters.AddWithValue("@Name", name); command.Parameters.AddWithValue("@ValidFrom", med.ValidFrom); command.Parameters.AddWithValue("@ValidTo", med.ValidTo); command.ExecuteNonQuery(); } return(id); } else { string newQuery = "SELECT ID FROM[Effect] WHERE([Name] = @Name)"; using (SqlCommand get_effect = new SqlCommand(newQuery, connection)) { get_effect.Parameters.AddWithValue("@Name", name); var stringId = get_effect.ExecuteScalar().ToString(); Guid returnedId = Guid.Parse(stringId); return(returnedId); } } }
public static void AddMedicineEffect(Guid medicineId, Guid effectId, MedicineTemplate med, SqlConnection connection) { string query = "INSERT INTO dbo.MedicineEffects (MedicineID,EffectID,ValidFrom,ValidTo) VALUES (@MedicineID,@EffectID,@ValidFrom,@ValidTo)"; using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@MedicineID", medicineId); command.Parameters.AddWithValue("@EffectID", effectId); command.Parameters.AddWithValue("@ValidFrom", med.ValidFrom); command.Parameters.AddWithValue("@ValidTo", med.ValidTo); command.ExecuteNonQuery(); } }
public static List <string> GetMedicineEffects(MedicineTemplate med) { List <string> effectsList = new List <string>(); var effecto = med.Effects.Replace("\"", ""); if (effecto.Contains("+")) { string[] effects = effecto.Split(" +"); foreach (string effect in effects) { effectsList.Add(effect); } } else { effectsList.Add(effecto); } return(effectsList); }