private void DeleteResult(SampleTestResult result)
 {
     if (_deleteResultCanExecute())
     {
         Data.Delete(result);
     }
 }
        private void AddResult(SampleTestResult previous)
        {
            int i = 0;

            foreach (var r in Results.List)
            {
                var n = r.Name ?? "";
                if (n.StartsWith("R"))
                {
                    n = n.Substring(1);
                }

                if (int.TryParse(n, out var v))
                {
                    i = Math.Max(i, v);
                }
            }

            var test = Data.Add <SampleTestResult>(r =>
            {
                r.Name       = string.Format("R{0}", i + 1);
                r.SampleTest = Model;
                r.UserId     = Model.UserId;
            });

            if (test != null)
            {
                Results.List.Update();
            }
        }
        private TestResultsListViewModel SetResults()
        {
            var vm = _getResults(Model);

            vm.SetSelectAction(async r =>
            {
                await LoadResultAsync(r as SampleTestResult).ConfigureAwait(false);
                if (SelectResultCommand is CommandPropertyHolder nc)
                {
                    nc.CheckCanExecute();
                }
            });

            SampleTestResult selected = null;

            foreach (var result in vm.List)
            {
                if (selected == null)
                {
                    selected = result;
                }
                if (result == Model.Result)
                {
                    selected = result;
                }
            }
            vm.Selected = selected;
            return(vm);
        }
 private async Task SelectResult(SampleTestResult result)
 {
     if (result.Stage == SampleTestResultWorkflow.Validated)
     {
         Model.Result = result;
         await Results.List.RefreshAsync();
     }
 }
//        private Action<LinkedDocument> _createAction;
        public LinkedDocumentsListViewModel(
            SampleTestResult result
//            Expression<Func<LinkedDocument,bool>> filter,
//            Action<LinkedDocument> createAction = null
            ) : base(c => c
                     .StaticFilter(e => e.SampleTestResultId == result.Id)
                     //.DeleteAllowed()
                     .Column()
                     .Header("{Name}").Width(200).Content(s => s.Name)
                     )
        {
//            _createAction = createAction;
        }
        public async Task LoadResultAsync(SampleTestResult target = null)
        {
            await FormHelper.LoadAsync(Model, target).ConfigureAwait(true);

            var state = Workflow.CurrentState;

            if (state == SampleTestWorkflow.Specifications)
            {
                FormHelper.Mode = TestFormMode.Specification;
            }
            //else if (state == SampleTestWorkflow.Running)
            //    FormHelper.Mode = TestFormMode.Capture;
            else
            {
                FormHelper.Mode = TestFormMode.ReadOnly;
            }
        }