Example #1
0
        public void SeedData()
        {
            Tag tag1 = Tags.Add(new Tag {
                Name = "Artist"
            }).Entity;
            Tag tag2 = Tags.Add(new Tag {
                Name = "Likes hiking"
            }).Entity;
            Tag tag3 = Tags.Add(new Tag {
                Name = "Likes cooking"
            }).Entity;
            Tag tag4 = Tags.Add(new Tag {
                Name = "Vegan"
            }).Entity;

            User mary = Users.Add(new User {
                Name = "Mary", Wall = new Models.Wall()
            }).Entity;
            User john = Users.Add(new User {
                Name = "John", Wall = new Models.Wall(),
            }).Entity;
            User louise = Users.Add(new User {
                Name = "Louise", Wall = new Models.Wall()
            }).Entity;

            UserTag maryTag1 = new UserTag {
                User = mary, Tag = tag1
            };
            UserTag maryTag2 = new UserTag {
                User = mary, Tag = tag2
            };
            UserTag louiseTag2 = new UserTag {
                User = louise, Tag = tag2
            };
            UserTag louiseTag3 = new UserTag {
                User = louise, Tag = tag3
            };

            mary.UserTags.Add(maryTag1);
            mary.UserTags.Add(maryTag2);

            louise.UserTags.AddRange(new UserTag[] { louiseTag2, louiseTag3 });

            Post post1 = new Models.Post {
                Content = "hello", User = mary, DatePosted = DateTime.Now, Wall = john.Wall
            };
            Post post2 = new Models.Post {
                Content = "hi!", User = mary, DatePosted = DateTime.Now, Wall = louise.Wall
            };
            Post post3 = new Models.Post {
                Content = "hello again!", User = john, DatePosted = DateTime.Now, Wall = mary.Wall
            };
            Post post4 = new Models.Post {
                Content = "post4", User = john, DatePosted = DateTime.Now, Wall = louise.Wall
            };

            Posts.AddRange(post1, post2, post3, post4);
            UserTags.AddRange(maryTag1, maryTag2, louiseTag2, louiseTag3);
            SaveChanges();
        }
Example #2
0
        public bool ContainsTag(ITag tag)
        {
            Check.Argument.IsNotNull(tag, "tag");
            Check.Argument.IsNotEmpty(tag.Name, "tag.Name");

            return(UserTags.Any(ut => ut.Tag.Name == tag.Name));
        }
Example #3
0
        public void RemoveTag(ITag tag)
        {
            Check.Argument.IsNotNull(tag, "tag");
            Check.Argument.IsNotEmpty(tag.Name, "tag.Name");

            UserTags.Remove(UserTags.SingleOrDefault(st => st.Tag.Name == tag.Name));
        }
Example #4
0
 public Player(string token, DataRow dbRow)
 {
     Token       = token;
     Id          = (int)dbRow["id"];
     Username    = (string)dbRow["username"];
     Tags        = (UserTags)(int)dbRow["tags"];
     currentMode = (PlayModes)(sbyte)dbRow["last_played_mode"];
 }
Example #5
0
        public void RemoveTag(ITag tag)
        {
            Check.Argument.IsNotNull(tag, "tag");
            Check.Argument.IsNotEmpty(tag.Name, "tag.Name");

            //It should load all UserTags then remove the desired tag
            UserTags.Remove(UserTags.FirstOrDefault(t => t.Name == tag.Name));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            UserTags userTags = await db.UserTags.FindAsync(id);

            db.UserTags.Remove(userTags);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "UserTagsId,UserId,TagId,Name")] UserTags userTags)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userTags).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstName", userTags.UserId);
            return(View(userTags));
        }
Example #8
0
        public void AddTag(ITag tag)
        {
            Check.Argument.IsNotNull(tag, "tag");
            Check.Argument.IsNotEmpty(tag.Id, "tag.Id");
            Check.Argument.IsNotEmpty(tag.Name, "tag.Name");

            if (!ContainsTag(tag))
            {
                UserTags.Add(new UserTag {
                    Tag = (Tag)tag
                });
            }
        }
        // GET: UserTags/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserTags userTags = await db.UserTags.FindAsync(id);

            if (userTags == null)
            {
                return(HttpNotFound());
            }
            return(View(userTags));
        }
