public void IsAdminedByTest() { Group group = new Group(); User user = new User(); Assert.IsFalse(group.IsAdminedBy(user)); group.Administrators.Add(user); Assert.IsTrue(group.IsAdminedBy(user)); }
public void IsCreatedByTest() { Group group = new Group(); User user = new User(); Assert.IsFalse(group.IsCreatedBy(user)); group.Creator = user; Assert.IsTrue(group.IsCreatedBy(user)); }
private void AddChildrenToList(Group group, List<Group> list) { foreach (var child in group.Children) { list.Add(child); AddChildrenToList(child, list); } }
public void HasMemberTest() { Group group = new Group(); User user1 = new User(); User user2 = new User(); group.Users.Add(user2); Assert.IsFalse(group.HasMember(user1)); Assert.IsTrue(group.HasMember(user2)); }
public void GetAllSubGroupsTest() { Group group = new Group(); Group group2 = new Group(); group.Children.Add(group2); Group group3 = new Group(); group2.Children.Add(group3); Assert.AreEqual(2, group.GetAllSubGroups().Count()); }
/// <summary> /// Přidání nové skupiny /// </summary> /// <param name="group">skupina</param> /// <param name="user">uživatel, který vytváří skupinu</param> public void Add(User user, Group group) { user.CreatedGroups.Add(group); user.AdminedGroups.Add(group); user.JoinedGroups.Add(group); group.Administrators.Add(user); group.Creator = user; group.Users.Add(user); db.AddToGroupSet(group); db.SaveChanges(); }
public void AddEvent(User user, Group group, DateTime from, DateTime to, String name, String text) { Event ev = new Event(); ev.Group = group; ev.User = user; ev.From = from; ev.To = to; ev.Name = name; ev.Text = text; db.AddToEventSet(ev); db.SaveChanges(); }
public void AddStatus(User user, Group group, Event ev, StatusFormModel formModel) { if (group != null) { if (!group.HasMember(user)) { throw new StatusException("User is not member of group"); } } var status = new Status { Text = formModel.Status, User = user, Group = group, Event = ev }; db.AddToStatusSet(status); // obrázky if (formModel.Images != null) { for (int i = 0; i < formModel.Images.Count; i++) { var uploadedImage = formModel.Images[i]; // vynechat neobrázky if (uploadedImage == null || uploadedImage.ContentLength == 0 || !ImageHelper.IsImage(uploadedImage.ContentType)) { continue; } // vyrobit entitu var img = new Image { Description = formModel.ImageDescriptions[i], }; db.ImageSet.AddObject(img); status.Images.Add(img); // uložit db, aby entita měla id a tudíž se dala vymyslet cesta k obrázku db.SaveChanges(); // uložit soubor imageService.SaveImage(img, uploadedImage.InputStream); } } // soubory if (formModel.Files != null) { for (int i = 0; i < formModel.Files.Count; i++) { var uploadedFile = formModel.Files[i]; if (uploadedFile == null || uploadedFile.ContentLength == 0) { continue; } // vyrobit entitu var file = new File { Description = formModel.FileDescriptions[i], FileName = uploadedFile.FileName, }; db.FileSet.AddObject(file); status.Files.Add(file); // uložit db, aby entita měla id a tudíž se dala vymyslet cesta k souboru db.SaveChanges(); // uložit soubor fileService.SaveFile(file, uploadedFile); } } // odkazy if (formModel.Links != null) { for (int i = 0; i < formModel.Links.Count; i++) { var url = formModel.Links[i]; if (String.IsNullOrWhiteSpace(url)) { continue; } status.Links.Add(new Link { URL = url, Description = formModel.LinkDescriptions[i], }); } } db.SaveChanges(); // přidat do zdí List<User> userList = user.Followers.ToList(); if (group != null) { userList.Union(group.Users); } else { userList.Add(user); } wallService.Add(status, userList.Distinct()); }
/// <summary> /// /// </summary> /// <param name="group"></param> public void Edit(Group group) { db.SaveChanges(); }
/// <summary> /// Create a new Group object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="description">Initial value of the Description property.</param> public static Group CreateGroup(global::System.Int32 id, global::System.String name, global::System.String description) { Group group = new Group(); group.Id = id; group.Name = name; group.Description = description; return group; }
public IQueryable<User> GetUsers(Group grp) { throw new NotImplementedException(); }
public void Edit(Group group) { throw new NotImplementedException(); }
public void Delete(Group grp) { throw new NotImplementedException(); }
public void AddSubGroup(User user, Group group, Group child) { throw new NotImplementedException(); }
public void Add(User user, Group grp) { throw new NotImplementedException(); }
public static void Insert() { #region Insert test data FelBookDBEntities db = new FelBookDBEntities(); #region Vymazání všech tabulek a resetování ID //vymazání tabulek které spojují db.ExecuteStoreCommand("DELETE FROM StatusInformationFiles"); db.ExecuteStoreCommand("DELETE FROM StatusInformationImages"); db.ExecuteStoreCommand("DELETE FROM StatusInformationLinks"); db.ExecuteStoreCommand("DELETE FROM Followings"); db.ExecuteStoreCommand("DELETE FROM GroupAdministration"); db.ExecuteStoreCommand("DELETE FROM MessageRecievers"); db.ExecuteStoreCommand("DELETE FROM MessageReaders"); db.ExecuteStoreCommand("DELETE FROM UserGroupMembership"); db.ExecuteStoreCommand("DELETE FROM WallItemSet"); //vymazání tabulek které obsahují informace db.ExecuteStoreCommand("DELETE FROM ImageSet"); db.ExecuteStoreCommand("DELETE FROM FileSet"); db.ExecuteStoreCommand("DELETE FROM LinkSet"); db.ExecuteStoreCommand("DELETE FROM CommentSet"); db.ExecuteStoreCommand("DELETE FROM StatusSet"); db.ExecuteStoreCommand("DELETE FROM MessageSet"); db.ExecuteStoreCommand("DELETE FROM GroupSet"); db.ExecuteStoreCommand("DELETE FROM UserSet"); //resetování ID -> je spuštěno pouze na tabulky které mají klíč typu UNIQUE, INCREMENT=YES db.ExecuteStoreCommand("DBCC CHECKIDENT (CommentSet, RESEED, 0)"); db.ExecuteStoreCommand("DBCC CHECKIDENT (FileSet, RESEED, 0)"); db.ExecuteStoreCommand("DBCC CHECKIDENT (GroupSet, RESEED, 0)"); db.ExecuteStoreCommand("DBCC CHECKIDENT (ImageSet, RESEED, 0)"); db.ExecuteStoreCommand("DBCC CHECKIDENT (LinkSet, RESEED, 0)"); db.ExecuteStoreCommand("DBCC CHECKIDENT (MessageSet, RESEED, 0)"); db.ExecuteStoreCommand("DBCC CHECKIDENT (StatusSet, RESEED, 0)"); db.ExecuteStoreCommand("DBCC CHECKIDENT (UserSet, RESEED, 0)"); db.ExecuteStoreCommand("DBCC CHECKIDENT (WallItemSet, RESEED, 0)"); #endregion #region naplnění UserSet User usr1 = new User(); usr1.Name = "Jakub"; usr1.Surname = "Novák"; usr1.Created = new DateTime(2008, 3, 1, 7, 0, 0); usr1.LastLogged = DateTime.Now; usr1.Mail = "*****@*****.**"; usr1.Username = "******"; usr1.Title = "Ing."; usr1.TitleAfter = "CSc."; usr1.StudyProgramme = "STM"; usr1.Phone = "0609112567"; usr1.ICQ = "123456789"; usr1.Specialization = "Software engineering"; usr1.ChangePassword("123456"); User usr2 = new User(); usr2.Name = "Jan"; usr2.Surname = "Novák"; usr2.Created = new DateTime(2009, 9, 10, 10, 0, 0); usr2.LastLogged = new DateTime(2010, 10, 10, 10, 0, 0); usr2.Mail = "*****@*****.**"; usr2.Username = "******"; usr2.ChangePassword("123456"); User usr3 = new User(); usr3.Name = "Bedřich"; usr3.Surname = "Červený"; usr3.Created = new DateTime(2007, 4, 8, 11, 5, 4); usr3.LastLogged = new DateTime(2008, 7, 8, 9, 4, 3); usr3.Mail = "*****@*****.**"; usr3.Username = "******"; usr3.ChangePassword("123456"); User usr4 = new User(); usr4.Id = 4; usr4.Name = "Ondřej"; usr4.Surname = "Zelený"; usr4.Created = new DateTime(2004, 2, 2, 8, 8, 5); usr4.LastLogged = new DateTime(2006, 7, 8, 9, 4, 3); usr4.Mail = "*****@*****.**"; usr4.Username = "******"; usr4.ChangePassword("123456"); User usr5 = new User(); usr5.Id = 5; usr5.Name = "Jiří"; usr5.Surname = "Mach"; usr5.Created = new DateTime(2007, 5, 1, 5, 1, 5); usr5.LastLogged = new DateTime(2010, 8, 9, 12, 5, 7); usr5.Mail = "*****@*****.**"; usr5.Username = "******"; usr5.ChangePassword("123456"); User usr6 = new User(); usr6.Id = 6; usr6.Name = "Alena"; usr6.Surname = "Bílá"; usr6.Created = new DateTime(2008, 7, 2, 5, 4, 6); usr6.LastLogged = new DateTime(2009, 4, 1, 13, 4, 10); usr6.Mail = "*****@*****.**"; usr6.Username = "******"; usr6.ChangePassword("123456"); User usr7 = new User(); usr7.Id = 7; usr7.Name = "Květa"; usr7.Surname = "Pampeliškova"; usr7.Created = new DateTime(2007, 6, 3, 2, 2, 11); usr7.LastLogged = new DateTime(2008, 6, 2, 7, 8, 9); usr7.Mail = "*****@*****.**"; usr7.Username = "******"; usr7.ChangePassword("123456"); User usr8 = new User(); usr8.Id = 8; usr8.Name = "Zuzana"; usr8.Surname = "Frydrychová"; usr8.Created = new DateTime(2007, 6, 3, 2, 2, 11); usr8.LastLogged = new DateTime(2008, 6, 2, 7, 8, 9); usr8.Mail = "*****@*****.**"; usr8.Username = "******"; usr8.ChangePassword("123456"); User usr9 = new User(); usr9.Id = 9; usr9.Name = "Andrea"; usr9.Surname = "Senová"; usr9.Created = new DateTime(2004, 1, 6, 2, 9, 12); usr9.LastLogged = new DateTime(2005, 5, 1, 2, 6, 3); usr9.Mail = "*****@*****.**"; usr9.Username = "******"; usr9.ChangePassword("123456"); User usr10 = new User(); usr10.Id = 10; usr10.Name = "Simona"; usr10.Surname = "Červená"; usr10.Created = new DateTime(2006, 2, 6, 2, 9, 9); usr10.LastLogged = new DateTime(2007, 5, 8, 2, 1, 3); usr10.Mail = "*****@*****.**"; usr10.Username = "******"; usr10.ChangePassword("123456"); User usr11 = new User(); usr11.Id = 11; usr11.Name = "Michal"; usr11.Surname = "Stach"; usr11.Created = new DateTime(2005, 2, 6, 2, 10, 12); usr11.LastLogged = new DateTime(2006, 1, 2, 2, 8, 3); usr11.Mail = "*****@*****.**"; usr11.Username = "******"; usr11.ChangePassword("123456"); User usr12 = new User(); usr12.Id = 12; usr12.Name = "Vladimír"; usr12.Surname = "Roubal"; usr12.Created = new DateTime(2003, 8, 6, 4, 7, 9); usr12.LastLogged = new DateTime(2008, 1, 4, 2, 5, 3); usr12.Mail = "*****@*****.**"; usr12.Username = "******"; usr12.ChangePassword("123456"); db.AddToUserSet(usr1); db.AddToUserSet(usr2); db.AddToUserSet(usr3); db.AddToUserSet(usr4); db.AddToUserSet(usr5); db.AddToUserSet(usr6); db.AddToUserSet(usr7); db.AddToUserSet(usr8); db.AddToUserSet(usr9); db.AddToUserSet(usr10); db.AddToUserSet(usr11); db.AddToUserSet(usr12); #endregion #region naplnění MessageSet Message msg1 = new Message(); msg1.Sender = usr1; msg1.Text = "Ahoj jak se máš?"; msg1.Recievers.Add(usr2); msg1.Created = new DateTime(2010, 10, 11, 12, 5, 7); Message msg2 = new Message(); msg2.Sender = usr1; msg2.Recievers.Add(usr2); msg2.Recievers.Add(usr3); msg2.Recievers.Add(usr4); msg2.Recievers.Add(usr5); msg2.Text = "Nezapomeňte dodělat domácí úkol."; msg2.Created = new DateTime(2009, 3, 5, 8, 1, 2); Message msg3 = new Message(); msg3.Sender = usr3; msg3.Recievers.Add(usr1); msg3.ReplyTo = msg2; msg3.Text = "Už jsem ten úkol odevzdal."; msg3.Created = new DateTime(2007, 12, 11, 10, 4, 4); Message msg4 = new Message(); msg4.Sender = usr3; msg4.Recievers.Add(usr1); msg3.ReplyTo = msg2; msg4.Text = "Taky už jsem ho udělal a díky za ty materiály, zejtra vás zvu na pivo."; msg4.Created = new DateTime(2010, 12, 8, 10, 2, 2); Message msg5 = new Message(); msg5.Sender = usr5; msg5.Recievers.Add(usr4); msg5.Text = "Podařilo se mi rozchodit ten server !!!"; msg5.Created = new DateTime(2010, 1, 8, 7, 6, 2); db.AddToMessageSet(msg1); db.AddToMessageSet(msg2); db.AddToMessageSet(msg3); db.AddToMessageSet(msg4); db.AddToMessageSet(msg5); #endregion #region naplnění GroupSet Group grp1 = new Group(); Group grp2 = new Group(); Group grp3 = new Group(); Group grp4 = new Group(); Group grp5 = new Group(); Group grp6 = new Group(); Group grp7 = new Group(); Group grp8 = new Group(); Group grp9 = new Group(); Group grp10 = new Group(); Group grp11 = new Group(); Group grp12 = new Group(); Group grp13 = new Group(); Group grp14 = new Group(); Group grp15 = new Group(); grp1.Name = "Svět"; grp1.Description = "Řídíme svět"; grp1.Creator = usr2; grp1.Children.Add(grp2); grp1.Children.Add(grp3); grp1.Users.Add(usr1); grp1.Users.Add(usr2); grp1.Users.Add(usr3); grp1.Users.Add(usr4); grp1.Users.Add(usr5); usr1.JoinedGroups.Add(grp1); usr2.JoinedGroups.Add(grp2); grp1.Administrators.Add(usr1); grp1.Administrators.Add(usr2); grp2.Name = "Asie"; grp2.Description = "Řídíme asii"; grp2.Parent = grp1; grp2.Creator = usr1; grp2.Administrators.Add(usr1); grp3.Name = "Evropa"; grp3.Description = "Řídíme Evropu"; grp3.Parent = grp2; grp3.Children.Add(grp4); grp3.Creator = usr1; grp3.Administrators.Add(usr1); grp4.Name = "Česká republika"; grp4.Description = "Řídíme Českou republiku"; grp4.Parent = grp3; grp4.Creator = usr1; grp4.Administrators.Add(usr1); grp5.Name = "Slunce"; grp5.Description = "Jsme úplně jiná planeta"; grp5.Creator = usr1; grp5.Administrators.Add(usr1); grp6.Name = "Katedra Kybernetiky"; grp6.Description = "Řešíme hlavne nedeterministické algoritmy"; grp6.Children.Add(grp7); grp6.Children.Add(grp8); grp6.Creator = usr5; grp6.Administrators.Add(usr5); grp7.Name = "Vytěžování dat"; grp7.Description = "Zabíváme se tu dataminingem"; grp7.Parent = grp6; grp7.Creator = usr5; grp7.Administrators.Add(usr5); grp8.Name = "Kybernetika a umělá inteligence"; grp8.Description = "Jedná se o úvodní obecný předmět umožňující studentům pochopit cíle a metody kybernetiky a umělé inteligence."; grp8.Parent = grp6; grp8.Creator = usr5; grp8.Administrators.Add(usr5); grp9.Name = "Katedra matematiky"; grp9.Description = "Stále něco počítáme."; grp9.Children.Add(grp10); grp9.Children.Add(grp11); grp9.Creator = usr7; grp9.Administrators.Add(usr7); grp10.Name = "Úvod do lineární algebry"; grp10.Description = "Matice, zobrazení, polynomy atd"; grp10.Parent = grp9; grp10.Creator = usr9; grp10.Administrators.Add(usr9); grp11.Name = "Matematická logika"; grp11.Description = "PCNF, kvantifikátory, logické operátory atd"; grp11.Parent = grp9; grp11.Creator = usr9; grp11.Administrators.Add(usr9); grp12.Name = "Diskrétní matematika"; grp12.Description = "Počítání modulo a samá přirozená čísla."; grp12.Parent = grp9; grp12.Creator = usr9; grp12.Administrators.Add(usr9); grp13.Name = "Katedra počítačů"; grp13.Description = "Programování a různé techniky při tvorbě softwaru to je naše."; grp13.Children.Add(grp14); grp13.Children.Add(grp15); grp12.Creator = usr10; grp13.Administrators.Add(usr10); grp14.Name = "Teoretická informatika"; grp14.Description = "Teorie grafů a algoritmy ohledně teorie grafů to je hlavní náplň tohoto kurzu."; grp14.Parent = grp13; grp14.Creator = usr10; grp14.Administrators.Add(usr10); grp15.Name = "Softwarové inženýrství"; grp15.Description = "Tak kvůli tomuhle předmětu jsem vůbec napsal tuhle větu :)."; grp15.Parent = grp13; grp15.Creator = usr10; grp15.Administrators.Add(usr10); #endregion #region naplnění StatusSet a zároveň CommentSet Status st1 = new Status(); st1.Text = "Dneska jsem udělal maturitu"; st1.User = usr1; st1.Created = new DateTime(2010, 1, 1, 12, 3, 4); Status st2 = new Status(); st2.Text = "Podařilo se mi tu maturitu dát s vyznamenáním"; st2.User = usr2; st2.Created = new DateTime(2010, 2, 1, 12, 3, 4); Status st3 = new Status(); st3.Text = "Tohle je zajímavá skupina"; st3.User = usr2; st3.Group = grp1; st3.Created = new DateTime(2008, 9, 1, 6, 2, 1); Status st4 = new Status(); st4.Text = "Tady v té skupině řešíme evropu"; st4.User = usr2; st4.Group = grp3; st4.Created = new DateTime(2009, 10, 2, 4, 8, 8); Status st5 = new Status(); st5.Text = "Kdo neskáče není čech !!"; st5.User = usr4; st5.Group = grp4; st5.Created = new DateTime(2010, 2, 4, 7, 1, 2); Comment cmt1 = new Comment(); cmt1.Author = usr3; cmt1.Text = "Ano také si to myslím !!"; cmt1.Created = new DateTime(2008, 10, 10, 7, 2, 3); st3.Comments.Add(cmt1); Comment cmt2 = new Comment(); cmt2.Author = usr5; cmt2.Text = "Tak to jsi frajer!"; cmt2.Created = new DateTime(2010, 1, 1, 12, 20, 10); st1.Comments.Add(cmt2); db.AddToCommentSet(cmt1); db.AddToCommentSet(cmt2); db.AddToStatusSet(st1); db.AddToStatusSet(st2); db.AddToStatusSet(st3); db.AddToStatusSet(st4); db.AddToStatusSet(st5); db.SaveChanges(); #endregion #endregion }
/// <summary> /// Deprecated Method for adding a new object to the GroupSet EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToGroupSet(Group group) { base.AddObject("GroupSet", group); }
/// <summary> /// Vrátí true/false podle toho jeslti je uživatel ve skupině /// </summary> /// <param name="usr">Uživatel</param> /// <param name="grp">Skupina</param> /// <returns>true nebo false podle toho jestli v té skupině je nebo není</returns> public bool IsUserInGroup(User usr, Group grp) { return grp.Users.Contains(usr); }
/// <summary> /// Vrátí uživatelé dané skupiny /// </summary> /// <param name="grp">Skupina</param> /// <returns>Uživatelé skupiny</returns> public IQueryable<User> GetUsers(Group grp) { return grp.Users.AsQueryable(); }
/// <summary> /// Přidá daného uživatele do skupiny, jako parametr je typ členství /// </summary> /// <param name="usr">Uživatel</param> /// <param name="grp">Skupina</param> public void JoinGroup(User usr, Group grp) { usr.JoinedGroups.Add(grp); grp.Users.Add(usr); foreach (var parent in grp.Parents) { usr.JoinedGroups.Add(parent); parent.Users.Add(usr); } db.SaveChanges(); }
/// <summary> /// Přidání nové podgrupy k dané nadgrupě /// </summary> /// <param name="user">Zakladatel skupiny</param> /// <param name="group">ID groupy do které budu přidávat podgrupu</param> /// <param name="child">nová podgrupa</param> public void AddSubGroup(User user, Group group, Group child) { child.Parent = group; group.Children.Add(child); Add(user, child); }
/// <summary> /// Odebere daného uživatele ze skupiny /// </summary> /// <param name="usr">Uživatel který se bude mazat</param> /// <param name="grp">Skupina ze které se bude mazat</param> public void LeaveGroup(User usr, Group grp) { usr.JoinedGroups.Remove(grp); grp.Users.Remove(usr); foreach (var subGroup in grp.GetAllSubGroups()) { usr.JoinedGroups.Remove(subGroup); subGroup.Users.Remove(usr); } db.SaveChanges(); }
public void AddStatus(User user, Group group, StatusFormModel formModel) { throw new NotImplementedException(); }
public void AddStatus(User user, Group group, StatusFormModel formModel) { AddStatus(user, group, null, formModel); }