예제 #1
0
        public void GroupAdd()
        {
            Group group = new Group();

            string name1 = "maichao";
            string company1 = "ynu";
            string position1 = "student";

            Person person1 = new Person { Name = name1, Company = company1, Position = position1 };

            group.AddPerson(person1);

            Assert.AreEqual(1, group.Amount);

            string name2 = "mai";
            string company2 = "ynu";
            string position2 = "graduate";

            Person person2 = new Person { Name = name2, Company = company2, Position = position2 };

            group.AddPerson(person2);

            Assert.AreEqual(2, group.Amount);

            Assert.AreNotEqual(group.Persons[0], group.Persons[1]);
        }
예제 #2
0
        public GroupWindow(ref Services services, ref Group group, EditMode mode)
        {
            InitializeComponent();
            this.services = services;
            this.group = group;
            this.mode = mode;

            InitializeUI();
        }
예제 #3
0
        public ModifyGroupWindow(ref Services services, ref Group curGroup, ref Person person, ModifyGroupMode mode)
        {
            InitializeComponent();
            this.services = services;
            this.curGroup = curGroup;
            this.person = person;
            this.mode = mode;

            InitializeUI();
        }
예제 #4
0
        public void DeleteGroup(Group group)
        {
            Group groupDefault = this.SearchGroup("Default")[0];

            // move its contacts to default group
            foreach (Person person in group.Persons)
            {
                groupDefault.AddPerson(person);
            }

            // delete it
            groups.Remove(this.SearchGroupById(group.Id));
        }
