public async void DeleteAsync(long vacationId)
        {
            IsBusy = true;
            try
            {
                var srvc = new VacationService.VacationServiceClient();
                var resultTask = srvc.VacationRemoveAsync(vacationId).ContinueWith((t) => 
                    {
                        if (t.Exception != null)
                            throw t.Exception;

                        if (!string.IsNullOrEmpty(t.Result.Error))
                            throw new Exception(t.Result.Error);
                    }, 
                    CancellationToken.None, TaskContinuationOptions.AttachedToParent, TaskScheduler.FromCurrentSynchronizationContext());

                await resultTask;

                IsDeleted = true;
            }
            catch(Exception ex)
            {
                Error = ex.ToString();
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 2
0
        private async void SaveAsync(VacationService.Vacation vacationToSave)
        {
            IsBusy = true;
            try
            {
                var task = Task.Factory.StartNew(() => {
                    var sc = new VacationService.VacationServiceClient();
                    try
                    {
                        var updateRes = Vacation.Id == 0
                            ? sc.VacationInsert(vacationToSave)
                            : sc.VacationUpdate(vacationToSave);

                        if (!string.IsNullOrWhiteSpace(updateRes.Error))
                            throw new Exception(updateRes.Error);

                        return updateRes.Value;
                    }
                    finally
                    {
                        try { sc.Close(); } catch { }
                    }
                });

                Vacation.CopyObjectFrom(await task);
                
                Error = null;
                IsBusy = false;
                IsEditMode = false;
            }
            catch (Exception ex)
            {
                IsBusy = false;
                Error = GetExceptionText(nameof(SaveAsync), ex);
            }
        }
Exemplo n.º 3
0
        private async void DeleteAsync()
        {
            if (Vacation.Id == 0)
            {
                IsDeleted = true;
                return;
            }

            IsBusy = true;
            try
            {
                var sc = new VacationService.VacationServiceClient();
                var waittask = sc.VacationRemoveAsync(Vacation.Id);
                await waittask.ContinueWith(t =>
                {
                    try
                    {
                        if (t.Exception != null)
                        {
                            Error = GetExceptionText(nameof(DeleteAsync), t.Exception);
                        }
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(t.Result.Error))
                            {
                                Error = t.Result.Error;
                            }
                            else
                            {
                                Error = null;
                                VacationForEdit = null;
                                IsDeleted = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error = GetExceptionText(nameof(DeleteAsync), ex);
                    }
                    finally
                    {
                        try { sc.Close(); } catch { }
                        IsBusy = false;
                    }
                },
                    System.Threading.CancellationToken.None,
                    TaskContinuationOptions.AttachedToParent,
                    TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                IsBusy = false;
                Error = GetExceptionText(nameof(DeleteAsync), ex);
            }
        }
        private async void SaveAsync(VacationService.VacationFunctionalGroup groupToSave, Action sucessEndAction = null, Action errorEndAction = null)
        {
            SaveEmployees(groupToSave);
            IsBusy = true;
            try
            {
                var task = Task.Factory.StartNew(() => {
                    var sc = new VacationService.VacationServiceClient();
                    try
                    {
                        var updateRes = Group.Id == 0
                            ? sc.VacationFunctionalGroupInsert(groupToSave)
                            : sc.VacationFunctionalGroupUpdate(groupToSave);

                        if (!string.IsNullOrWhiteSpace(updateRes.Error))
                        {
                            throw new Exception(updateRes.Error);
                        }
                        else
                        {
                            Owner.RunUnderDispatcher(new Action(() => 
                            {
                                this.Group.CopyObjectFrom(updateRes.Value);

                                IsEmpty = Group.Id == 0;
                                Error = null;
                                IsBusy = false;
                                IsEditMode = false;
                                sucessEndAction?.Invoke();
                            }));
                        }
                    }
                    finally
                    {
                        try { sc.Close(); } catch { }
                    }
                });

                await task;
            }
            catch (Exception ex)
            {
                IsBusy = false;
                Error = GetExceptionText(nameof(SaveAsync), ex);
                errorEndAction?.Invoke();
            }
        }