Example #10
0
    protected void TagShare_Click(object sender, EventArgs e)
    {
        List <ListItem> checkedItems = new List <ListItem>();

        foreach (ListItem item in FriendList.Items)
        {
            if (item.Selected)
            {
                checkedItems.Add(item);
            }
        }

        var fb = new FacebookClient(Session["AccessToken"].ToString());

        int x = 10, y = 10;

        UserTags[] tags = new UserTags[checkedItems.Count];

        for (int i = 0; i < checkedItems.Count; i++)
        {
            ListItem item = checkedItems[i];

            UserTags tag = new UserTags();
            tag.tag_uid = long.Parse(item.Value);
            tag.x       = x;
            tag.y       = y;

            tags[i] = tag;

            x += 10;
            y += 10;
        }

        string sportsperson = ViewState["SportsPerson"].ToString();

        var parameters = new Dictionary <string, object>();

        parameters["name"]    = "If " + ViewState["FBName"] + " was a sports person, he would have been " + sportsperson;
        parameters["tags"]    = tags;
        parameters["TestPic"] = new FacebookMediaObject
        {
            ContentType = "image/jpeg",
            FileName    = sportsperson + ".jpg"
        }.SetValue(File.ReadAllBytes(Server.MapPath("~\\Images\\" + sportsperson + ".jpg")));

        dynamic res = fb.Post("me/Photos", parameters);

        Status.Text = "Photo Uploaded. Photo ID: " + res.id;
    }
        // GET: UserTags/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserTags userTags = await db.UserTags.FindAsync(id);

            if (userTags == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstName", userTags.UserId);
            return(View(userTags));
        }
Example #12
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var tag = await _context.Tags.FindAsync(request.TagId);

                if (tag == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { course = " could not find tag" });
                }

                var user = await _context.Users.FindAsync(request.UserId.ToString());

                if (user == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { User = "******" });
                }

                var members =
                    await _context.UserTags.SingleOrDefaultAsync(x =>
                                                                 x.TagId == tag.Id && x.AppUserId == user.Id);

                if (members != null)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Members = "already member of this tag" });
                }

                members = new UserTags
                {
                    Tag     = tag,
                    AppUser = user,
                };

                _context.UserTags.Add(members);

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

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

                throw new Exception("problem saving changes");
            }
Example #13
0
 public bUserInfo(int ID, string Name, int TimeZone, byte CountryID, UserTags Tags, PlayModes PlayMode,
                  float Longitude, float Latitude, int GlobalRank)
 {
     this.ID = ID;
     if (this.ID < 0)
     {
         this.ID = -this.ID;
     }
     else
     {
         IsValidId = (this.ID != 0);
     }
     this.Name       = Name;
     this.TimeZone   = TimeZone;
     this.CountryID  = CountryID;
     this.Tags       = Tags;
     this.PlayMode   = PlayMode;
     this.Longitude  = Longitude;
     this.Latitude   = Latitude;
     this.GlobalRank = GlobalRank; //NOTE: It can not be this
 }
Example #14
0
        public bUserInfo(SerializationReader r)
        {
            ID = r.ReadInt32();
            if (ID < 0)
            {
                ID = -ID;
            }
            else
            {
                IsValidId = (ID != 0);
            }
            Name      = r.ReadString();
            TimeZone  = r.ReadByte() - 24;
            CountryID = r.ReadByte();
            var b = r.ReadByte();

            Tags       = ((UserTags)b & (UserTags)(-225));
            PlayMode   = (PlayModes)Math.Max(0, Math.Min(3, (b & 224) >> 5));
            Longitude  = r.ReadSingle();
            Latitude   = r.ReadSingle();
            GlobalRank = r.ReadInt32();
        }
Example #15
0
        public static void Save()
        {
            XmlElement config = XmlHelper.CreateDocument(RootTag);

            XmlElement dirs = config.EnsureChildElement("Directories");
            {
                dirs.SetString("Game", GameDirectory);
                dirs.SetString("Working", WorkingDirectory);
                dirs.SetString("CVS", CVSDirectory);
            }

            XmlElement reserves = config.EnsureChildElement("Reserves");

            {
                reserves.SetUInt32("Absolute", AbsoluteReserve);
                reserves.SetUInt32("Relative", RelativeReserve);
            }

            UserTags.Save(config.EnsureChildElement("UserTags"));
            Codepage.Serial(config);

            config.GetOwnerDocument().Save(ConfigFile);
        }
