Example #1
0
        public MainCRMViewModel()
        {
            Messenger.Default.Register<NotificationMessage>(this, (message) =>
            {
                switch (message.Notification)
                {
                    case "CloseMainCRMWindow":
                        App.Current.Shutdown();
                        break;
                }
            });

            int userId = ApplicationState.GetValue<Int32>("EmployeeID");
            Employee u = null;
            using (dbContext db = new dbContext())
            {
                u = db.Employee.SingleOrDefault(item => item.EmployeeId == userId);
                this.employeer = u;
                u.LastLog = DateTime.Now;
                if (u.NumberOfLogs == null)
                {
                    u.NumberOfLogs = 1;
                }
                else
                {
                    u.NumberOfLogs += 1;
                }
                db.SaveChanges();
            }
        }
Example #2
0
 public LogBookListViewModel()
 {
     int userId = ApplicationState.GetValue<Int32>("EmployeeID");
     using (dbContext db = new dbContext())
     {
         Employeer = db.Employee.Find(userId);
     }
     GetEmployeers();
     GetLogs();
 }
Example #3
0
 public CustomerListViewModel()
 {
     using (dbContext db = new dbContext())
     {
         //Employeer = db.Employee.Find(ApplicationState.GetValue<Int32>("EmployeeID"));
         Employeer = db.Employee.Find(2);
         db.CustomerGroup.OrderBy(item => item.Name).ToList();
         CustomerGroupList = db.CustomerGroup.Local;
     }
        GetCustomers();
 }
Example #4
0
        public LogBookViewModel(int CustomerId)
        {
            this.ContactDate = DateTime.Now;
            int userId = ApplicationState.GetValue<Int32>("EmployeeID");

            using (dbContext db = new dbContext())
            {
                Employeer = db.Employee.Find(userId);
                Customer = db.Customer.Find(CustomerId);

                db.CustomerContactType.ToList().OrderBy(item => item.Name);
                this.CustomerContactTypeList = db.CustomerContactType.Local;
            }
        }
Example #5
0
        public CustomerViewModel(int CustomerID = 0, CustomerTemp ct = null )
        {
            int userId = ApplicationState.GetValue<Int32>("EmployeeID");
            this.ShowView2Command = new RelayCommand(this.ShowView2CommandExecute);  // ??
            this.db = new dbContext();
            this.Items = new Dictionary<string, object>();
            employeer = this.db.Employee.SingleOrDefault(item => item.EmployeeId == userId);

            this.SelectedItems = new Dictionary<string, object>();

            if (CustomerID == 0)
            {

                this.isNew = true;
                this.customer = new Customer();
                if (ct != null)
                {
                    this.ct = ct;
                    this.customer.AccountMarketer = db.Employee.SingleOrDefault(item => item.EmployeeId == userId);
                }
                this.customer.CreateDate = DateTime.Now;
                this.SelectedItems = new Dictionary<string, object>();

            }
            else
            {
                this.isNew = false;
                this.customer = this.db.Customer.Where(s => s.CustomerId == CustomerID).FirstOrDefault<Customer>();
                if (ct != null)
                {
                    this.ct = ct;
                    this.customer.AccountMarketer = db.Employee.SingleOrDefault(item => item.EmployeeId == userId);
                }
            }

            if (this.CustomerContact == null)
            {
                this.CustomerContactList = new ObservableCollection<CustomerContact>();
            }
            else
            {
                this.CustomerContactList = new ObservableCollection<oneCRM.Model.CustomerContact>(this.CustomerContact);
            }

            if (this.LogBook == null)
            {
                this.LogBookList = new ObservableCollection<Model.LogBook>();
            }
            else
            {
                this.LogBookList = new ObservableCollection<Model.LogBook>(this.LogBook);
            }

            if (this.CustomerAktywa == null)
            {
                this.CustomerAktywaList = new ObservableCollection<CustomerAktywa>();
            }
            else
            {
                this.CustomerAktywaList = new ObservableCollection<CustomerAktywa>(this.CustomerAktywa);
            }

            if (this.CustomerZatrudnienie == null)
            {
                this.CustomerZatrudnienieList = new ObservableCollection<CustomerZatrudnienie>();
            }
            else
            {
                this.CustomerZatrudnienieList = new ObservableCollection<CustomerZatrudnienie>(this.CustomerZatrudnienie);
            }

            if (this.CustomerPrzychody == null)
            {
                this.CustomerPrzychodyList = new ObservableCollection<CustomerPrzychody>();
            }
            else
            {
                this.CustomerPrzychodyList = new ObservableCollection<CustomerPrzychody>(this.CustomerPrzychody);
            }

            GetLists();
            Items.Clear();
            foreach (var item in CustomerGroupList)
            {
                Items.Add(item.Name, item);
            }
            SelectedItems.Clear();
            if(this.CustomerGroup != null)
            {
                foreach (CustomerGroup a in this.CustomerGroup.Where(item => item.isSelected == true))
                {
                    this.SelectedItems.Add(a.Name, a);
                }
            }
            db.SaveChanges();
        }