private async void DisenrollButton_OnClicked(object sender, EventArgs e) { var restResponse = await _restService.DisenrollUser(_currentWorkshopID); if (restResponse.ResponseCode == null) { await DisplayAlert("Error", restResponse.ErrorMessage + "\nControleer of u verbining heeft met het internet", "Ok"); return; } if (restResponse.ResponseCode == HttpStatusCode.Unauthorized) { //Check token validation additionaly await DisplayAlert("Error", "Uw sessie is verlopen, U wordt terug gestuurd naar de login pagina", "Ok"); Application.Current.MainPage = new LoginView(); } if (restResponse.ResponseCode == HttpStatusCode.OK) { UserDisenrolled?.Invoke(this, _currentWorkshop); _currentWorkshop.IsEnrolled = false; _currentWorkshop.TakenSpots--; await Navigation.PopModalAsync(); } }
private async void WorkshopsListView_OnItemSelected(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem == null) { return; } var currentItem = e.SelectedItem as WorkshopDTO; var workshopDetailpage = new WorkshopDetail(currentItem.Id); workshopDetailpage.UserEnrolled += (o, workshop) => { //This can be called only from workshop all //Update raw list var workshopDto = workshopsRawList.FirstOrDefault(dto => dto.Id == workshop.Id); if (workshopDto != null) { workshopDto.IsEnrolled = true; workshopDto.TakenSpots++; } UserEnrolled?.Invoke(this, workshopDto); }; workshopDetailpage.UserDisenrolled += (o, workshop) => { var workshopDto = workshopsRawList.FirstOrDefault(dto => dto.Id == workshop.Id); if (workshopDto != null) { if (_type == WorkshopBrowserType.All) { workshopDto.IsEnrolled = false; workshopDto.TakenSpots--; } else if (_type == WorkshopBrowserType.Reserved) { workshopsRawList.Remove(workshopDto); displayList = ApplySorting(ApplyFilters(workshopsRawList)); } } UserDisenrolled?.Invoke(this, workshopDto); }; workshopDetailpage.WorkshopEvaluated += (o, workshop) => { //Update raw list var workshopDto = workshopsRawList.FirstOrDefault(dto => dto.Id == workshop.Id); if (workshopDto != null) { workshopDto.IsEvaluated = true; } WorkshopEvaluated?.Invoke(this, workshopDto); }; await Navigation.PushModalAsync(workshopDetailpage); WorkshopsListView.SelectedItem = null; }
private async void WorkshopsListView_OnItemSelected(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem == null) { return; } var currentItem = e.SelectedItem as WorkshopDTO; var workshopDetailpage = new WorkshopDetail(currentItem.Id); workshopDetailpage.UserEnrolled += (o, workshop) => { var workshopDto = _workshopsList.FirstOrDefault(dto => dto.Id == workshop.Id); if (workshopDto != null) { workshopDto.IsEnrolled = true; workshopDto.TakenSpots++; } UserEnrolled?.Invoke(this, workshopDto); }; workshopDetailpage.UserDisenrolled += (o, workshop) => { var workshopDto = _workshopsList.FirstOrDefault(dto => dto.Id == workshop.Id); if (workshopDto != null) { workshopDto.IsEnrolled = false; workshopDto.TakenSpots--; } UserDisenrolled?.Invoke(this, workshopDto); }; workshopDetailpage.WorkshopEvaluated += (o, workshop) => { var workshopDto = _workshopsList.FirstOrDefault(dto => dto.Id == workshop.Id); if (workshopDto != null) { workshopDto.IsEvaluated = true; } WorkshopEvaluated?.Invoke(this, workshopDto); }; await Navigation.PushModalAsync(workshopDetailpage); WorkshopsListView.SelectedItem = null; }
private async Task PopulateCalendar() { //Get list of days with workshops for given year/month var takenDaysRepsonse = await _restService.GetDaysWithWorkshop(_currentMonth, _currentYear); var takenDays = new List <int>(); if (takenDaysRepsonse.ResponseCode == null) { await DisplayAlert("Error", takenDaysRepsonse.ErrorMessage + "\nMake sure that you have internet connection", "Ok"); } if (takenDaysRepsonse.ResponseCode == HttpStatusCode.Unauthorized) { await DisplayAlert("Error", "Your session has expired. You will be redirected to log in", "Ok"); Application.Current.MainPage = new LoginView(); } if (takenDaysRepsonse.ResponseCode == HttpStatusCode.OK) { takenDays = takenDaysRepsonse.Value; } Month.Text = (_cultureInfo.DateTimeFormat.GetMonthName(_currentMonth) + " " + _currentYear).ToUpper(); var daysNumber = DateTime.DaysInMonth(_currentYear, _currentMonth); var firstDayOfWeek = (new DateTime(_currentYear, _currentMonth, 1)).DayOfWeek; int firstDay; if (firstDayOfWeek == DayOfWeek.Sunday) { firstDay = 6; } else { firstDay = (int)firstDayOfWeek - 1; } var dayCounter = 1; for (var j = 0; j < 6; j++) { for (var i = 0; i < 7; i++) { var label = _gridStackLayouts.ElementAt(j * 7 + i).Children[0] as Label; var button = _gridStackLayouts.ElementAt(j * 7 + i).Children[1] as Button; button.BackgroundColor = _gridStackLayouts.ElementAt(j * 7 + i).BackgroundColor; _gridStackLayouts.ElementAt(j * 7 + i).GestureRecognizers.Clear(); if (dayCounter <= daysNumber && j * 7 + i >= firstDay) { if (takenDays.Contains(dayCounter)) { var localCounter = dayCounter; button.BackgroundColor = Color.Black; var tap = new TapGestureRecognizer(); tap.Tapped += async(object sender, EventArgs e) => { var newDayModal = new DayModalView(_currentYear, _currentMonth, localCounter); newDayModal.UserEnrolled += (o, dto) => { UserEnrolled?.Invoke(this, dto); }; newDayModal.UserDisenrolled += (o, dto) => { UserDisenrolled?.Invoke(this, dto); }; newDayModal.WorkshopEvaluated += (o, dto) => { WorkshopEvaluated?.Invoke(this, dto); }; await Navigation.PushModalAsync(newDayModal); }; _gridStackLayouts.ElementAt(j * 7 + i).GestureRecognizers.Add(tap); } label.Text = dayCounter.ToString(); dayCounter++; } else { label.Text = null; } } } }