コード例 #1
0
        public ResultMessageModel GetRoomActive()
        {
            ResultMessageModel result   = new ResultMessageModel();
            List <RoomModel>   roomList = new List <RoomModel>();

            try
            {
                /* Because We will put all out values from our (UserRegistration.aspx)
                 *              To in Bussiness object and then Pass it to Bussiness logic and then to
                 *              DataAcess
                 *              this way the flow carry on*/
                SqlDataAdapter da  = new SqlDataAdapter();
                DataTable      dt  = new DataTable();
                SqlCommand     cmd = new SqlCommand("usp_USER_GetRoomActive", con);
                cmd.CommandType  = CommandType.StoredProcedure;
                da.SelectCommand = cmd;
                da.Fill(dt);
                cmd.Dispose();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        roomList.Add(UtilsRepository.CreateItemFromRow <RoomModel>(row));
                    }
                    result.Result        = dt.Rows.Count;
                    result.ResultID      = 1;
                    result.ResultMessage = JsonConvert.SerializeObject(roomList);
                }
                else
                {
                    result.Result        = 0;
                    result.ResultID      = 0;
                    result.ResultMessage = "NO_ROOM_ACTIVE";
                }
            }
            catch (Exception ex)
            {
                result.Result        = -1;
                result.ResultID      = 0;
                result.ResultMessage = ex.Message;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return(result);
        }
コード例 #2
0
        public UserModel GetUserByUserID(int iUserID)
        {
            UserModel result = new UserModel();

            try
            {
                /* Because We will put all out values from our (UserRegistration.aspx)
                 *              To in Bussiness object and then Pass it to Bussiness logic and then to
                 *              DataAcess
                 *              this way the flow carry on*/
                SqlDataAdapter da  = new SqlDataAdapter();
                DataTable      dt  = new DataTable();
                SqlCommand     cmd = new SqlCommand("usp_USER_GetUserByUserID", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@pUserID", SqlDbType.VarChar, 50);
                cmd.Parameters["@pUserID"].Value = iUserID;
                da.SelectCommand = cmd;
                da.Fill(dt);
                cmd.Dispose();
                if (dt.Rows.Count == 1)
                {
                    result = UtilsRepository.CreateItemFromRow <UserModel>(dt.Rows[0]);
                }
                else
                {
                    result = null;
                }
            }
            catch (Exception ex)
            {
                result = null;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return(result);
        }