Skip to content

Instantly share code, notes, and snippets.

@klimisa
Created May 5, 2017 17:14
Show Gist options
  • Save klimisa/2eda943ea447c3240b3d5ed42e4db1aa to your computer and use it in GitHub Desktop.
Save klimisa/2eda943ea447c3240b3d5ed42e4db1aa to your computer and use it in GitHub Desktop.
public void Save(Hospital hospital)
{
int numberOfRecordsAffected = 0;
using (var connection = new SqlConnection(_applicationSettings.ConnectionString))
{
var command = connection.CreateCommand();
command.CommandText = _UpdateSQL;
command.Parameters.Add(new SqlParameter("@Id", hospital.Id));
command.Parameters.Add(new SqlParameter("@Name", hospital.Name));
command.Parameters.Add(new SqlParameter("@CategoryId", hospital.HospitalCategory.Id));
command.Parameters.Add(new SqlParameter("@Street", hospital.Street));
command.Parameters.Add(new SqlParameter("@StreetNo", hospital.StreetNo));
command.Parameters.Add(new SqlParameter("@PostalCode", hospital.PostalCode));
command.Parameters.Add(new SqlParameter("@City", hospital.City));
command.Parameters.Add(new SqlParameter("@ProvinceId", hospital.ProvinceId));
command.Parameters.Add(new SqlParameter("@RegionId", hospital.RegionId));
command.Parameters.Add(new SqlParameter("@CountryId", hospital.CountryId));
command.Parameters.Add(new SqlParameter("@Phone", hospital.Phone));
command.Parameters.Add(new SqlParameter("@Fax", hospital.Fax ?? (object)DBNull.Value));
command.Parameters.Add(new SqlParameter("@Email", hospital.Email ?? (object)DBNull.Value));
command.Parameters.Add(new SqlParameter("@Website", hospital.Website ?? (object)DBNull.Value));
command.Parameters.Add(new SqlParameter("@BedsNo", hospital.BedsNo));
command.Parameters.Add(new SqlParameter("@ChemoPerMonth", hospital.ChemoPerMonth));
command.Parameters.Add(new SqlParameter("@Nurses", hospital.Nurses));
command.Parameters.Add(new SqlParameter("@SkilledNursesPlanned", hospital.SkilledNursesPlanned));
command.Parameters.Add(new SqlParameter("@SkilledNursesOccupied", hospital.SkilledNursesOccupied));
command.Parameters.Add(new SqlParameter("@ResidentNursesPlanned", hospital.ResidentNursesPlanned));
command.Parameters.Add(new SqlParameter("@ResidentNursesOccupied", hospital.ResidentNursesOccupied));
connection.Open();
numberOfRecordsAffected = command.ExecuteNonQuery();
}
// if (numberOfRecordsAffected == 0)
// throw new ApplicationException(@"No changes were made to Hospital Id (" + Hospital.Id + "), this was due to another process updating the data.");
// else
// Hospital.Version++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment