//Called when the SaveGuest command is executed, private void ExecuteSaveGuestCommand() { try { List <GuestModel> guestModels = new List <GuestModel>(); foreach (var item in guestCollection) { guestModels.Add(new GuestModel { Age = item.Age, CheckInDate = item.CheckInDate, CheckOutDate = item.CheckOutDate, GuestName = item.GuestName, RoomId = selectedRoom.RoomId, Sex = item.Sex }); } var response = WebApiConsumer.ConsumePostAsJsonAsync("guest", guestModels); MessageBox.Show("Record saved successfully"); } catch (Exception) { MessageBox.Show("Error occurs while saving. Retry Again!"); } }
async void ExecuteRegistrationCommand() { if (RegistrationPassword != ConfirmPassword) { MessageBox.Show("Password and confirmation password do not match."); return; } UserModel userModel = new UserModel { Login = RegistrationLogin, Password = RegistrationPassword, UserName = Username }; try { string response = await WebApiConsumer.ConsumePostAsJsonAsync("users", userModel); if (!string.IsNullOrEmpty(response)) { UserModel user = JsonConvert.DeserializeObject <UserModel>(response); CurrentUserHelper.Instance.SetUserDetails(user); ClearRegistraton(); var currentRegion = regionManager.Regions["LoginViewRegion"]; if (currentRegion != null) { currentRegion.RequestNavigate(new Uri("Dashboard", UriKind.Relative)); } } } catch (Exception) { MessageBox.Show("There is a problem on Registration. Please try again"); } }
async void ExecuteLoginCommand() { UserModel userModel = new UserModel { Login = LoginUserName, Password = LoginPassword }; try { string response = await WebApiConsumer.ConsumePostAsJsonAsync("login", userModel); if (!string.IsNullOrEmpty(response)) { UserModel user = JsonConvert.DeserializeObject <UserModel>(response); CurrentUserHelper.Instance.SetUserDetails(user); var currentRegion = regionManager.Regions["LoginViewRegion"]; if (currentRegion != null) { currentRegion.RequestNavigate(new Uri("Dashboard", UriKind.Relative)); } ClearLogin(); } } catch (Exception) { MessageBox.Show("There is a problem while login. Please try again"); } }
async void GetRooms(string location) { roomCollection.Clear(); string response = await WebApiConsumer.ConsumeGetAsync("room?location=" + location); IEnumerable <RoomModel> rooms = JsonConvert.DeserializeObject <IEnumerable <RoomModel> >(response); foreach (var item in rooms) { roomCollection.Add(item); } SelectedRoom = roomCollection.FirstOrDefault(); }
async void ExecuteSaveCommand() { RoomModel roomModel = new RoomModel { Address = this.Address, Capacity = this.Capacity, Location = this.Location, RoomName = this.RoomName }; try { string response = await WebApiConsumer.ConsumePostAsJsonAsync("room", roomModel); } catch (Exception) { MessageBox.Show("Error occurs while saving. Retry Again!"); } }
async void OnInitialize() { ErrorMessage = string.Empty; ShowErrorRegion = false; try { string response = await WebApiConsumer.ConsumeGetAsync("room"); IEnumerable <RoomModel> locations = JsonConvert.DeserializeObject <IEnumerable <RoomModel> >(response); foreach (var item in locations) { locationCollection.Add(item.Location); } } catch (Exception) { ErrorMessage = "Error in fetching data. Retry Again."; ShowErrorRegion = true; } }
// Calls the web api and gets the guest collection based on selected room. private async void GetGuestCollection() { if (SelectedRoom == null) { return; } ErrorMessage = string.Empty; ShowErrorRegion = false; try { string navigateUrl = "guest?id=" + SelectedRoom.RoomId; string response = await WebApiConsumer.ConsumeGetAsync(navigateUrl); IEnumerable <GuestModel> rooms = JsonConvert.DeserializeObject <IEnumerable <GuestModel> >(response); foreach (var item in rooms) { guestCollection.Add(new GuestEntryViewModel { Age = item.Age, CheckInDate = item.CheckInDate, CheckOutDate = item.CheckOutDate, GuestName = item.GuestName, Sex = item.Sex, GuestId = item.GuestId, RoomId = item.RoomId, IsEditable = false }); } ShowGuestList = guestCollection.Count > 0; } catch (Exception) { ErrorMessage = "Error while fetching data. Retry Again!."; ShowErrorRegion = true; } }