private async void SaveCommandExecute() { try { if (!ValidateForm()) { return; } Messenger.Default.Send(new LoadingMessage(true)); if (editMode) { await myCompanyClient.TravelRequestService.Update(this.travelRequest); } else { TravelRequest.TravelRequestId = await myCompanyClient.TravelRequestService.Add(this.travelRequest); } await UploadNewAttachments(); foreach (int attachmentId in removedAttachments) { await myCompanyClient.TravelAttachmentService.Delete(attachmentId); } navService.NavigateToTravelRequestList(); } catch (Exception) { Messenger.Default.Send(new LoadingMessage(false)); CustomDialogMessage message = new CustomDialogMessage(() => { }, StringResources.UnexpectedError, Visibility.Collapsed); Messenger.Default.Send <CustomDialogMessage>(message); } }
private static void ShowErrorMessage(string textMessage) { CustomDialogMessage message = new CustomDialogMessage(async() => { await SecurityService.Logout(); }, textMessage, Visibility.Collapsed); Messenger.Default.Send <CustomDialogMessage>(message); Messenger.Default.Send(new LoadingMessage(false)); }
private void HandleDialogMessage(CustomDialogMessage msg) { IsVisibleDialog = true; msg.CancelAction = () => { IsVisibleDialog = false; }; DialogMessage = msg; }
private void CancelCommandExecute() { if (isDirty) { CustomDialogMessage message = new CustomDialogMessage(() => { navService.NavigateToTravelRequestList(); }, String.Format(Resources.Strings.StringResources.ConfirmCancelMessage), Visibility.Visible); Messenger.Default.Send <CustomDialogMessage>(message); } else { navService.NavigateToTravelRequestList(); } }
private void RemoveTravelRequestExecute(int id) { // Get the travel request to remove. TravelRequest travelToRemove = this.travelsList.FirstOrDefault(t => t.TravelRequestId == id); CustomDialogMessage message = new CustomDialogMessage(async() => { // Remove travel request in the UI list RemoveFromList(travelToRemove); // Remove travel request in BBDD await this.myCompanyClient.TravelRequestService.Delete(id); }, String.Format(Resources.Strings.StringResources.ConfirmDeleteMessage, travelToRemove.Name), Visibility.Visible); Messenger.Default.Send <CustomDialogMessage>(message); }
/// <summary> /// Initialize Data. /// </summary> public async Task InitializeData() { try { Messenger.Default.Send(new LoadingMessage(true)); TravelsCount = await myCompanyClient.TravelRequestService.GetAllCount(this.filter, (int)TravelRequestStatus.Approved); this.pagConfig = new PaginationConfig(this.travelsCount, PAGESIZE); NavigateToPage(this.pagConfig.NumberOfPageSelected); } catch (Exception) { CustomDialogMessage message = new CustomDialogMessage(() => { }, StringResources.UnexpectedError, Visibility.Collapsed); Messenger.Default.Send <CustomDialogMessage>(message); } }
/// <summary> /// Initialize form data /// </summary> /// <param name="travelRequest">travel request to edit</param> public async Task InitializeData(TravelRequest travelRequest) { Messenger.Default.Send(new LoadingMessage(true)); try { this.PropertyChanged -= TravelRequestFormViewModel_PropertyChanged; isDirty = false; editMode = travelRequest.TravelRequestId > 0; TravelRequest = travelRequest; this.removedAttachments = new List <int>(); var employees = await myCompanyClient.EmployeeService.GetEmployees(); EmployeesList = new ObservableCollection <Employee>(employees); AttachmentsList = new ObservableCollection <TravelAttachment>(); NewAttachmentName = String.Empty; if (editMode) { this.TravelRequest = await myCompanyClient.TravelRequestService.Get(travelRequest.TravelRequestId, PictureType.Small); if (TravelRequest.TravelAttachments != null) { AttachmentsList = new ObservableCollection <TravelAttachment>(TravelRequest.TravelAttachments); } } SetSelectableDates(); this.PropertyChanged += TravelRequestFormViewModel_PropertyChanged; this.TravelRequest.PropertyChanged += TravelRequestFormViewModel_PropertyChanged; } catch (Exception) { CustomDialogMessage message = new CustomDialogMessage(() => { }, StringResources.UnexpectedError, Visibility.Collapsed); Messenger.Default.Send <CustomDialogMessage>(message); } finally { Messenger.Default.Send(new LoadingMessage(false)); } }
private async void NavigateToPage(int pageToNavigate) { try { Messenger.Default.Send(new LoadingMessage(true)); ResetPaginator(); var travels = await myCompanyClient.TravelRequestService.GetAllTravelRequests(this.filter, (int)TravelRequestStatus.Approved, PictureType.Small, this.pagConfig.PageSize, pageToNavigate - 1); TravelsList = new ObservableCollection <TravelRequest>(travels); PagesList = new ObservableCollection <PageItem>(CalculatePaginator()); } catch (Exception) { CustomDialogMessage message = new CustomDialogMessage(() => { }, StringResources.UnexpectedError, Visibility.Collapsed); Messenger.Default.Send <CustomDialogMessage>(message); } finally { Messenger.Default.Send(new LoadingMessage(false)); } }
private async void DownloadAttachmentCommandExecute(TravelAttachment attachment) { Messenger.Default.Send(new LoadingMessage(true)); try { TravelAttachment travelAttachment = await myCompanyClient.TravelAttachmentService.Get(attachment.TravelAttachmentId); string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string filePath = Path.Combine(folderPath, travelAttachment.FileName); FileStream fileStream = File.Create(filePath); fileStream.Write(travelAttachment.Content, 0, travelAttachment.Content.Length); fileStream.Flush(); fileStream.Close(); Messenger.Default.Send(new LoadingMessage(false)); System.Diagnostics.Process.Start(filePath); } catch (Exception) { Messenger.Default.Send(new LoadingMessage(false)); CustomDialogMessage message = new CustomDialogMessage(() => { }, StringResources.UnexpectedError, Visibility.Collapsed); Messenger.Default.Send <CustomDialogMessage>(message); } }