コード例 #1
0
        public ResponseResult Save(Model.Medias media)
        {
            int count = dbContext.Create(media);

            if (count > 0)
            {
                return(new SuccessResult("save successful"));
            }
            else
            {
                return(new ErrorResult("failed to save"));
            }
        }
コード例 #2
0
ファイル: Medias.cs プロジェクト: HaotianSunL/COMP3851B
        public List <Model.Medias> Get(string position)
        {
            List <Model.Medias> mediaList = new List <Model.Medias>();

            using (SqlConnection conn = new SqlConnection())
            {
                string connectStr = ConfigurationManager.ConnectionStrings["connect"].ToString();

                conn.ConnectionString = connectStr;

                SqlCommand cmd = new SqlCommand();

                var pos = position.Split(',').Select((str) =>
                {
                    return("'" + str + "'");
                });

                var distStr = "(" + string.Join(",", pos) + ")";

                cmd.CommandText = "select * from Medias where position in " + distStr;

                cmd.Connection = conn;

                conn.Open();

                SqlDataReader read = cmd.ExecuteReader();

                while (read.Read())
                {
                    Model.Medias media = new Model.Medias()
                    {
                        id         = read.GetInt32(0),
                        title      = read.GetString(1),
                        position   = read.GetString(2),
                        fileName   = read.GetString(3),
                        path       = read.GetString(4),
                        mediaType  = read.GetInt32(5),
                        createTime = read.GetDateTime(6),
                        updateTime = read.GetDateTime(7),
                        isDel      = read.GetBoolean(8)
                    };
                    mediaList.Add(media);
                }

                conn.Close();
            }
            return(mediaList);
        }
コード例 #3
0
ファイル: Medias.cs プロジェクト: HaotianSunL/COMP3851B
        public List <Model.Medias> GetSliders(int mediaType)
        {
            List <Model.Medias> mediaList = new List <Model.Medias>();

            using (SqlConnection conn = new SqlConnection())
            {
                string connectStr = ConfigurationManager.ConnectionStrings["connect"].ToString();

                conn.ConnectionString = connectStr;

                SqlCommand cmd = new SqlCommand();

                cmd.CommandText = "select * from Medias where media_type=@mediaType and is_del=0";

                cmd.Parameters.AddWithValue("@mediaType", mediaType);

                cmd.Connection = conn;

                conn.Open();

                SqlDataReader read = cmd.ExecuteReader();

                while (read.Read())
                {
                    Model.Medias media = new Model.Medias()
                    {
                        id         = read.GetInt32(0),
                        title      = read.GetString(1),
                        position   = read.GetString(2),
                        fileName   = read.GetString(3),
                        path       = read.GetString(4),
                        mediaType  = read.GetInt32(5),
                        createTime = read.GetDateTime(6),
                        updateTime = read.GetDateTime(7),
                        isDel      = read.GetBoolean(8)
                    };
                    mediaList.Add(media);
                }

                conn.Close();
            }
            return(mediaList);
        }
コード例 #4
0
ファイル: Medias.cs プロジェクト: HaotianSunL/COMP3851B
        public Model.Medias Get(int id)
        {
            Model.Medias media = null;
            using (SqlConnection conn = new SqlConnection())
            {
                string connectStr = ConfigurationManager.ConnectionStrings["connect"].ToString();

                conn.ConnectionString = connectStr;

                SqlCommand cmd = new SqlCommand();

                cmd.CommandText = "select * from Medias where id=@id";

                cmd.Parameters.AddWithValue("@id", id);

                cmd.Connection = conn;

                conn.Open();

                SqlDataReader read = cmd.ExecuteReader();

                if (read.HasRows)
                {
                    read.Read();
                    media = new Model.Medias()
                    {
                        id         = read.GetInt32(0),
                        title      = read.GetString(1),
                        position   = read.GetString(2),
                        fileName   = read.GetString(3),
                        path       = read.GetString(4),
                        mediaType  = read.GetInt32(5),
                        createTime = read.GetDateTime(6),
                        updateTime = read.GetDateTime(7),
                        isDel      = read.GetBoolean(8)
                    };
                }

                conn.Close();
            }
            return(media);
        }
コード例 #5
0
ファイル: Medias.cs プロジェクト: HaotianSunL/COMP3851B
        public int Create(Model.Medias media)
        {
            int rows = 0;

            using (SqlConnection conn = new SqlConnection())
            {
                string connectStr = ConfigurationManager.ConnectionStrings["connect"].ToString();
                conn.ConnectionString = connectStr;
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "insert into Medias(title, position, file_name, path, media_type,create_time, update_time) values(@title, @position, @fileName, @path, @mediaType, @createTime, @updateTime)";
                cmd.Parameters.AddWithValue("@title", media.title);
                cmd.Parameters.AddWithValue("@position", media.position);
                cmd.Parameters.AddWithValue("@fileName", media.fileName);
                cmd.Parameters.AddWithValue("@path", media.path);
                cmd.Parameters.AddWithValue("@mediaType", media.mediaType);
                cmd.Parameters.AddWithValue("@createTime", media.createTime);
                cmd.Parameters.AddWithValue("@updateTime", media.updateTime);
                cmd.Connection = conn;
                conn.Open();
                rows = cmd.ExecuteNonQuery();
                conn.Close();
            }
            return(rows);
        }