HasMember() public method

Má člena
public HasMember ( User user ) : bool
user User testovaný uživatel
return bool
示例#1
0
        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));
        }
示例#2
0
        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());
        }
示例#3
0
        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());
        }