public static UserForTableModel ToObject(DataRow reader)
        {
            UserForTableModel userForTableModel = new UserForTableModel();

            userForTableModel.userID                = int.Parse(reader[0].ToString());
            userForTableModel.userName              = reader[1].ToString();
            userForTableModel.groupName             = reader[2].ToString();
            userForTableModel.userNumberOfFollowers = int.Parse(reader[3].ToString());

            try
            {
                userForTableModel.followedByMe = int.Parse(reader[4].ToString()) > 0;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("trying to parse mysql followedByMe: " + ex.Message);
            }

            try
            {
                userForTableModel.followedByMe = bool.Parse(reader[4].ToString());
            }
            catch (Exception ex)
            {
                Debug.WriteLine("trying to parse mssql followedByMe: " + ex.Message);
            }

            Debug.WriteLine("userForTableModel:" + userForTableModel.ToString());
            return(userForTableModel);
        }
Example #2
0
        public UserForTableModel DeleteFollower(int followedID, int followerID)
        {
            if (followedID < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (followerID < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            DataTable         dt        = new DataTable();
            UserForTableModel userModel = new UserForTableModel();

            using (SqlCommand command = new SqlCommand())
            {
                dt = GetMultipleQuery(DataQueryStringsSql.DeleteFollower(followedID, followerID));
            }
            foreach (DataRow ms in dt.Rows)
            {
                userModel = UserForTableModel.ToObject(ms);
            }

            return(userModel);
        }
        public UserForTableModel GetOneUserForTableById(int followerID, int followedID)
        {
            if (followerID < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (followedID < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            var resultQuary = from users in _users.AsQueryable()
                              join groups in _group.AsQueryable() on users.userGroupId equals groups.groupID into joinedGroups
                              where (users.userID == followedID)
                              select new UserForTableModel
            {
                userID                = users.userID,
                userName              = users.userName,
                groupName             = joinedGroups.First().groupName,
                userNumberOfFollowers = users.userNumberOfFollowers
            };

            UserForTableModel userForTableModel = resultQuary.SingleOrDefault();

            userForTableModel.followedByMe = IsFollowedByMe(followedID, followerID);
            return(userForTableModel);
        }
 public HttpResponseMessage GetOneUserForTableById(int followedID)
 {
     try
     {
         int followerID         = int.Parse(base.ControllerContext.RequestContext.Principal.Identity.Name);
         UserForTableModel user = userRepository.GetOneUserForTableById(followerID, followedID);
         return(Request.CreateResponse(HttpStatusCode.OK, user));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
     }
 }
Example #5
0
        public List <UserForTableModel> GetUsersForTable(int myId)
        {
            DataTable dt = new DataTable();
            List <UserForTableModel> arrUsers = new List <UserForTableModel>();

            using (SqlCommand command = new SqlCommand())
            {
                dt = GetMultipleQuery(DataQueryStringsSql.GetUsersForTable(myId));
            }

            foreach (DataRow ms in dt.Rows)
            {
                arrUsers.Add(UserForTableModel.ToObject(ms));
            }

            return(arrUsers);
        }