public void UpdateRoom(Room room) { ICollection<ValidationResult> validationResults; if (!room.Validate(out validationResults)) { throw new AggregateException("Objektet klarade inte valideringen.", validationResults.Select(vr => new ValidationException(vr.ErrorMessage)).ToList().AsReadOnly()); } RoomDAL.UpdateRoom(room); }
public void UpdateRoom(Room room) { try { using (var conn = new SqlConnection(ConnectionString)) { var cmd = new SqlCommand("appSchema.usp_UpdateRoom", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@RoomID", SqlDbType.TinyInt, 1).Value = room.RoomID; cmd.Parameters.Add("@Heating", SqlDbType.Bit, 1).Value = room.Heating; cmd.Parameters.Add("@RoomDescription", SqlDbType.VarChar, 50).Value = room.RoomDescription; conn.Open(); cmd.ExecuteNonQuery(); } } catch { throw new ApplicationException("Ett fel inträffade då rummet skulle uppdateras i databasen."); } }