Exemplo n.º 1
0
        public Dictionary <string, Models.Friends.Linking> GetLinksUser(string userId)
        {
            try{
                var catUser = db.linkusercategories.Where(x => x.UserId == userId).ToList().GroupBy(p => p.Category);
                Dictionary <string, Models.Friends.Linking> dictUser = new Dictionary <string, Models.Friends.Linking>();
                foreach (var item in catUser)
                {
                    var itemx = (from f1 in db.linkfriendcategories
                                 join f2 in db.linkfriends on f1.IdFriend equals f2.IdFriend
                                 where f2.IdUser == userId && f1.IdCategory == item.Key
                                 select f1).ToList();

                    int    catId   = item.Key;
                    string cat     = item.Key.ToString();
                    string nameCat = db.categories.Where(id => id.Id == catId).First().Category1;
                    Models.Friends.Linking obLink = new Models.Friends.Linking();
                    obLink.CategoryId   = catId;
                    obLink.CategoryName = nameCat;
                    obLink.friends      = new Dictionary <string, string>();
                    dictUser.Add(cat, obLink);
                    foreach (var itemNew in itemx)
                    {
                        if (dictUser[cat].friends.ContainsKey(itemNew.IdFriend))
                        {
                            dictUser[cat].friends[itemNew.IdFriend] = dictUser[cat].friends[itemNew.IdFriend] + ',' + itemNew.Tag;
                        }
                        else
                        {
                            dictUser[cat].friends.Add(itemNew.IdFriend, itemNew.Tag);
                        }
                    }
                }
                return(dictUser);
            }
            catch (Exception) { return(null); }
        }
Exemplo n.º 2
0
        public Dictionary <string, Models.Friends.Linking> GetFriends(string userId)
        {
            var friendsCat = (from f1 in db.linkfriends
                              join f2 in db.friends on f1.IdFriend equals f2.IdFriend
                              join f3 in db.linkfriendcategories on f2.IdFriend equals f3.IdFriend
                              where f1.IdUser == userId
                              select f3).ToList();//retreive all the friends for the specific user and their categories+tag
            Dictionary <string, Models.Friends.Linking> dict = new Dictionary <string, Models.Friends.Linking>();

            foreach (var item in friendsCat)
            {
                //categoryName+categoryId+listOfFriends-tags
                int catId = item.IdCategory;
                if (!dict.ContainsKey(catId.ToString()))
                {
                    var resultLink = friendsCat.Where(idC => idC.IdCategory == catId).ToList();
                    Models.Friends.Linking obLink = new Models.Friends.Linking();
                    obLink.CategoryId   = catId;
                    obLink.CategoryName = db.categories.Where(idc => idc.Id == catId).FirstOrDefault().Category1;
                    obLink.friends      = new Dictionary <string, string>();
                    foreach (var itemL in resultLink)
                    {
                        if (obLink.friends.ContainsKey(itemL.IdFriend))
                        {
                            obLink.friends[itemL.IdFriend] = obLink.friends[itemL.IdFriend] + ',' + itemL.Tag;
                        }
                        else
                        {
                            obLink.friends.Add(itemL.IdFriend, itemL.Tag);
                        }
                    }
                    dict.Add(catId.ToString(), obLink);
                }
            }
            return(dict);
        }