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(); } }
public List <UserProfile> GetAllUsers() { using (var _gorillaCtx = new MSGorillaEntities()) { return(_gorillaCtx.UserProfiles.ToList()); } }
public List <Category> GetCategoryByGroup(string groupID) { using (var _gorillaCtx = new MSGorillaEntities()) { return(_gorillaCtx.Groups.Find(groupID).Categories.ToList()); } }
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); } }
public Category GetCategory(string name, string groupID) { using (var _gorillaCtx = new MSGorillaEntities()) { return(GetCategory(name, groupID, _gorillaCtx)); } }
public Category GetCategory(int id) { using (var _gorillaCtx = new MSGorillaEntities()) { return(GetCategory(id, _gorillaCtx)); } }
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); } }
public UserProfile FindUser(string userid) { using (var _gorillaCtx = new MSGorillaEntities()) { return(_gorillaCtx.UserProfiles.Find(userid)); } }
public List <Membership> GetAllGroupMember(string groupID) { using (var _gorillaCtx = new MSGorillaEntities()) { return(GetAllGroupMember(groupID, _gorillaCtx)); } }
public bool Contain(string schemaID) { using (var _gorillaCtx = new MSGorillaEntities()) { return(!(_gorillaCtx.Schemata.Find(schemaID) == null)); } }
public DisplayMetricChart GetChart(string name) { using (var _gorillaCtx = new MSGorillaEntities()) { return(_gorillaCtx.MetricCharts.Find(name)); } }
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); } }
public List <MetricDataSet> GetAllDataSetByGroup(string groupID) { using (var _gorillaCtx = new MSGorillaEntities()) { return(_gorillaCtx.MetricDataSets.Where(d => d.GroupID == groupID).ToList()); } }
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); } }
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); } }
public Membership CheckMembership(string groupID, string userid) { using (var _gorillaCtx = new MSGorillaEntities()) { return(CheckMembership(groupID, userid, _gorillaCtx)); } }
public bool IsFavouriteTopic(string userid, int topicID) { using (var _gorillaCtx = new MSGorillaEntities()) { return(IsFavouriteTopic(userid, topicID, _gorillaCtx)); } }
public List <Schema> GetSchema() { using (var _gorillaCtx = new MSGorillaEntities()) { return(_gorillaCtx.Schemata.ToList()); } }
public List <Group> GetAllGroup() { using (var _gorillaCtx = new MSGorillaEntities()) { return(GetAllGroup(_gorillaCtx)); } }
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); } }
public void CheckAdmin(string groupID, string userid, MSGorillaEntities ctx) { if (!"admin".Equals(CheckMembership(groupID, userid, ctx).Role)) { throw new UnauthroizedActionException(); } }
public void CheckAdmin(string groupID, string userid) { using (var _gorillaCtx = new MSGorillaEntities()) { CheckAdmin(groupID, userid, _gorillaCtx); } }
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); }
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()); } } }
public MetricDataSet GetDataSet(int id) { using (var _gorillaCtx = new MSGorillaEntities()) { MetricDataSet dataset = _gorillaCtx.MetricDataSets.Find(id); return(dataset); } }
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>()); } }
public void incrementUnreadMsgCountOfFavouriteTopic(int topicID) { using (var _gorillaCtx = new MSGorillaEntities()) { _gorillaCtx.Database.ExecuteSqlCommand( "update [favouritetopic] set UnreadMsgcount = UnreadMsgcount + 1 where topicid={0}", topicID); } }
public void clearAtlineNotifCount(string userid) { using (var _gorillaCtx = new MSGorillaEntities()) { NotificationCount notif = FindUserNotif(userid, _gorillaCtx); notif.UnreadAtlineMsgCount = 0; _gorillaCtx.SaveChanges(); } }
public Topic AddTopic(Topic topic) { using (var _gorillaCtx = new MSGorillaEntities()) { topic = _gorillaCtx.Topics.Add(topic); _gorillaCtx.SaveChanges(); return(topic); } }
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(); } }