public EditCustomerViewModel(contact customer)
        {
            this.currentCustomer = customer;
            this.civilities = Civility.list;
            this.civilityIndex = Civility.indexByValue(customer.civility);
            this.firstname = customer.firstname;
            this.lastname = customer.lastname;
            this.street = customer.street;
            this.city = customer.city;
            this.zip = customer.zip;
            this.country = customer.country;

            foreach (phone p in this.currentCustomer.phones)
            {
                switch (p.description)
                {
                    case "private":
                        this.phonePrivate = p.number;
                        break;
                    case "pro":
                        this.phonePro = p.number;
                        break;
                }
            }

            if(customer.emails.Count != 0)
                this.email = customer.emails.First().email1;

            this.cmdEdit = new RelayCommand<object>(actEdit);
        }
 public void actDelete(contact customer)
 {
     customers.Remove(customer);
     db.contacts.Remove(customer);
     db.SaveChanges();
     NotifyPropertyChanged("customers");
 }
 public DeleteCustomerViewModel(contact contact)
 {
     this.cmdDelete = new RelayCommand<Object>(actDeleteCustomer);
     this.contact = contact;
     this.nbrRequest = contact.requests.Count();
     this.nbrStudent = contact.students.Count();
 }
        public void actViewDetail(contact customer)
        {
            Tab tab = new Tab(customer.lastname, new View.Customer.ShowCustomerUCView(customer), null);

            parentVM.customerTabs.Add(tab);
            parentVM.selectedTab = tab;
        }
        public void actAddTab(contact customer, UserControl view)
        {
            Tab tab = new Tab(customer.lastname, view,customer, null);

            this.customerTabs.Add(tab);
            this.selectedTab = tab;

            mediator.Register(Helper.Event.DELETE_CUSTOMER, this);
        }
 public AddStudentViewModel(contact customer)
 {
     this.customer = customer;
     this.birthday = DateTime.Now;
     this.kinships = Kinship.list;
     this.genders = Gender.list;
     this.cmdAdd = new RelayCommand<object>(actAdd);
     this.parentVM = parentVM;
 }
 public AddRequestViewModel(contact customer)
 {
     this.cmdAdd = new RelayCommand<Object>(actAdd);
     this.customer = customer;
     this.students = customer.students.ToList();
     this.student = this.students.First();
     this.journeys = Helper.Enum.Journey.list;
     this.journey = this.journeys.First();
 }
        public void actEdit(contact contact)
        {
            EditCustomerViewModel editCustomerViewModel = new EditCustomerViewModel(contact);
            EditCustomerView editCustomerView = new EditCustomerView();

            editCustomerView.DataContext = editCustomerViewModel;
            editCustomerViewModel.CloseActionFormAdd = new Action(() => editCustomerView.Close());

            editCustomerView.Show(); 
        }
        public void actDelete(contact customer)
        {
            DeleteCustomerViewModel deleteCustomerViewModel = new DeleteCustomerViewModel(customer);
            DeleteCustomerView deleteCustomerView = new DeleteCustomerView(customer);

            deleteCustomerView.DataContext = deleteCustomerViewModel;
            deleteCustomerViewModel.CloseActionDelete = new Action(() => deleteCallback(deleteCustomerView,customer));

            deleteCustomerView.ShowDialog();
        }
        public void actViewDetail(contact customer)
        {

            View.Customer.ShowCustomerUCView showCustommerView = new View.Customer.ShowCustomerUCView(customer);
            showCustommerView.DataContext = new ViewModel.Customer.ShowCustomerViewModel(customer, parentVM);
            Tab tab = new Tab(customer.lastname, showCustommerView, null);

            parentVM.customerTabs.Add(tab);
            parentVM.selectedTab = tab;
        }
        public ShowCustomerViewModel(contact customer)
        {
            var ongoningRequestQuery = customer.requests.Where(r => r.events.Last().event_types.order != 100);
            this.customer = customer;
            this.students = new ObservableCollection<student>(customer.students.ToList());
            this.ongoingRequests = new ObservableCollection<request>(ongoningRequestQuery.ToList());
            if (customer.phones.Count > 0)
                this.phone1 = customer.phones.First();
            if (customer.phones.Count > 1)
                this.phone2 = customer.phones.ElementAt(2);
            if (customer.emails.Count > 0)
                this.email = customer.emails.First();

            this.cmdEditCustomer = new RelayCommand<Object>(actEditCustomer);
            this.cmdDeleteCustomer = new RelayCommand<Object>(actDeleteCustomer);
            this.cmdAddStudent = new RelayCommand<Object>(actAddStudent);
            this.cmdEditStudent = new RelayCommand<student>(actEditStudent);
            this.cmdDeleteStudent = new RelayCommand<student>(actDeleteStudent);
            this.cmdAddRequest = new RelayCommand<student>(actAddRequest);
            this.cmdShowRequest = new RelayCommand<request>(actShowRequest);

            mediator.Register(Helper.Event.ADD_STUDENT, this);
            mediator.Register(Helper.Event.DELETE_STUDENT, this);
        }
        public void actAdd(object obj)
        {
            bool error = false;
            this.validFirstname = new Validation();
            this.validLastname = new Validation();

            contact customer = new contact();

            // Validation prénom
            if (!this.firstname.Equals(""))
            {
                customer.firstname = this.firstname;
                this.validFirstname.message = "Valide";
                this.validFirstname.valid = true;
                NotifyPropertyChanged("validFirstname");
            }
            else
            {
                this.validFirstname.message = "Champ requis";
                this.validFirstname.valid = false;
                NotifyPropertyChanged("validFirstname");
                error = true;
            }

            // Validation nom
            if (!this.lastname.Equals(""))
            {
                customer.lastname = this.lastname;
                this.validLastname.message = "Valide";
                this.validLastname.valid = true;
                NotifyPropertyChanged("validLastname");
            }
            else
            {
                this.validLastname.message = "Champ requis";
                this.validLastname.valid = false;
                NotifyPropertyChanged("validLastname");
                error = true;
            }

            customer.street = this.street;
            customer.city = this.city;
            customer.zip = this.zip;
            customer.country = this.country;

            if (!this.phonePrivate.Equals(""))
            {
                phone phone = new phone();
                phone.number = this.phonePrivate;
                phone.description = "private";
                phone.main = true;
                customer.phones.Add(phone);
            }

            if (!this.phonePro.Equals(""))
            {
                phone phone = new phone();
                phone.number = this.phonePro;
                phone.description = "pro";
                phone.main = true;
                customer.phones.Add(phone);
            }

            if (!this.email.Equals(""))
            {
                email email = new email();
                email.email1 = this.email;
                email.main = true;
                customer.emails.Add(email);
            }

            if (!error)
            {
                customer.add_date = DateTime.Now;
                customer.civility = civilities.ElementAt(civilityIndex).getValue();

                // Enregistre dans la base
                db.contacts.Add(customer);
                db.SaveChanges();

                mediator.NotifyViewModel(Helper.Event.ADD_CUSTOMER, customer);

                this.CloseActionFormAdd();
            }
        }
        public void openShowCustomerView(contact customer)
        {
            ShowCustomerUCView showCustomerView = new ShowCustomerUCView();
            showCustomerView.DataContext = new ShowCustomerViewModel(customer);

            ((CustomerViewModel)mainTabs["customer"].tabViewModel).actAddTab(customer, showCustomerView);
        }
        public void openEditCustomerView(contact customer)
        {
            EditCustomerViewModel editCustomerViewModel = new EditCustomerViewModel(customer);
            EditCustomerView editCustomerView = new EditCustomerView();

            editCustomerView.DataContext = editCustomerViewModel;
            editCustomerViewModel.CloseActionFormEdit = new Action(() => editCustomerView.Close());

            editCustomerView.Show();
        }
        public void openAddStudentView(contact customer)
        {
            AddStudentViewModel addStudentViewModel = new AddStudentViewModel(customer);
            AddStudentView addStudentView = new AddStudentView();

            addStudentView.DataContext = addStudentViewModel;
            addStudentViewModel.CloseActionAdd = new Action(() => addStudentView.Close());

            addStudentView.Show();
        }
 public void actViewDetail(contact customer)
 {
     mediator.openShowCustomerView(customer);
     mediator.Register(Helper.Event.DELETE_CUSTOMER, this);
     mediator.Register(Helper.Event.DELETE_CUSTOMER, mediator.mainTabs["customer"].tabViewModel);
 }
 private void deleteCallback(DeleteCustomerView view, contact customer)
 {
     view.Close();
     customers.Remove(customer);
     NotifyPropertyChanged("customers");
 }