public BookingsListViewModel() : base() { if (IsInDesignMode) { #region Design-time data User dummyUser1 = new User() { FirstName = "John", LastName = "Doe" }; User dummyUser2 = new User() { FirstName = "Alice", LastName = "Wondergirl" }; Room dummyRoom1 = new Room() { Name = "The Red Room" }; Room dummyRoom2 = new Room() { Name = "International Space Station" }; // set up sample model data Bookings = new ObservableCollection<Booking>() { //new Booking() { // ID = 1, StartDate = DateTime.Now.AddDays(-2), EndDate = DateTime.Now.AddDays(-2).AddHours(1), Room = dummyRoom1, User = dummyUser1, RefNum = "abc123", IsCanceled = true }, //new Booking() { // ID = 2, StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(2), Room = dummyRoom2, User = dummyUser2, RefNum = "def456"}, //new Booking() { // ID = 3, StartDate = DateTime.Now.AddDays(2), EndDate = DateTime.Now.AddDays(2).AddHours(1), Room = dummyRoom1, User = dummyUser2, RefNum="ghi789" } }; SelectedBooking = Bookings[2]; #endregion } else { _isInitialized = false; } }
public RoomsFormViewModel() : base() { _roomService = new RoomServiceClient(); _currentRoom = new Room(); SaveRoomCommand = new RelayCommand(this.SaveRoom, () => IsValid); }
public void Delete(Room room) { try { roomRepository.Delete(room); } catch (Exception ex) { throw ex; } }
public void Delete(Room room) { IRoomComponent component = new RoomComponent(); try { component.Delete(room); } catch (Exception e) { throw new FaultException(e.Message); } }
public Room Save(Room room) { IRoomComponent component = new RoomComponent(); try { component.Save(room); } catch (Exception e) { throw new FaultException(e.Message); } return room; }
public void Update(Room entity) { try { using (var session = NHibernateHelper.OpenSession(connString)) { session.Update(entity); session.Flush(); } } catch (Exception ex) { throw ex; } }
public bool Delete(Room entity) { try { using (var session = NHibernateHelper.OpenSession(connString)) { session.Delete(entity); session.Flush(); return true; } } catch (Exception ex) { throw ex; } }
public bool Add(Room entity) { try { using (var session = NHibernateHelper.OpenSession(connString)) { session.Save(entity); return true; } } catch (Exception) { return false; throw; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { lblID.Text = "4"; using (IRoomComponent roomService = new RoomComponent()) { Room room = new Room(); room = roomService.GetRoomByID(int.Parse(lblID.Text)); txtName.Text = room.Name; txtLocation.Text = room.Location; txtCapacity.Text = room.Capacity.ToString(); chkIsEnabled.Checked = room.IsEnabled; } } }
public void Save(Room room) { try { if (room.ID == 0) { roomRepository.Add(room); } else { roomRepository.Update(room); } } catch (Exception ex) { throw ex; } }
protected void btnSave_Click(object sender, EventArgs e) { try { using (IRoomComponent roomService = new RoomComponent()) { Room myRoom = new Room(); myRoom.Name = txtName.Text; myRoom.Location = txtLocation.Text; myRoom.Capacity = int.Parse(txtCapacity.Text); myRoom.IsEnabled = chkIsEnabled.Checked; roomService.Save(myRoom); lblMessage.Text = "Success"; } } catch (Exception) { lblMessage.Text = "Fail"; throw; } }
private void SaveRoom() { RoomValidator validator = new RoomValidator(); ValidationResult results = validator.Validate(_currentRoom); if (!results.IsValid) { foreach (var failure in results.Errors) { Console.WriteLine("Property " + failure.PropertyName + " failed validation. Error was: " + failure.ErrorMessage); } } else { MessengerInstance.Send(new LoadingMessage("Saving room...")); Exception exceptionResult = null; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (object sender, DoWorkEventArgs e) => { if (_currentRoom.ID == 0) { _currentRoom.CreatedBy = StateManager.CurrentUser.ID; _currentRoom.ModifiedBy = null; } else _currentRoom.ModifiedBy = StateManager.CurrentUser.ID; _currentRoom = _roomService.Save(_currentRoom); }; worker.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) => { RaisePropertyChanged("CurrentRoom"); MessengerInstance.Send(new NotificationMessage("RoomSaved")); MessengerInstance.Send(new LoadingMessage(false)); Cancel(); }; worker.RunWorkerAsync(); } }
public BookingsFormViewModel(Booking booking) : base() { _booking = booking; // Initialize fields if (IsInDesignMode) { // Hardcoded design time data RoomList = new ObservableCollection<Room>() { new Room() { Name = "Winterfell", Location = "25th floor", Capacity = 10 }, new Room() { Name = "King's Landing", Location = "24th floor", Capacity = 8 } }; _isConflicting = true; } else { _bookingService = new BookingServiceClient(); _roomService = new RoomServiceClient(); _assetService = new AssetComponent(); _isConflicting = false; RefreshRooms(); RefreshAssets(); } if (_booking == null) { // New booking _isNewBooking = true; _booking = new Booking(); // Default booking dates are today _startDate = DateTime.Today; _endDate = DateTime.Today; // Default booking start time is now + rounded up to next half hour var startHour = DateTime.Now.Hour; var startMinute = DateTime.Now.Minute; if (startMinute < 30 && startMinute > 0) { startMinute = 30; } else if (startMinute > 30) { startMinute = 0; startHour++; } _startTime = new TimeSpan(startHour, startMinute, 0); // Default booking end time is one hour later _endTime = _startTime + TimeSpan.FromHours(1); getBookedItem(); } else { // Edit booking _isNewBooking = false; _startDate = _booking.StartDate.Date; _startTime = _booking.StartDate.TimeOfDay; _endDate = _booking.EndDate.Date; _endTime = _booking.EndDate.TimeOfDay; // Since we do not have navigational properties on Booking and properly // implemented Compare methods on Room, have to do it the ugly way foreach (var r in RoomList) { if (r.ID == _booking.RoomID) { _room = r; break; } } // pre-select booked assets foreach (var bookedAsset in _booking.AssetBookings) { var asset = AssetList.First(a => a.Asset.ID == bookedAsset.AssetID); if (asset != null) { asset.IsSelected = true; } } } // Generate TimeComboBoxitems from 00:00 to 23:30, in 30 minute increments _allTimeOptions = new ObservableCollection<TimeComboBoxItem>(); for (var i = 0; i < 48; i++) { var hours = i / 2; var minutes = (i % 2 == 0) ? 0 : 30; _allTimeOptions.Add(new TimeComboBoxItem() { Time = new TimeSpan(hours, minutes, 0) }); } // Wire up commands MakeBookingCommand = new RelayCommand(this.MakeBooking, () => IsValid && !IsConflicting); CancelCommand = new RelayCommand(this.Cancel); SelectedAssetsChangedCommand = new RelayCommand<SelectionChangedEventArgs>(this.SelectedAssetsChanged); // Subscribe to own PropertyChanging event, to AJAX-ly call BLL validations this.PropertyChanged += new PropertyChangedEventHandler(BookingsFormViewModel_PropertyChanged); }