Example #1
0
 public static Task<List<Timesheet>> GetTimesheets(TimesheetFilterObject tfo)
 {
     var task = new TaskCompletionSource<List<Timesheet>>();
     var cee = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
     cee.GetTimesheetsCompleted += (s, e) => task.SetResult(e.Result);
     cee.GetTimesheetsAsync(tfo);
     return task.Task;
 }
        private void ProcessSearchFilter()
        {
            TimesheetFilterObject tfo = new TimesheetFilterObject();

            if (mUserId > 0)
            {
                tfo.UserId = mUserId;
            }

            tfo.Year = Year;

            if (Month != "All")
            {
                tfo.Month = DateTime.ParseExact(Month, "MMMM", CultureInfo.InvariantCulture).Month;
            }

            //if (Week != "All") { tfo.Week = Int32.Parse(Week); }

            tfo.Status = Status;

            if (SelectedUser != null && SelectedUser.Id < 0 && Categories.Any())
            {
                tfo.CategoryIds = Categories.Select(x => x.Id).ToList();
            }

            var getTimesheetsByUser = DatabaseLoader.GetTimesheets(tfo);

            List<Task> tasks = new List<Task>();
            tasks.Add(getTimesheetsByUser);

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                Timesheets = getTimesheetsByUser.Result;

                CMS.UiFactory.StartNew(() =>
                {
                    RaisePropertyChanged("Timesheets");
                    mAddingNewWeek = false;
                    AddTimesheetButton.RaiseCanExecuteChanged();
                });
            });
        }