public InfoAccountReq GetInfoAccountByID(int id)
        {
            InfoAccountReq res = new InfoAccountReq();

            var cnn = (SqlConnection)Context.Database.GetDbConnection();

            if (cnn.State == ConnectionState.Closed)
            {
                cnn.Open();
            }
            try
            {
                SqlDataAdapter da  = new SqlDataAdapter();
                DataSet        ds  = new DataSet();
                var            cmd = cnn.CreateCommand();
                cmd.CommandText = "GetAccountByID";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@AccountID", id);
                da.SelectCommand = cmd;
                da.Fill(ds);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        InfoAccountReq p = new InfoAccountReq()
                        {
                            AccountId   = (int)row["AccountId"],
                            Email       = row["Email"].ToString(),
                            Password    = row["Password"].ToString(),
                            DisplayName = row["DisplayName"].ToString(),
                            AvatarURL   = row["AvatarURL"].ToString(),
                            Gender      = row["Gender"].ToString(),
                            YearOfBirth = (int)row["YearOfBirth"]
                        };
                        res = p;
                    }
                }
                List <PostReq> lst = GetPostsByID(res.AccountId);
                res.lstPost = lst;
            }
            catch (Exception ex)
            {
                res = null;
            }

            return(res);
        }
Beispiel #2
0
        public IActionResult GetInfoAccountByID([FromBody] InfoAccountReq req)
        {
            var res = _svc.GetInfoAccountByID(req.AccountId);

            return(Ok(res));
        }