public EndShiftConfirmViewModel() { WorkShift = true; DriveShift = false; BreakShift = false; dbService = new DatabaseService(); // Get last workshift ShiftTable currentShift = dbService.GetLastShift(); string uneditedStartLocation = currentShift.StartLocation; string uneditedEndLocation = currentShift.EndLocation; StartLocation = uneditedStartLocation.Substring(uneditedStartLocation.LastIndexOf(',') + 1); EndLocation = uneditedEndLocation.Substring(uneditedEndLocation.LastIndexOf(',') + 1); StartTimePicker = DateTime.Parse(currentShift.StartDate).TimeOfDay; EndTimePicker = DateTime.Parse(currentShift.EndDate).TimeOfDay; // Get all driving shifts associated listOfDriveShifts = dbService.GetDriveShifts(currentShift.Key); DriveShiftTotalCount = listOfDriveShifts.Count; // Get all breaks associated listOfBreaks = dbService.GetBreaks(currentShift); BreakTotalCount = listOfBreaks.Count; }
internal async Task <int> QueryShift(ShiftTable shift, bool shiftStarted, int userId = 0, int companyId = 0, int dayShift = 0) { string contentType = Constants.CONTENT_TYPE; string url; string json; if (shiftStarted) { url = GetBaseUrl() + Constants.REST_URL_ADDSHIFTEND; EndShiftModel shiftModel = new EndShiftModel() { id = shift.ServerKey, endDate = shift.EndDate, endLocationLat = shift.EndLat, endLocationLong = shift.EndLong, endLocation = shift.EndLocation, endNote = shift.EndNote }; json = JsonConvert.SerializeObject(shiftModel); } else { url = GetBaseUrl() + Constants.REST_URL_ADDSHIFTSTART; StartShiftModel shiftModel = new StartShiftModel() { driverId = userId, companyId = companyId, startDate = shift.StartDate, startLocationLat = shift.StartLat, startLocationLong = shift.StartLong, startLocation = shift.StartLocation, startNote = shift.StartNote, dayShiftId = dayShift }; json = JsonConvert.SerializeObject(shiftModel); } HttpContent content = new StringContent(json, Encoding.UTF8, contentType); HttpResponseMessage response; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", accessToken); try { response = await client.PostAsync(url, content); } catch { return(-2); } } if (response.IsSuccessStatusCode) { QueryShiftResponse result = JsonConvert.DeserializeObject <QueryShiftResponse>(response.Content.ReadAsStringAsync().Result); if (result.Success) { if (result.Result > 0) { return(result.Result); } return(0); } else { await UserDialogs.Instance.AlertAsync(Resource.RegisterShiftError, Resource.Alert, Resource.Okay); return(-2); } } else { await UserDialogs.Instance.AlertAsync(Resource.ConnectionError, Resource.Alert, Resource.Okay); return(-2); } }
public void LoadShiftDetails(ShiftTable shift) { Pages = new ObservableCollection <CarouselViewModel>(); Drives = new List <DriveTable>(); Notes = new List <NoteTable>(); Breaks = new List <BreakTable>(); Drives = db.GetDriveShifts(shift.Key); Notes = db.GetNotes(shift.Key); Breaks = db.GetBreaks(shift); if (Drives.Count != 0 || Breaks.Count != 0 || Notes.Count != 0) { ExtraDetails = true; } else { ExtraDetails = false; } if (Drives.Count != 0) { Pages.Add(new CarouselViewModel { Title = "Drives", Page = "DriveView", ImageSource = "icon.png", Drives = Drives }); } if (Notes.Count != 0) { Pages.Add(new CarouselViewModel { Title = "Notes", Page = "NoteView", ImageSource = "icon.png", Notes = Notes }); } if (Breaks.Count != 0) { Pages.Add(new CarouselViewModel { Title = "Breaks", Page = "BreakView", ImageSource = "icon.png", Breaks = Breaks }); } CurrentPage = Pages.FirstOrDefault(); if (shift.EndDate != string.Empty) { ShiftDate = DateTime.Parse(shift.StartDate).ToString("g") + " - " + DateTime.Parse(shift.EndDate).ToString("g"); } else { ShiftDate = DateTime.Parse(shift.StartDate).ToString("g") + " - Current"; } if (shift.StartLocation != null) { string startLocation = shift.StartLocation.Split(',')[1]; if (shift.EndLocation != null) { string endLocation = shift.EndLocation.Split(',')[1]; ShiftLocation = startLocation.Trim() + " - " + endLocation.Trim(); } else { ShiftLocation = startLocation.Trim() + " -"; } } else { ShiftLocation = "Unknown - Unknown"; } ShiftSelected = true; CurrentShiftIndex = ShiftList.IndexOf(shift); if (CurrentShiftIndex == 0) { CanExecuteChangeShift(false, true); } else if (CurrentShiftIndex == (ShiftList.Count - 1)) { CanExecuteChangeShift(true, false); } else { CanExecuteChangeShift(true, true); } OnPropertyChanged("Drives"); OnPropertyChanged("Notes"); OnPropertyChanged("Breaks"); OnPropertyChanged("ShiftDate"); OnPropertyChanged("ShiftLocation"); OnPropertyChanged("ShiftSelected"); OnPropertyChanged("DrivesAvailable"); OnPropertyChanged("BreaksAvailable"); OnPropertyChanged("NotesAvailable"); }