示例#1
0
        public async Task <IHttpActionResult> Post()
        {
            List <UserInfo> toReturn = new List <UserInfo>();

            try
            {
                using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetAllUserFriendsInfo @mail", con);
                    cmd.Parameters.AddWithValue("@mail", User.Identity.Name);

                    con.Open();
                    using (SqlDataReader rdr = await cmd.ExecuteReaderAsync())
                    {
                        while (rdr.Read())
                        {
                            UserInfo i = new UserInfo()
                            {
                                Avatar     = rdr["Avatar"] == DBNull.Value ? null : (byte[])rdr["Avatar"],
                                Country    = rdr["Country"] == DBNull.Value ? "-" : rdr["Country"].ToString(),
                                FirstName  = rdr["FirstName"] == DBNull.Value ? "-" : rdr["FirstName"].ToString(),
                                Interests  = rdr["Interests"] == DBNull.Value ? "-" : rdr["Interests"].ToString(),
                                LastName   = rdr["LastName"] == DBNull.Value ? "-" : rdr["LastName"].ToString(),
                                Region     = rdr["Region"] == DBNull.Value ? "-" : rdr["Region"].ToString(),
                                Settlement = rdr["Settlement"] == DBNull.Value ? "-" : rdr["Settlement"].ToString(),
                                Profession = rdr["Profession"] == DBNull.Value ? "-" : rdr["Profession"].ToString(),
                                Email      = rdr["UserEmail"].ToString(),
                                IsOnline   = AppHub.IsUserOnline(rdr["UserEmail"].ToString())
                            };

                            toReturn.Add(i);
                        }
                    }
                }

                return(Ok(toReturn));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
示例#2
0
        public async Task <IHttpActionResult> Put([FromBody] string email)
        {
            List <Tuple <UserInfo, int> > toReturn = new List <Tuple <UserInfo, int> >();

            try
            {
                using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetPossibleFriends @mail", con);
                    cmd.Parameters.AddWithValue("@mail", email);

                    con.Open();

                    using (SqlDataReader rdr = await cmd.ExecuteReaderAsync())
                    {
                        while (rdr.Read())
                        {
                            toReturn.Add(new Tuple <UserInfo, int>(new UserInfo()
                            {
                                Avatar    = rdr["Avatar"] != DBNull.Value ? (byte[])rdr["Avatar"] : null,
                                Email     = rdr["UserEmail"].ToString(),
                                FirstName = rdr["FirstName"].ToString(),
                                LastName  = rdr["LastName"].ToString(),
                                IsOnline  = AppHub.IsUserOnline(rdr["UserEmail"].ToString())
                            },
                                                                   Convert.ToInt32(rdr["FriendsCount"].ToString())
                                                                   ));
                        }
                    }
                }

                return(Ok(toReturn));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }