public MainWindowViewModel(IServiceProvider serviceProvider, ProfileManagementViewModel profileManagementViewModel, SimConnectManagerViewModel simConnectManagerViewModel)
        {
            _serviceProvider      = serviceProvider;
            ProfileManagement     = profileManagementViewModel;
            SimConnectManager     = simConnectManagerViewModel;
            _profileManager       = serviceProvider.GetRequiredService <ProfileManager>();
            _deviceBindingManager = serviceProvider.GetRequiredService <DeviceBindingManager>();
            _logger = serviceProvider.GetRequiredService <ILogger <MainWindowViewModel> >();

            WeakEventManager <ProfileManager, ProfileChangedEventArgs> .AddHandler(_profileManager, nameof(ProfileManager.CurrentProfileChanged), ProfileManager_CurrentProfileChanged);

            _profileEditor = new BindingProfileEditorViewModel(_serviceProvider, _profileManager.GetCurrentProfile());
            _profileEditor.CommandApplyChanges.CanExecuteChanged  += ProfileEditorCommandApplyChanges_CanExecuteChanged;
            _profileEditor.CommandRevertChanges.CanExecuteChanged += ProfileEditorCommandRevertChanges_CanExecuteChanged;

            _commandApplyProfileChanges = new NotifiedRelayCommand(async o =>
            {
                await _deviceBindingManager.DisableAsync(ProfileEditor.Model);
                ProfileEditor.CommandApplyChanges.Execute(o);
                if (_profileManager.GetCurrentProfile() == ProfileEditor.Model)
                {
                    await _deviceBindingManager.EnableAsync(_profileManager.GetCurrentProfile());
                }
            }, o => ProfileEditor.CommandApplyChanges.CanExecute(o), this, nameof(ProfileEditor));

            _commandRevertProfileChanges = new NotifiedRelayCommand(ProfileEditor.CommandApplyChanges.Execute, ProfileEditor.CommandRevertChanges.CanExecute, this, nameof(ProfileEditor));
        }
Beispiel #2
0
        public ActionResult FromQuoteToProfile(int clientId)
        {
            Client client = null;

            using (var db = new MyDbContext())
            {
                var query = from b in db.ClientsTable
                            select b;

                foreach (var item in query)
                {
                    if (item.ClientId == clientId)
                    {
                        client = item;
                    }
                }
            }
            var clientProfile    = new ClientProfile();
            var profileViewModel = new ProfileManagementViewModel()
            {
                ClientProfile = clientProfile,
                Client        = client
            };

            return(View("ProfileManagementPage", profileViewModel));
        }
Beispiel #3
0
 public ProfileManagementWindowViewModel(ProfileManagementViewModel profileManagementViewModel)
 {
     ProfileManagement = profileManagementViewModel;
 }
Beispiel #4
0
        public ActionResult SignIn(ClientLoginViewModel viewModel)
        {
            if (string.IsNullOrEmpty(viewModel.Client.Email) || string.IsNullOrEmpty(viewModel.Client.Password))
            {
                viewModel.OutcomeOfValidatingLogin = "******";
                return(View("SignInPage", viewModel));
            }

            var emailValidator = new EmailAddressAttribute();

            if (!emailValidator.IsValid(viewModel.Client.Email))
            {
                viewModel.OutcomeOfValidatingLogin = "******";
                return(View("SignInPage", viewModel));
            }

            using (var db = new MyDbContext())
            {
                var query = from b in db.ClientsTable
                            orderby b.ClientId
                            select b;
                bool isClient = false;
                foreach (var item in query)
                {
                    if (item.Email == viewModel.Client.Email && item.Password == viewModel.Client.Password)
                    {
                        isClient = true;
                        viewModel.Client.ClientId = item.ClientId;
                        break;
                    }
                }
                if (isClient)
                {
                    /*bool isFirstTime = true;
                     * var queryProfile = from b in db.ClientProfileTable
                     *                                 select b;
                     * ClientProfile profile = null;
                     * foreach(var item in queryProfile)
                     * {
                     *      if (item.Client == viewModel.Client)
                     *      {
                     *              isFirstTime = false;
                     *              profile = item;
                     *      }
                     *
                     * }
                     *
                     * if (isFirstTime == true)
                     * {*/
                    var clientProfile    = new ClientProfile();
                    var profileViewModel = new ProfileManagementViewModel()
                    {
                        ClientProfile = clientProfile,
                        Client        = viewModel.Client
                    };

                    return(View("ProfileManagementPage", profileViewModel));

                    /*}
                     * else
                     * {
                     *      //return Content("Is not first time user");
                     *      var fuelQuote = new FuelQuote
                     *      {
                     *              DeliveryAddress = profile.Address1
                     + " " + profile.Address2 + ", "
                     + profile.City + ", "
                     + profile.State + ", "
                     + profile.Zipcode
                     +      };
                     +      var fuelQuoteViewModel = new FuelQuoteViewModel
                     +      {
                     +              ClientId = viewModel.Client.ClientId,
                     +              FuelQuote = fuelQuote,
                     +      };
                     +      return View("FuelQuoteForm", fuelQuoteViewModel);
                     + }*/
                }
                else
                {
                    viewModel.OutcomeOfValidatingLogin = "******";
                    return(View("SignInPage", viewModel));
                }
            }
        }
