c# - How to make a List variable constant in ASP.NET -


in code, trying check rooms available @ time has been entered user. test whether room free, change roomname options , clash check. problem is, when change room name, updates on list of existingbookings. there way make sure existingbookings not change?

var existingbookings = _context.bookings.tolist(); var booking = await _context.bookings.singleordefaultasync(m => m.bookingid == id);  list<room> roomlist = new list<room>();  roomlist = (from product in _context.room             select product).tolist();  list<room> availablerooms = new list<room>();  foreach (var item in roomlist) {     booking.roomname = item.roomname;      if (businesslogic.bookingchecker.doesbookingclash(booking, existingbookings) == null)     {         availablerooms.insert(0, new room { roomid = item.roomid, roomname = item.roomname });     }      booking.roomname = "undef"; } 

thanks help!

in order have create new instance of booking. can call constructor , copy necessary properties, or implement icloneable.clone method.

public class booking : icloneable {     public booking clone()     {         return new booking() { roomid = this.roomid, etc. };     }      object icloneable.clone()     {         return this.clone();     } } 

then call it:

booking = booking.clone();  // use new booking instance. 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -