示例#1
0
        public List <UserProfile> Followers(string userid)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                UserProfile user = _gorillaCtx.UserProfiles.Find(userid);
                if (user == null)
                {
                    throw new UserNotFoundException(userid);
                }

                return((
                           from u in _gorillaCtx.UserProfiles
                           join su in _gorillaCtx.Subscriptions
                           on u.Userid equals su.Userid
                           where su.FollowingUserid == userid
                           select u
                           ).ToList <UserProfile>());

//                return _gorillaCtx.UserProfiles.SqlQuery(
//                    @"select Userid, DisplayName, PortraitUrl, Description, FollowingsCount, FollowersCount, Password, MessageCount from (
//		                select f.FollowingUserid, f.Userid, DisplayName, PortraitUrl, Description, FollowingsCount, FollowersCount, Password, MessageCount from
//			                [Subscription] f
//			                join
//			                [UserProfile] u
//			                on f.Userid = u.Userid
//	                ) ff
//	                where ff.FollowingUserid = {0}",
//                        new object[] { userid }
//                    ).ToList();
            }
        }
示例#2
0
 public List <UserProfile> GetAllUsers()
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(_gorillaCtx.UserProfiles.ToList());
     }
 }
示例#3
0
 public List <Category> GetCategoryByGroup(string groupID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(_gorillaCtx.Groups.Find(groupID).Categories.ToList());
     }
 }
示例#4
0
        public async Task <Boolean> Follow(string userid, string followingUserid)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                UserProfile user          = _gorillaCtx.UserProfiles.Find(userid);
                UserProfile followingUser = _gorillaCtx.UserProfiles.Find(followingUserid);
                if (user == null || followingUser == null)
                {
                    throw new UserNotFoundException(string.Format("{0} or {1}", userid, followingUserid));
                }

                if (_gorillaCtx.Subscriptions.Where(f => f.Userid == userid && f.FollowingUserid == followingUserid).ToList().Count > 0)
                {
                    return(true);
                }

                Subscription follow = new Subscription();
                follow.Userid                   = userid;
                follow.FollowingUserid          = followingUserid;
                follow.FollowingUserDisplayName = "";
                _gorillaCtx.Subscriptions.Add(follow);

                user.FollowingsCount++;
                followingUser.FollowersCount++;
                await _gorillaCtx.SaveChangesAsync();

                return(true);
            }
        }
示例#5
0
 public Category GetCategory(string name, string groupID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(GetCategory(name, groupID, _gorillaCtx));
     }
 }
示例#6
0
 public Category GetCategory(int id)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(GetCategory(id, _gorillaCtx));
     }
 }
示例#7
0
        public Category CreateCategory(string name, string groupID, string creater, string description = null)
        {
            if (!Utils.IsValidID(name))
            {
                throw new InvalidIDException(name, "name");
            }

            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Category category = GetCategory(name, groupID, _gorillaCtx);
                if (category != null)
                {
                    throw new CategoryAlreadyExistException(name, groupID);
                }

                category                 = new Category();
                category.Name            = name;
                category.GroupID         = groupID;
                category.Creater         = creater;
                category.CreateTimestamp = DateTime.UtcNow;
                category.Description     = description;

                _gorillaCtx.Categories.Add(category);
                _gorillaCtx.SaveChanges();
                return(category);
            }
        }
示例#8
0
 public UserProfile FindUser(string userid)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(_gorillaCtx.UserProfiles.Find(userid));
     }
 }
示例#9
0
 public List <Membership> GetAllGroupMember(string groupID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(GetAllGroupMember(groupID, _gorillaCtx));
     }
 }
示例#10
0
 public bool Contain(string schemaID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(!(_gorillaCtx.Schemata.Find(schemaID) == null));
     }
 }
示例#11
0
 public DisplayMetricChart GetChart(string name)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(_gorillaCtx.MetricCharts.Find(name));
     }
 }
示例#12
0
        public DisplayMetricChart AddDataSet(string name, int datasetID, string legend, string type)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                MetricChart chart = _gorillaCtx.MetricCharts.Find(name);
                if (chart == null)
                {
                    throw new MetricChartNotFoundException();
                }

                MetricDataSet data = _gorillaCtx.MetricDataSets.Find(datasetID);
                if (data == null)
                {
                    throw new MetricDataSetNotFoundException();
                }

                if (!chart.GroupID.Equals(data.GroupID, StringComparison.InvariantCultureIgnoreCase))
                {
                    throw new MetricGroupDismatchException();
                }
                Chart_DataSet dataset = new Chart_DataSet();
                dataset.MetricChartName = name;
                dataset.MetricDataSetID = datasetID;
                dataset.Legend          = legend;
                dataset.Type            = type;

                _gorillaCtx.Chart_DataSet.Add(dataset);
                _gorillaCtx.SaveChanges();
                return(dataset.MetricChart);
            }
        }
示例#13
0
 public List <MetricDataSet> GetAllDataSetByGroup(string groupID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(_gorillaCtx.MetricDataSets.Where(d => d.GroupID == groupID).ToList());
     }
 }
示例#14
0
        public MetricDataSet CreateDataSet(string creater, string instance, string counter, string category, string groupID, string description = null)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Group group = _gorillaCtx.Groups.Find(groupID);
                if (group == null)
                {
                    throw new GroupNotExistException();
                }

                UserProfile user = _gorillaCtx.UserProfiles.Find(creater);
                if (user == null)
                {
                    throw new UserNotFoundException(creater);
                }

                MetricDataSet data = new MetricDataSet();
                data.Instance    = instance;
                data.Counter     = counter;
                data.Category    = category;
                data.GroupID     = group.GroupID;
                data.Description = description;
                data.Creater     = creater;
                data.RecordCount = 0;

                _gorillaCtx.MetricDataSets.Add(data);
                _gorillaCtx.SaveChanges();

                return(data);
            }
        }
示例#15
0
        public Group CreateGroup(string creater, string groupID, string displayName, string description, bool isOpen)
        {
            if (!Utils.IsValidID(groupID))
            {
                throw new InvalidIDException();
            }

            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Group group = GetGroupByID(groupID);
                if (group != null)
                {
                    throw new GroupAlreadyExistException(groupID);
                }

                //add group
                group             = new Group();
                group.GroupID     = groupID;
                group.DisplayName = displayName;
                group.Description = description;
                group.IsOpen      = isOpen;
                _gorillaCtx.Groups.Add(group);
                //add creater as default admin
                Membership member = new Membership();
                member.GroupID  = groupID;
                member.MemberID = creater;
                member.Role     = "admin";
                _gorillaCtx.Memberships.Add(member);

                _gorillaCtx.SaveChanges();
                return(group);
            }
        }
示例#16
0
 public Membership CheckMembership(string groupID, string userid)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(CheckMembership(groupID, userid, _gorillaCtx));
     }
 }
示例#17
0
 public bool IsFavouriteTopic(string userid, int topicID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(IsFavouriteTopic(userid, topicID, _gorillaCtx));
     }
 }
示例#18
0
 public List <Schema> GetSchema()
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(_gorillaCtx.Schemata.ToList());
     }
 }
示例#19
0
 public List <Group> GetAllGroup()
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         return(GetAllGroup(_gorillaCtx));
     }
 }
示例#20
0
        public Membership AddMember(string groupID, string userid, string role = "user")
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                UserProfile user = _gorillaCtx.UserProfiles.Find(userid);
                if (user == null)
                {
                    throw new UserNotFoundException(userid);
                }

                if (user.IsRobot == true)
                {
                    throw new UpdateRobotMembershipException();
                }

                Membership member = _gorillaCtx.Memberships.Where(m => m.GroupID == groupID && m.MemberID == userid).FirstOrDefault();
                if (member == null)
                {
                    member          = new Membership();
                    member.GroupID  = groupID;
                    member.MemberID = user.Userid;
                    member.Role     = role;
                    _gorillaCtx.Memberships.Add(member);

                    _gorillaCtx.SaveChanges();
                }
                else
                {
                    member.Role = "user";
                    _gorillaCtx.SaveChanges();
                }

                return(member);
            }
        }
示例#21
0
 public void CheckAdmin(string groupID, string userid, MSGorillaEntities ctx)
 {
     if (!"admin".Equals(CheckMembership(groupID, userid, ctx).Role))
     {
         throw new UnauthroizedActionException();
     }
 }
示例#22
0
 public void CheckAdmin(string groupID, string userid)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         CheckAdmin(groupID, userid, _gorillaCtx);
     }
 }
示例#23
0
        public static DisplayGroup GetDisplayGroup(string groupID, string userid, string role = null)
        {
            string key = CacheHelper.DisplayGroupPrefix + userid + "@" + groupID;

            if (CacheHelper.Contains(key))
            {
                return(CacheHelper.Get <DisplayGroup>(key));
            }

            DisplayGroup result = null;

            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Group group = new GroupManager().GetGroupByID(groupID, _gorillaCtx);
                if (!string.IsNullOrEmpty(role))
                {
                    result = new DisplayGroup(group, role);
                }
                else
                {
                    result = new DisplayGroup(group, userid, _gorillaCtx);
                }
            }

            CacheHelper.Add(key, result);
            return(result);
        }
示例#24
0
 public List <MetricDataSet> QueryDataSet(string group, string category = null, string counter = null, string instance = null)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         if (!string.IsNullOrEmpty(instance))
         {
             return(_gorillaCtx.MetricDataSets.Where(
                        d => d.Instance == instance && d.Counter == counter && d.Category == category && d.GroupID == group
                        ).ToList());
         }
         else if (!string.IsNullOrEmpty(counter))
         {
             return(_gorillaCtx.MetricDataSets.Where(
                        d => d.Counter == counter && d.Category == category && d.GroupID == group
                        ).ToList());
         }
         else if (!string.IsNullOrEmpty(category))
         {
             return(_gorillaCtx.MetricDataSets.Where(
                        d => d.Category == category && d.GroupID == group
                        ).ToList());
         }
         else if (!string.IsNullOrEmpty(group))
         {
             return(_gorillaCtx.MetricDataSets.Where(
                        d => d.GroupID == group
                        ).ToList());
         }
         else
         {
             return(_gorillaCtx.MetricDataSets.ToList());
         }
     }
 }
示例#25
0
 public MetricDataSet GetDataSet(int id)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         MetricDataSet dataset = _gorillaCtx.MetricDataSets.Find(id);
         return(dataset);
     }
 }
示例#26
0
 public List <UserProfile> SearchUser(string keyword)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         var users = _gorillaCtx.UserProfiles.Where(u => u.Userid.Contains(keyword));
         return(users.ToList <UserProfile>());
     }
 }
示例#27
0
 public void incrementUnreadMsgCountOfFavouriteTopic(int topicID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         _gorillaCtx.Database.ExecuteSqlCommand(
             "update [favouritetopic] set UnreadMsgcount = UnreadMsgcount  + 1 where topicid={0}",
             topicID);
     }
 }
示例#28
0
 public void clearAtlineNotifCount(string userid)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         NotificationCount notif = FindUserNotif(userid, _gorillaCtx);
         notif.UnreadAtlineMsgCount = 0;
         _gorillaCtx.SaveChanges();
     }
 }
示例#29
0
 public Topic AddTopic(Topic topic)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         topic = _gorillaCtx.Topics.Add(topic);
         _gorillaCtx.SaveChanges();
         return(topic);
     }
 }
示例#30
0
 public void Remove(string userid, int topicID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         List <FavouriteTopic> finds = _gorillaCtx.FavouriteTopics.Where(f => f.Userid.Equals(userid) && f.TopicID == topicID).ToList();
         _gorillaCtx.FavouriteTopics.RemoveRange(finds);
         _gorillaCtx.SaveChanges();
     }
 }