/// <summary>
        /// Executes the command operation
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public async override void Execute(object parameter)
        {
            var dictionary = App.Current.Resources;

            try
            {
                var isSucceed = await this.ExecuteAsync(parameter as Institution);

                if (isSucceed)
                {
                    RecipeMessageBox.Show((string)dictionary["pharmacy_edit_success"]);

                    this._vm.SetVisibilities(Visibility.Visible, true);

                    var response = await((App)App.Current).InstitutionClient.GetAllPharmaciesAsync();

                    if (response.IsSuccessStatusCode)
                    {
                        this._vm.Pharmacies = new ObservableCollection <Institution>(response.Content);
                    }
                }
                else
                {
                    RecipeMessageBox.Show((string)dictionary["pharmacy_edit_fail"]);
                }
            }
            catch (Exception)
            {
                RecipeMessageBox.Show((string)dictionary["server_error"]);
            }
            finally
            {
                this._vm.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #2
0
        /// <summary>
        /// Executes command operation
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public async override void Execute(object parameter)
        {
            if (!this._isDoneAvailable)
            {
                return;
            }

            this._isDoneAvailable = false;
            this._vm.SetVisibilities(Visibility.Visible, true);

            var dictionary = App.Current.Resources;

            try
            {
                var added = await this.ExecuteAsync((Medicine)parameter);

                if (added)
                {
                    RecipeMessageBox.Show((string)dictionary["med_add_success"]);
                }
                else
                {
                    RecipeMessageBox.Show((string)dictionary["med_add_fail"]);
                }
            }
            catch
            {
                RecipeMessageBox.Show((string)dictionary["med_add_fail"]);
            }
            finally
            {
                this._isDoneAvailable = true;
                this._vm.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #3
0
        /// <summary>
        /// Executes the command operation
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public async override void Execute(object parameter)
        {
            var dictionary = App.Current.Resources;

            try
            {
                var isSuccessed = await this.ExecuteAsync((Medicine)parameter);

                if (isSuccessed)
                {
                    RecipeMessageBox.Show((string)dictionary["med_del_success"]);

                    this._vm.SetVisibilities(Visibility.Visible, true);

                    var response = await((App)App.Current).MedicineClient.GetAllMedicinesAsync("api/medicines");

                    if (response.IsSuccessStatusCode)
                    {
                        this._vm.Medicines = new ObservableCollection <Medicine>(response.Result);
                    }
                }
                else
                {
                    RecipeMessageBox.Show((string)dictionary["med_del_fail"]);
                }
            }
            catch
            {
                RecipeMessageBox.Show((string)dictionary["med_del_fail"]);
            }
            finally
            {
                this._vm.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #4
0
        /// <summary>
        /// Loads content
        /// </summary>
        /// <returns>nothing</returns>
        public async Task Load()
        {
            // setting visibilities
            this.hospitalsViewModel.SetVisibilities(Visibility.Visible, true);

            // getting message
            var msg = (string)App.Current.Resources["hospitals_load_error"];


            // loading
            try
            {
                var response = await this.client.GetAllHospitalsAsync();

                if (!response.IsSuccessStatusCode)
                {
                    RecipeMessageBox.Show(msg);
                }

                this.hospitalsViewModel.Hospitals = new ObservableCollection <Institution>(response.Content);
                this.hospitalsViewModel.Data      = this.hospitalsViewModel.Hospitals;
            }
            catch
            {
                RecipeMessageBox.Show(msg);
            }
            finally
            {
                this.hospitalsViewModel.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #5
0
        /// <summary>
        /// Executes service operation.
        /// </summary>
        /// <returns>nothing</returns>
        public async Task Execute()
        {
            ((App)App.Current).ProfilesMenuManager = this._profilesMenuManager;

            var load = await this._userInfoLoader.Execute();

            if (load == null)
            {
                RecipeMessageBox.Show((string)App.Current.Resources["load_fail"]);
                return;
            }

            this.InitializeVM(load);
            this.SaveSettings(load);

            this._profilesMenuManager.AddProfiles(load.Profiles);

            if (load.CurrentProfile == "none")
            {
                this._profilesMenuManager.CollapseAll();
                return;
            }

            this._profilesMenuManager.UpdateButtonsVisibilities();
        }
        private async Task <ObservableCollection <MedicinePricePair> > GetMedicinePricePair(IEnumerable <PharmMedicine> medicines)
        {
            var result = new ObservableCollection <MedicinePricePair>();

            foreach (var medicine in medicines)
            {
                var response = await this.medClient.GetMedicineAsync($"api/medicines/{medicine.MedicineId}");

                if (!response.IsSuccessStatusCode)
                {
                    RecipeMessageBox.Show("Couldn't find the medicine.");
                    return(null);
                }

                var medicinePrice = new MedicinePricePair
                {
                    Name  = response.Result.Name,
                    Price = medicine.Price
                };

                result.Add(medicinePrice);
            }

            return(result);
        }
        /// <summary>
        /// Executes command operation.
        /// </summary>
        /// <param name="parameter">Command parameter.</param>
        public async override void Execute(object parameter)
        {
            if (!this._isDoneAvailable)
            {
                return;
            }

            this._isDoneAvailable = false;
            this.viewModel.SetVisibilities(Visibility.Visible, true);

            var dictionary = App.Current.Resources;

            try
            {
                var historyItems = (IEnumerable <RecipeHistoryItem>) this.viewModel.HistoryItems;

                var response = await((App)App.Current).UserApiClient.GetPharmacistByIdAsync(User.Default.Id);

                if (response.Status == Status.Error)
                {
                    RecipeMessageBox.Show((string)dictionary["pharmacy_find_fail"]);
                    return;
                }

                var pharmacyId = response.Result.PharmacyId;

                var recipeHistory = new RecipeHistory
                {
                    CreatedOn  = DateTime.Now,
                    RecipeId   = this.viewModel.Recipe.First().Id,
                    PharmacyId = pharmacyId,
                    Sold       = historyItems.ToList <RecipeHistoryItem>()
                };

                var sellResponse = await this.ExecuteAsync(recipeHistory);

                this.viewModel.Start();
                this.viewModel.Recipe   = null;
                this.viewModel.RecipeId = null;

                if (!sellResponse.IsSuccessStatusCode)
                {
                    RecipeMessageBox.Show((string)dictionary["sell_medicines_fail"]);
                    return;
                }

                RecipeMessageBox.Show((string)dictionary["sell_medicines_success"]);
            }
            catch
            {
                RecipeMessageBox.Show((string)dictionary["recipe_unknown_error"]);
            }
            finally
            {
                this._isDoneAvailable = true;
                this.viewModel.SetVisibilities(Visibility.Collapsed, false);
            }
        }
        public async Task <Recipe> Map(RecipeClient.Recipe recipeFromApi)
        {
            var recipeItems = new ObservableCollection <RecipeItem>();

            var dictionary = App.Current.Resources;

            foreach (var recipeItemFromApi in recipeFromApi.RecipeItems)
            {
                var medicineApiResponse = await this.medicineClient.GetMedicineAsync($"api/medicines/{recipeItemFromApi.MedicineId}");

                if (!medicineApiResponse.IsSuccessStatusCode)
                {
                    RecipeMessageBox.Show((string)dictionary["med_name_fail"]);
                    return(null);
                }

                var recipeItem = new RecipeItem
                {
                    Medicine         = medicineApiResponse.Result,
                    Count            = recipeItemFromApi.Count,
                    CountPerUse      = recipeItemFromApi.CountPerUse,
                    TimesPerUnit     = recipeItemFromApi.TimesPerUnit,
                    UseFrequencyUnit = recipeItemFromApi.UseFrequencyUnit,
                    LeftCount        = recipeItemFromApi.LeftCount
                };

                recipeItems.Add(recipeItem);
            }

            var gettingHospitalNameResponse = await this.userApiClient.GetDoctorByIdAsync(recipeFromApi.DoctorId);

            if (gettingHospitalNameResponse.Status == Status.Error)
            {
                RecipeMessageBox.Show((string)dictionary["hospital_name_fail"]);
                return(null);
            }

            var gettingDoctorFullNameResponse = await this.userApiClient.GetUserAsync(recipeFromApi.DoctorId);

            if (gettingDoctorFullNameResponse.Status == Status.Error)
            {
                RecipeMessageBox.Show((string)dictionary["doc_fail"]);
                return(null);
            }

            return(new Recipe
            {
                CreatedOn = recipeFromApi.CreatedOn,
                HospitalName = gettingHospitalNameResponse.Result.HospitalName,
                Id = recipeFromApi.Id,
                DoctorName = gettingDoctorFullNameResponse.Result.FullName,
                RecipeItems = recipeItems
            });
        }
Пример #9
0
        /// <summary>
        /// Event handler for menu item click.
        /// After this operation user's current profile updates.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Routed event argument</param>
        public async void ChangeProfileEventHandler(object sender, RoutedEventArgs e)
        {
            var item = (MenuItem)sender;

            var dictionary = App.Current.Resources;

            if (item.Header == dictionary[User.Default.CurrentProfile])
            {
                return;
            }

            var client = ((App)App.Current).UserApiClient;

            var currentProfile = (string)item.Header;

            var profileUpdateInfo = new ProfileUpdateInfo
            {
                Id      = User.Default.Id,
                Profile = (string)dictionary[currentProfile]
            };

            var response = await client.UpdateCurrentProfileAsync(profileUpdateInfo);

            if (response.Status == Status.Ok)
            {
                this._vm.CurrentProfile = currentProfile;

                User.Default.CurrentProfile = profileUpdateInfo.Profile;
                User.Default.Save();

                this.UpdateButtonsVisibilities();

                this._vm.PhotoUrl = ConfigurationManager.AppSettings[User.Default.CurrentProfile];

                var app = ((App)App.Current);

                var tokenProvider = app.TokenProvider;

                var tokenResponse = await tokenProvider.RefreshAccessTokenAsync();

                if (tokenResponse == TokenStatus.Error)
                {
                    return;
                }

                app.RiseProfileChanged();

                RecipeMessageBox.Show((string)dictionary["current_update_success"]);
            }
            else
            {
                RecipeMessageBox.Show((string)dictionary["current_update_fail"]);
            }
        }
Пример #10
0
        /// <summary>
        /// Loads unapproved  pharmacy admins.
        /// </summary>
        /// <returns></returns>
        public async Task Load()
        {
            var unapprovedPharmacyAdminsResponse = await this.client.GetUnapprovedPharmacyAdmins();

            if (unapprovedPharmacyAdminsResponse.Status == Status.Error)
            {
                RecipeMessageBox.Show("Couldn't get unapproved hospital admins.");
                return;
            }

            this.viewModel.PharmacyAdmins = new ObservableCollection <UnapprovedPharmacyAdmin>(unapprovedPharmacyAdminsResponse.Result);
        }
        public async Task Load()
        {
            var response = await this.instClient.GetPharmacyMedicinesAsync(this.CurrentPharamcy);

            if (!response.IsSuccessStatusCode)
            {
                RecipeMessageBox.Show("There is no such pharmacy. Please, try again.");
                return;
            }

            this.pharmaciesViewModel.Medicines = await this.GetMedicinePricePair(response.Content);
        }
        public async Task Load()
        {
            var medicineId = await this.GetMedicineId();

            var response = await this.instClient.GetAllSuppliersAsync(medicineId);

            if (!response.IsSuccessStatusCode)
            {
                RecipeMessageBox.Show("Couldn't find medicine suppliers.");
                return;
            }

            this.pharmaciesViewModel.Pharmacies = new ObservableCollection <Institution>(response.Content);
        }
Пример #13
0
        /// <summary>
        /// Executes the command operation
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public async void Execute(object parameter)
        {
            var response = await this._tokenProvider.SignOutAsync();

            if (response == TokenStatus.Error)
            {
                RecipeMessageBox.Show((string)App.Current.Resources["sign_out_fail"]);
                return;
            }

            User.Default.Reset();

            this._hyperlinkService.Navigate <MainWindow, SignIn>();
        }
        private async Task <int> GetMedicineId()
        {
            var response = await this.medClient.GetMedicineAsync($"api/medicines/?medicineName={this.MedicineName}");

            if (!response.IsSuccessStatusCode)
            {
                RecipeMessageBox.Show("Couldn't find the medicine.");
                return(-1);
            }

            int.TryParse(response.Result.Id, out int id);

            return(id);
        }
Пример #15
0
        /// <summary>
        /// Executes doctor approving command
        /// </summary>
        /// <param name="parameter">Command parameter.</param>
        public override async void Execute(object parameter)
        {
            var response = await this.ExecuteAsync((int)parameter);

            if (response.Status == Status.Error)
            {
                RecipeMessageBox.Show("Error occured");
                return;
            }

            RecipeMessageBox.Show("Profile is successfully approved");

            var service = new LoadHospitalAdminApprovalsService(this.viewModel);
            await service.Load();
        }
Пример #16
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public override async void Execute(object parameter)
        {
            this._isSendAvailable = false;
            this._vm.SetVisibilities(Visibility.Visible, true);

            var dictionary = App.Current.Resources;

            try
            {
                var userResponse = await this._userApiClient.GetUserAsync(User.Default.Id);

                if (userResponse.Status == Status.Error)
                {
                    RecipeMessageBox.Show((string)dictionary["mail_get_fail"]);
                    return;
                }

                var email = userResponse.Result.Email;

                var recipeId = (string)parameter;

                var qrSendInfo = new QrSendInfo
                {
                    Email    = email,
                    RecipeId = recipeId
                };

                var qrResponse = await this._recipeClient.SendQrReqeust(qrSendInfo);

                if (!qrResponse.IsSuccessStatusCode)
                {
                    RecipeMessageBox.Show((string)dictionary["qr_send_fail"]);
                    return;
                }

                RecipeMessageBox.Show((string)dictionary["qr_send_success"]);
            }
            catch
            {
                RecipeMessageBox.Show((string)dictionary["qr_send_error"]);
            }
            finally
            {
                this._isSendAvailable = true;
                this._vm.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #17
0
        /// <summary>
        /// Executes the command operation.
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public async void Execute(object parameter)
        {
            var manager = ((App)App.Current).ProfilesMenuManager;

            var response = await this._client.DeleteCurrentProfile(User.Default.CurrentProfile);

            var dictionary = App.Current.Resources;

            if (response.Status == Status.Error)
            {
                RecipeMessageBox.Show((string)dictionary["profile_del_error"]);
                return;
            }

            manager.DeleteProfile(User.Default.CurrentProfile);

            RecipeMessageBox.Show((string)dictionary["profile_del_success"]);
        }
Пример #18
0
        /// <summary>
        /// Handler for new frame
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="eventArgs">Event argument</param>
        private async void FrameHandler(object sender, NewFrameEventArgs eventArgs)
        {
            try
            {
                var bitmapImage = new BitmapImage();

                using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
                {
                    // decoding QR
                    var id = "";

                    await App.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { id = this.GetRecipeId(bitmap).Result; }));

                    // if id is not null end QR decoding and open sell page
                    if (id != null)
                    {
                        this.Stop();
                        this._vm.RecipeId            = id;
                        this._vm.QrDecoderVisibility = Visibility.Hidden;
                        this._vm.ItemsVisibility     = Visibility.Visible;
                        await App.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate
                        {
                            this._vm.FindRecipeCommand.Execute(id);
                        }));

                        SystemSounds.Beep.Play();
                        return;
                    }

                    bitmapImage = this.GetImage(bitmap);
                }

                bitmapImage.Freeze();

                await App.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { this._vm.QrDecoderSource = bitmapImage; }));
            }
            catch
            {
                var dictionary = App.Current.Resources;

                RecipeMessageBox.Show((string)dictionary["qr_decode_error"]);
            }
        }
Пример #19
0
        /// <summary>
        /// Executes the command asynchronously
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public override async void Execute(object parameter)
        {
            if (!this._isDoneAvailable)
            {
                return;
            }

            var dictionary = App.Current.Resources;

            this._isDoneAvailable = false;
            this._vm.SetVisibilities(Visibility.Visible, true);

            try
            {
                var profileInfo = parameter as T;

                var response = await this.ExecuteAsync(profileInfo);

                if (response.Status == Status.Ok)
                {
                    RecipeMessageBox.Show((string)dictionary["profile_add_success"]);

                    var manager = ((App)App.Current).ProfilesMenuManager;

                    manager.AddProfile(this._name);
                }
                else
                {
                    RecipeMessageBox.Show((string)dictionary["profile_add_fail"]);
                }
            }
            catch (Exception)
            {
                RecipeMessageBox.Show((string)dictionary["server_error"]);
            }
            finally
            {
                this._isDoneAvailable = true;
                this._vm.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #20
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public async override void Execute(object parameter)
        {
            if (!this._isFindAvailable)
            {
                return;
            }

            this._isFindAvailable = false;
            this._viewModel.SetVisibilities(Visibility.Visible, true);

            var dictionary = App.Current.Resources;

            try
            {
                var response = await this.ExecuteAsync((string)parameter);

                if (!response.IsSuccessStatusCode)
                {
                    RecipeMessageBox.Show((string)dictionary["recipe_find_fail"]);
                    return;
                }

                var recipe = response.Content;

                var loadService = new LoadRecipesService();

                this._viewModel.Recipe = new ObservableCollection <Models.Recipe>();
                this._viewModel.Recipe.Add(await loadService.Map(recipe));

                this._viewModel.HistoryItems = this.Map(this._viewModel.Recipe.First());
            }
            catch
            {
                RecipeMessageBox.Show((string)dictionary["recipe_find_fail"]);
            }
            finally
            {
                this._isFindAvailable = true;
                this._viewModel.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #21
0
        /// <summary>
        /// Executes the command operation
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public override async void Execute(object parameter)
        {
            if (!this._isSignInAvailable)
            {
                return;
            }

            this._isSignInAvailable = false;

            this._vm.SetVisibilities(Visibility.Visible, Visibility.Collapsed, true);

            var signInInfo = (SignInInfo)parameter;

            var dictionary = App.Current.Resources;

            try
            {
                var status = await this._tokenProvider.SignInAsync(signInInfo.Username, signInInfo.Password);

                if (status == TokenStatus.Error)
                {
                    RecipeMessageBox.Show((string)dictionary["invalid_credentials"]);

                    return;
                }

                User.Default.Username = signInInfo.Username;
                User.Default.Save();

                this._hyperLinkService.Navigate <SignIn, MainWindow>();
            }
            catch (Exception)
            {
                RecipeMessageBox.Show((string)dictionary["server_error"]);
            }
            finally
            {
                this._isSignInAvailable = true;
                this._vm.SetVisibilities(Visibility.Collapsed, Visibility.Visible, false);
            }
        }
Пример #22
0
        public async Task Load()
        {
            if (!this.isLoadAvailable)
            {
                return;
            }

            this.isLoadAvailable = false;
            this.recipesViewModel.SetVisibilities(Visibility.Visible, true);

            var dictionary = App.Current.Resources;

            try
            {
                var response = await this.recipeClient.GetAllAsync <RecipeClient.Recipe>($"api/recipes?patientId={User.Default.Id}");

                if (!response.IsSuccessStatusCode)
                {
                    RecipeMessageBox.Show((string)App.Current.Resources["recipe_load_fail"]);
                    return;
                }

                var recipes = new ObservableCollection <Recipe>();

                foreach (var recipeFromApi in response.Content)
                {
                    recipes.Add(await this.Map(recipeFromApi));
                }

                this.recipesViewModel.Recipes = recipes;
            }
            catch
            {
                RecipeMessageBox.Show((string)dictionary["recipes_unknown_erro"]);
            }
            finally
            {
                this.isLoadAvailable = true;
                this.recipesViewModel.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #23
0
        /// <summary>
        /// Executes the command asynchronously
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public override async void Execute(object parameter)
        {
            if (!this._isSignUpAvailable)
            {
                return;
            }

            this._isSignUpAvailable = false;

            this._vm.SetVisibilities(Visibility.Visible, Visibility.Collapsed, true);

            var dictionary = App.Current.Resources;

            try
            {
                var register = (Register)parameter;

                var response = await this.ExecuteAsync(register);

                if (response.Result.IsSuccessStatusCode)
                {
                    var vm     = new CodeConfirmationViewModel(register.Username);
                    var window = new CodeConfirmation(vm);
                    window.Show();
                }
                else
                {
                    RecipeMessageBox.Show((string)dictionary["register_fail"]);
                }
            }
            catch (Exception)
            {
                RecipeMessageBox.Show((string)dictionary["server_error"]);
            }
            finally
            {
                this._isSignUpAvailable = true;
                this._vm.SetVisibilities(Visibility.Collapsed, Visibility.Visible, false);
            }
        }
Пример #24
0
        /// <summary>
        /// Executes command asynchronously
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public override async void Execute(object parameter)
        {
            if (!this._isConfirmAvailable)
            {
                return;
            }

            this._isConfirmAvailable = false;
            this._vm.SetVisibilities(Visibility.Visible, Visibility.Collapsed, true);

            var dictionary = App.Current.Resources;

            try
            {
                var response = await this.ExecuteAsync((UserVerificationInfo)parameter);

                if (response.Result.StatusCode == HttpStatusCode.BadRequest)
                {
                    RecipeMessageBox.Show((string)dictionary["ver_code_fail"]);
                }
                else if (response.Result.StatusCode == HttpStatusCode.InternalServerError)
                {
                    RecipeMessageBox.Show((string)dictionary["ver_server_error"]);
                }
                else
                {
                    this.ManageWindows();
                }
            }
            catch
            {
                RecipeMessageBox.Show((string)dictionary["server_error"]);
            }
            finally
            {
                this._isConfirmAvailable = true;
                this._vm.SetVisibilities(Visibility.Collapsed, Visibility.Visible, false);
            }
        }
Пример #25
0
        /// <summary>
        /// Executes the command asynchronously
        /// </summary>
        /// <param name="parameter">Command parameter</param>
        public override async void Execute(object parameter)
        {
            if (!this._isDoneAvailable)
            {
                return;
            }

            this._isDoneAvailable = false;
            this._vm.SetVisibilities(Visibility.Visible, true);

            var dictionary = App.Current.Resources;

            try
            {
                var institution = parameter as Institution;
                institution.Type = institution.Type == "0" ? "hospital" : "pharmacy";

                var isSucceed = await this.ExecuteAsync(institution);

                if (isSucceed)
                {
                    RecipeMessageBox.Show((string)dictionary["inst_add_success"]);
                }
                else
                {
                    RecipeMessageBox.Show((string)dictionary["inst_add_fail"]);
                }
            }
            catch (Exception)
            {
                RecipeMessageBox.Show((string)dictionary["server_error"]);
            }
            finally
            {
                this._isDoneAvailable = true;
                this._vm.SetVisibilities(Visibility.Collapsed, false);
            }
        }
Пример #26
0
        /// <summary>
        /// Loads medicines
        /// </summary>
        /// <returns>nothing</returns>
        public async Task Load()
        {
            // setting visibilities
            this.viewModel.SetVisibilities(Visibility.Visible, true);

            // getting messgae
            var msg = (string)App.Current.Resources["med_load_error"];

            // loading
            try
            {
                var response = await this.client.GetAllMedicinesAsync("api/medicines");

                if (!response.IsSuccessStatusCode)
                {
                    RecipeMessageBox.Show(msg);
                }

                if (this.viewModel is MedicinesViewModel)
                {
                    ((MedicinesViewModel)this.viewModel).Medicines = new ObservableCollection <Medicine>(response.Result);
                    ((MedicinesViewModel)this.viewModel).Data      = ((MedicinesViewModel)this.viewModel).Medicines;
                }
                else if (this.viewModel is CreateRecipeViewModel)
                {
                    ((CreateRecipeViewModel)this.viewModel).Medicines = new ObservableCollection <Medicine>(response.Result);
                }
            }
            catch
            {
                RecipeMessageBox.Show(msg);
            }
            finally
            {
                this.viewModel.SetVisibilities(Visibility.Collapsed, false);
            }
        }