Beispiel #5
0
        public ActionResult ManagingProfile(int clientId, ProfileManagementViewModel profileManagmentViewModel)
        {
            if (string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.Name) ||
                string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.Address1) ||
                string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.City) ||
                string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.State) ||
                string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.Zipcode))
            {
                var client = new Client {
                    ClientId = clientId
                };
                var clientProf = new ClientProfile {
                    ClientProfileId = clientId
                };
                profileManagmentViewModel = new ProfileManagementViewModel
                {
                    Client        = client,
                    ClientProfile = clientProf,
                    OutcomeOfValidatingProfiles = "SomeNullInput"
                };
                return(View("ProfileManagementPage", profileManagmentViewModel));
            }
            int  tempNumber     = 0;
            bool zipCodeIsValid = Int32.TryParse(profileManagmentViewModel.ClientProfile.Zipcode, out tempNumber);

            if (!zipCodeIsValid)
            {
                var client = new Client {
                    ClientId = clientId
                };
                var clientProf = new ClientProfile {
                    ClientProfileId = clientId
                };
                profileManagmentViewModel = new ProfileManagementViewModel
                {
                    Client        = client,
                    ClientProfile = clientProf,
                    OutcomeOfValidatingProfiles = "InvalidZipCode"
                };
                return(View("ProfileManagementPage", profileManagmentViewModel));
            }
            using (var db = new MyDbContext())
            {
                ClientProfile temp = db.ClientProfileTable.SingleOrDefault(x => x.ClientProfileId == clientId);
                if (temp != null)
                {
                    temp.Name     = profileManagmentViewModel.ClientProfile.Name;
                    temp.Address1 = profileManagmentViewModel.ClientProfile.Address1;
                    temp.Address2 = profileManagmentViewModel.ClientProfile.Address2;
                    temp.City     = profileManagmentViewModel.ClientProfile.City;
                    temp.State    = profileManagmentViewModel.ClientProfile.State;
                    temp.Zipcode  = profileManagmentViewModel.ClientProfile.Zipcode;
                    db.SaveChanges();
                }
                else
                {
                    var newProfile = new ClientProfile
                    {
                        ClientProfileId = clientId,
                        Name            = profileManagmentViewModel.ClientProfile.Name,
                        Address1        = profileManagmentViewModel.ClientProfile.Address1,
                        Address2        = profileManagmentViewModel.ClientProfile.Address2,
                        City            = profileManagmentViewModel.ClientProfile.City,
                        State           = profileManagmentViewModel.ClientProfile.State,
                        Zipcode         = profileManagmentViewModel.ClientProfile.Zipcode
                    };
                    db.ClientProfileTable.Add(newProfile);
                    db.SaveChanges();
                }

                var fuelQuote = new FuelQuote
                {
                    DeliveryAddress = profileManagmentViewModel.ClientProfile.Address1
                                      + " " + profileManagmentViewModel.ClientProfile.Address2 + ", "
                                      + profileManagmentViewModel.ClientProfile.City + ", "
                                      + profileManagmentViewModel.ClientProfile.State + ", "
                                      + profileManagmentViewModel.ClientProfile.Zipcode
                };
                var fuelQuoteViewModel = new FuelQuoteViewModel
                {
                    ClientId  = clientId,
                    FuelQuote = fuelQuote,
                };
                return(View("FuelQuoteForm", fuelQuoteViewModel));
            }
        }