public SaveObjectiveFunctionsViewModel(string objectiveFunctionsJson, string defaultDirectoryPath)
        {
            DefaultDirectoryPath = defaultDirectoryPath;

            var objectiveFunctionsJObject  = JObject.Parse(objectiveFunctionsJson);
            var objectiveFunctionArguments = (JArray)objectiveFunctionsJObject["Arguments"];

            ObjectiveFunctions.Clear();
            foreach (var a in objectiveFunctionArguments)
            {
                var jObject = JObject.Parse(a.ToString());
                ObjectiveFunctions.Add(new Models.ObjectiveFunction(jObject));
            }

            var prescriptionsJArray = (JArray)objectiveFunctionsJObject["Prescriptions"];
            var PrescriptionsAll    = prescriptionsJArray.ToObject <List <Models.Prescription> >();

            Prescriptions.Clear();
            foreach (var p in PrescriptionsAll)
            {
                if (ObjectiveFunctions.Where(o => (o.PlanLabel == p.PlanLabel)).Count() > 0)
                {
                    Prescriptions.Add(p);
                }
            }

            OkCommand       = new DelegateCommand(() => { CanExecute = true; });
            CancelCommand   = new DelegateCommand(() => { CanExecute = false; });
            SaveFileCommand = new DelegateCommand(SaveFile);
        }
        public async Task GetPrescriptions()
        {
            IsRefreshing = true;
            var docs = await DatabaseInstance.Database.GetDoctors();

            var myaddress = AccountManager.Instance().GetAddress();
            var webclient = WebClient.WebAPI;

            List <Prescription> prescriptions;

            try
            {
                prescriptions = await webclient.GetPrescriptions(myaddress);
            }
            catch
            {
                IsRefreshing = false;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsRefreshing)));
                return;
            }
            var query = prescriptions.Join(docs,
                                           prescription => prescription.DoctorId,
                                           doc => doc.Address,
                                           (doc, prescription) => (Projection)doc);

            Prescriptions.Clear();
            foreach (var item in query)
            {
                var proj = new Projection();
                proj            = (Projection)item;
                proj.BuyCommand = buy;
                proj.DoctorName = docs.First(x => x.Address == item.DoctorId).Name;
                Prescriptions.Add(proj);
            }
            IsRefreshing = false;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsRefreshing)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Prescriptions)));
        }