Example #16
0
        public double GetTopicTagStatistic(Topic topic)
        {
            var results = this.GetResults(topic).ToList();
            var users = results.Select(r => r.User).ToList();
            if (users.Count == 0 || results.Count == 0)
            {
                return 0;
            }
            // Масив типу : юзер - його теги і їх значення 
            var usersWithTags = new List<UserTags>();
            foreach (var user in users)
            {
                var temp = new UserTags { Id = user.Id };
                temp.Tags = new Dictionary<int, double>();
                if (this.GetUserTagScores(user).Count() == 0)
                {
                    return 0;
                }
                foreach (var tag in this.GetUserTagScores(user))
                {
                    temp.Tags.Add(tag.TagId, tag.Score);
                }
                usersWithTags.Add(temp);
            }

            // Масив типу : тег - ( значення тегу певного юзера, результат тесту того ж юзера) 
            var tagValueScores = new Dictionary<int, List<KeyValuePair<double, double>>>();

            foreach (var userWithTag in usersWithTags)
            {
                if (userWithTag.Tags == null)
                {
                    return 0;
                }
                foreach (var tag in userWithTag.Tags)
                {
                    var item = new KeyValuePair<double, double>(userWithTag.Tags[tag.Key], results.First(x => x.User.Id == userWithTag.Id).Score.ScaledScore.Value * 100);
                    
                    if (!tagValueScores.Keys.Contains(tag.Key))
                    {
                        tagValueScores.Add(tag.Key, new List<KeyValuePair<double, double>> { item });
                    }
                    else
                    {
                        tagValueScores[tag.Key].Add(item);
                    }
                }
            }

            var generalAmount = 0;
            var successAmount = 0;

            foreach (var tagValueScore in tagValueScores)
            {
                tagValueScore.Value.Sort(Comparer);
                for (int i = 0; i < tagValueScore.Value.Count; i++)
                {
                    for (int j = 0; j < tagValueScore.Value.Count; j++)
                    {
                        if (Math.Abs(tagValueScore.Value[i].Key - tagValueScore.Value[j].Key) < 20)
                        {
                            if (Math.Abs(tagValueScore.Value[i].Value - tagValueScore.Value[j].Value) < 20)
                            {
                                successAmount++;
                            }
                            generalAmount++;
                        }
                        
                    }
                }
                
            }

            return 1.0 * successAmount / generalAmount;
        }
Example #17
0
        public double GetTopicTagStatistic(Topic topic)
        {
            var results = this.GetResults(topic).ToList();
            var users   = results.Select(r => r.User).ToList();

            if (users.Count == 0 || results.Count == 0)
            {
                return(0);
            }
            // Масив типу : юзер - його теги і їх значення
            var usersWithTags = new List <UserTags>();

            foreach (var user in users)
            {
                var temp = new UserTags {
                    Id = user.Id
                };
                temp.Tags = new Dictionary <int, double>();
                if (this.GetUserTagScores(user).Count() == 0)
                {
                    return(0);
                }
                foreach (var tag in this.GetUserTagScores(user))
                {
                    temp.Tags.Add(tag.TagId, tag.Score);
                }
                usersWithTags.Add(temp);
            }

            // Масив типу : тег - ( значення тегу певного юзера, результат тесту того ж юзера)
            var tagValueScores = new Dictionary <int, List <KeyValuePair <double, double> > >();

            foreach (var userWithTag in usersWithTags)
            {
                if (userWithTag.Tags == null)
                {
                    return(0);
                }
                foreach (var tag in userWithTag.Tags)
                {
                    var item = new KeyValuePair <double, double>(userWithTag.Tags[tag.Key], results.First(x => x.User.Id == userWithTag.Id).Score.ScaledScore.Value * 100);

                    if (!tagValueScores.Keys.Contains(tag.Key))
                    {
                        tagValueScores.Add(tag.Key, new List <KeyValuePair <double, double> > {
                            item
                        });
                    }
                    else
                    {
                        tagValueScores[tag.Key].Add(item);
                    }
                }
            }

            var generalAmount = 0;
            var successAmount = 0;

            foreach (var tagValueScore in tagValueScores)
            {
                tagValueScore.Value.Sort(Comparer);
                for (int i = 0; i < tagValueScore.Value.Count; i++)
                {
                    for (int j = 0; j < tagValueScore.Value.Count; j++)
                    {
                        if (Math.Abs(tagValueScore.Value[i].Key - tagValueScore.Value[j].Key) < 20)
                        {
                            if (Math.Abs(tagValueScore.Value[i].Value - tagValueScore.Value[j].Value) < 20)
                            {
                                successAmount++;
                            }
                            generalAmount++;
                        }
                    }
                }
            }

            return(1.0 * successAmount / generalAmount);
        }
Example #18
0
 public void RemoveAllTags()
 {
     UserTags.Clear();
 }
Example #19
0
 public void RemoveAllTags()
 {
     //It should load all UserTags then clear the collection
     UserTags.Clear();
 }