예제 #5
0
        public void GeatherData(ref Group group)
        {
            foreach (var item in grid.Children)
            {
                if (item is TextBox)
                {
                    TextBox textBox = item as TextBox;
                    object tag = textBox.Tag;
                    PropertyInfo tagProperty = tag as PropertyInfo;

                    Type t = typeof(Group);
                    var properties = t.GetProperties();

                    foreach (PropertyInfo property in properties)
                    {
                        if (tagProperty != null && tagProperty.Name == property.Name)
                        {
                            if (property.PropertyType.ToString() == "System.String")
                            {
                                property.SetValue(group, textBox.Text);
                            }
                            else if (property.PropertyType.ToString() == "System.Int32")
                            {
                                // dont't need to set amount
                            }
                            else
                            {
                                if (!property.PropertyType.IsGenericType)
                                {
                                    var instance = Activator.CreateInstance(property.PropertyType, textBox.Text);
                                    property.SetValue(group, instance);
                                }
                                // don't have to handle persons, user will maintain it.
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var group = new Domain.Group
                {
                    Id               = request.Id,
                    navn             = request.navn,
                    beskrivelse      = request.beskrivelse,
                    aktiv            = request.aktiv,
                    aktiv_til_og_med = request.aktiv_til_og_med,
                    opprettet        = request.opprettet,
                    groupType        = request.groupType,
                    OrganisationId   = request.organisation
                };

                _context.Groups.Add(group);

                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName ==
                                                                     _userAccessor.GetCurrentUsername());

                var admin = new UserGroup
                {
                    AppUser    = user,
                    Group      = group,
                    GroupAdmin = true,
                    DateJoined = DateTime.Now
                };

                _context.UserGroups.Add(admin);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
예제 #7
0
        public List<Group> SearchPerson(string condition)
        {
            List<Group> resGroup = new List<Group>();

            foreach (var group in groups)
            {
                Group g = new Group() { Name = group.Name };
                var persons = group.Persons;

                foreach (var person in persons)
                {
                    Type t = typeof(Person);

                    var properties = t.GetProperties();

                    foreach (var property in properties)
                    {
                        object value = property.GetValue(person);

                        if (value != null && value.ToString() == condition)
                        {
                            if (!resGroup.Contains(g))
                            {
                                resGroup.Add(g);
                            }

                            if (!g.Persons.Contains(person))
                            {
                                g.AddPerson(person);
                            }
                        }
                    }
                }
            }

            return resGroup;
        }
예제 #8
0
        public void GroupSearchPerson()
        {
            Group group = new Group();

            string name1 = "maichao";
            string company1 = "ynu";
            string position1 = "student";

            Person person1 = new Person { Name = name1, Company = company1, Position = position1 };

            group.AddPerson(person1);

            string name2 = "mai";
            string company2 = "ynu";
            string position2 = "graduate";

            Person person2 = new Person { Name = name2, Company = company2, Position = position2 };

            group.AddPerson(person2);

            string name3 = "chao";
            string company3 = "ynu";
            string position3 = "ynu";

            Person person3 = new Person { Name = name3, Company = company3, Position = position3 };

            group.AddPerson(person3);

            var ans1 = group.SearchPerson("mai");

            Assert.IsNotNull(ans1);
            Assert.AreEqual(1, ans1.Count);

            var ans2 = group.SearchPerson("ynu");

            Assert.IsNotNull(ans2);
            Assert.AreEqual(3, ans2.Count);
        }
예제 #9
0
        public void GroupGetPersons()
        {
            Group group = new Group();

            string name1 = "maichao";
            string company1 = "ynu";
            string position1 = "student";

            Person person1 = new Person { Name = name1, Company = company1, Position = position1 };

            group.AddPerson(person1);

            string name2 = "mai";
            string company2 = "ynu";
            string position2 = "graduate";

            Person person2 = new Person { Name = name2, Company = company2, Position = position2 };

            group.AddPerson(person2);

            List<Person> persons = group.Persons;

            Assert.IsNotNull(persons);
            Assert.AreEqual(2, group.Amount);
        }
예제 #10
0
        public void ContactsAdd()
        {
            Contacts contacts = new Contacts();

            Group group1 = new Group();

            string name1 = "maichao";
            string company1 = "ynu";
            string position1 = "student";

            Person person1 = new Person { Name = name1, Company = company1, Position = position1 };

            group1.AddPerson(person1);

            Assert.AreEqual(1, group1.Amount);

            string name2 = "mai";
            string company2 = "ynu";
            string position2 = "graduate";

            Person person2 = new Person { Name = name2, Company = company2, Position = position2 };

            group1.AddPerson(person2);

            Group group2 = new Group();

            string name3 = "chao";
            string company3 = "ynu";
            string position3 = "graduate";

            Person person3 = new Person { Name = name3, Company = company3, Position = position3 };

            group2.AddPerson(person3);

            Group group3 = new Group();

            string name4 = "maichao";
            string company4 = "ynu";
            string position4 = "student";

            Person person4 = new Person { Name = name4, Company = company4, Position = position4 };

            group3.AddPerson(person4);

            Assert.AreEqual(1, group3.Amount);

            string name5 = "mai";
            string company5 = "ynu";
            string position5 = "graduate";

            Person person5 = new Person { Name = name5, Company = company5, Position = position5 };

            group3.AddPerson(person5);

            contacts.AddGroup(group1);
            contacts.AddGroup(group2);
            contacts.AddGroup(group3);

            Assert.AreEqual(4, contacts.GroupsAmount);
            Assert.AreEqual(5, contacts.PersonsAmount);
        }
예제 #11
0
 public void AddPersonToGroup(Person person, Group group)
 {
     this.SearchGroupById(group.Id).AddPerson(person);
 }
예제 #12
0
 public void AddGroup(Group group)
 {
     groups.Add(group);
 }
예제 #13
0
 public Contacts()
 {
     groups = new List<Group>();
     Group group = new Group() { Name = "Default" };
     this.AddGroup(group);
 }
예제 #14
0
 public void UpdateGroup(Group group)
 {
     this.SearchGroupById(group.Id).UpdateInfo(group);
 }
예제 #15
0
 private void MenuItem_Click_GroupsNew(object sender, RoutedEventArgs e)
 {
     Group newGroup = new Group();
     GroupWindow groupWindow = new GroupWindow(ref services, ref newGroup, EditMode.New);
     groupWindow.ShowDialog();
     LoadData(services.GetGroups());
 }
예제 #16
0
        public void ContactsSearchGroup()
        {
            Contacts contacts = new Contacts();

            string name1 ="family";
            string name2 ="work";
            string name3 ="other";

            Group group1 = new Group() { Name = name1 };
            Group group2 = new Group() { Name = name2 };
            Group group3 = new Group() { Name = name3 };

            contacts.AddGroup(group1);
            contacts.AddGroup(group2);
            contacts.AddGroup(group3);

            var res = contacts.SearchGroup("work");

            Assert.AreEqual(1, res.Count);
        }
예제 #17
0
 public void MovePersonToGroup(Person person, Group curGroup, Group newGroup)
 {
     contacts.MovePersonToGroup(person, curGroup, newGroup);
 }
예제 #18
0
        public void SaveData()
        {
            //Contacts1 contacts1 = new Contacts1() { Name = "waef" };

            //FileStream fileStream = new FileStream("data.dat", FileMode.Create, FileAccess.Write);
            //BinaryFormatter binaryFormatter = new BinaryFormatter();
            //binaryFormatter.Serialize(fileStream, contacts1);

            Contacts contacts = new Contacts();

            Group group1 = new Group();

            string name1 = "maichao";
            string company1 = "ynu";
            string position1 = "student";

            Person person1 = new Person { Name = name1, Company = company1, Position = position1 };

            group1.AddPerson(person1);

            Assert.AreEqual(1, group1.Amount);

            string name2 = "mai";
            string company2 = "ynu";
            string position2 = "graduate";

            Person person2 = new Person { Name = name2, Company = company2, Position = position2 };

            group1.AddPerson(person2);

            Group group2 = new Group();

            string name3 = "chao";
            string company3 = "ynu";
            string position3 = "graduate";

            Person person3 = new Person { Name = name3, Company = company3, Position = position3 };

            group2.AddPerson(person3);

            Group group3 = new Group();

            string name4 = "maichao";
            string company4 = "ynu";
            string position4 = "student";

            Person person4 = new Person { Name = name4, Company = company4, Position = position4 };

            group3.AddPerson(person4);

            Assert.AreEqual(1, group3.Amount);

            string name5 = "mai";
            string company5 = "ynu";
            string position5 = "graduate";

            Person person5 = new Person { Name = name5, Company = company5, Position = position5 };

            group3.AddPerson(person5);

            string name = "maimai";
            string company = "ynu";
            string position = "graduate";

            Person person = new Person { Name = name, Company = company, Position = position };

            group1.AddPerson(person);
            group2.AddPerson(person);
            group3.AddPerson(person);

            contacts.AddGroup(group1);
            contacts.AddGroup(group2);
            contacts.AddGroup(group3);

            FileStream fileStream = new FileStream("data.dat", FileMode.Create, FileAccess.Write);
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            binaryFormatter.Serialize(fileStream, person1);
            //BinaryDataAccess bda = new BinaryDataAccess();
            //bda.SaveData(contacts, "data.dat");
        }
예제 #19
0
 public void UpdateGroup(Group group)
 {
     contacts.UpdateGroup(group);
 }
예제 #20
0
 public void AddGroup(Group group)
 {
     contacts.AddGroup(group);
 }
예제 #21
0
 public void AddPersonToGroup(Person person, Group group)
 {
     contacts.AddPersonToGroup(person, group);
 }
예제 #22
0
        public void GroupNew()
        {
            string name = "family";

            Group group = new Group();

            Assert.IsNotNull(group.Id);
            Assert.AreEqual(0, group.Amount);

            group.Name = name;
            Assert.AreEqual(name, group.Name);
        }
예제 #23
0
 public void DeleteGroup(Group group)
 {
     contacts.DeleteGroup(group);
 }
예제 #24
0
        public void GroupSearchPersonById()
        {
            Group group = new Group();

            string name1 = "maichao";
            string company1 = "ynu";
            string position1 = "student";

            Person person1 = new Person { Name = name1, Company = company1, Position = position1 };

            group.AddPerson(person1);

            string name2 = "mai";
            string company2 = "ynu";
            string position2 = "graduate";

            Person person2 = new Person { Name = name2, Company = company2, Position = position2 };

            group.AddPerson(person2);

            Person person = group.SearchPersonById(person1.Id);

            Assert.IsNotNull(person);
            Assert.AreEqual(person1.Id, person.Id);
            Assert.AreEqual(name1, person.Name);
            Assert.AreEqual(company1, person.Company);
            Assert.AreEqual(position1, person.Position);
        }
예제 #25
0
        public void LoadContacts()
        {
            //BinaryDataAccess bda = new BinaryDataAccess();
            //this.contacts = bda.LoadData("data.dat");

            Group group1 = new Group();
            group1.Name = "Family";

            string name1 = "maichao";
            string company1 = "ynu";
            string position1 = "student";

            Person person1 = new Person { Name = name1, Company = company1, Position = position1 };

            Pair<string, string> num1 = new Pair<string, string>("187", "cellphone");
            Pair<Guid, Pair<string, string>> phone1 = new Pair<Guid, Pair<string, string>>(Guid.NewGuid(), num1);

            person1.AddPhone(phone1);

            Pair<string, string> num2 = new Pair<string, string>("187", "cellphone");
            Pair<Guid, Pair<string, string>> phone2 = new Pair<Guid, Pair<string, string>>(Guid.NewGuid(), num2);

            person1.AddPhone(phone2);

            group1.AddPerson(person1);

            string name2 = "mai";
            string company2 = "ynu";
            string position2 = "graduate";

            Person person2 = new Person { Name = name2, Company = company2, Position = position2 };

            group1.AddPerson(person2);

            Group group2 = new Group();
            group2.Name = "Work";

            string name3 = "chao";
            string company3 = "ynu";
            string position3 = "graduate";

            Person person3 = new Person { Name = name3, Company = company3, Position = position3 };

            group2.AddPerson(person3);

            Group group3 = new Group();
            group3.Name = "Other";

            string name4 = "maichao";
            string company4 = "ynu";
            string position4 = "student";

            Person person4 = new Person { Name = name4, Company = company4, Position = position4 };

            group3.AddPerson(person4);

            string name5 = "mai";
            string company5 = "ynu";
            string position5 = "graduate";

            Person person5 = new Person { Name = name5, Company = company5, Position = position5 };

            group3.AddPerson(person5);

            string name = "maimai";
            string company = "ynu";
            string position = "graduate";

            Person person = new Person { Name = name, Company = company, Position = position };

            group1.AddPerson(person);
            group2.AddPerson(person);
            group3.AddPerson(person);

            contacts.AddGroup(group1);
            contacts.AddGroup(group2);
            contacts.AddGroup(group3);
        }
예제 #26
0
파일: Group.cs 프로젝트: ChaoMai/learning
 public void UpdateInfo(Group group)
 {
     this.Name = group.Name;
 }
예제 #27
0
 public void MovePersonToGroup(Person person, Group curGroup, Group newGroup)
 {
     this.SearchGroupById(newGroup.Id).AddPerson(person);
     this.SearchGroupById(curGroup.Id).DeletePerson(person);
 }