public NV_MediaLib_ChiTiet GetByUrl(string url) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_MediaLib_getByUrl", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@Url", SqlDbType.NVarChar, 200); pID.Value = url; myCommand.Parameters.Add(pID); NV_MediaLib_ChiTiet model = new NV_MediaLib_ChiTiet(); DataTable dt; myConnection.Open(); using (SqlDataAdapter mData = new SqlDataAdapter(myCommand)) { dt = new DataTable(); mData.Fill(dt); } if (dt != null && dt.Rows.Count > 0) { model = new NV_MediaLib_ChiTiet(dt.Rows[0]); } return(model); } } }
public bool ThemMediaLib(NV_MediaLib_ChiTiet model) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_MediaLib_add", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pTenMediaLib = new SqlParameter("@TenMediaLib", SqlDbType.NVarChar, 500); pTenMediaLib.Value = model.TenMediaLib; myCommand.Parameters.Add(pTenMediaLib); SqlParameter pTypeMedia = new SqlParameter("@TypeMedia", SqlDbType.Int); pTypeMedia.Value = model.TypeMedia; myCommand.Parameters.Add(pTypeMedia); SqlParameter pMoTa = new SqlParameter("@MoTa", SqlDbType.NText); pMoTa.Value = model.MoTa; myCommand.Parameters.Add(pMoTa); SqlParameter pHoatDongID = new SqlParameter("@HoatDongID", SqlDbType.Int); pHoatDongID.Value = model.HoatDongID; myCommand.Parameters.Add(pHoatDongID); SqlParameter pHinhAnh = new SqlParameter("@HinhAnh", SqlDbType.Int); pHinhAnh.Value = model.HinhAnh; myCommand.Parameters.Add(pHinhAnh); SqlParameter pDiSanID = new SqlParameter("@DiSanID", SqlDbType.Int); pDiSanID.Value = model.DiSanID; myCommand.Parameters.Add(pDiSanID); SqlParameter pNgayTao = new SqlParameter("@NgayTao", SqlDbType.DateTime); pNgayTao.Value = model.NgayTao; myCommand.Parameters.Add(pNgayTao); SqlParameter pNgaySua = new SqlParameter("@NgaySua", SqlDbType.DateTime); pNgaySua.Value = model.NgaySua; myCommand.Parameters.Add(pNgaySua); SqlParameter pNguoiTao = new SqlParameter("@NguoiTao", SqlDbType.NVarChar, 200); pNguoiTao.Value = model.NguoiTao; myCommand.Parameters.Add(pNguoiTao); SqlParameter pDuyet = new SqlParameter("@Duyet", SqlDbType.Bit); pDuyet.Value = model.Duyet; myCommand.Parameters.Add(pDuyet); SqlParameter pMediaArray = new SqlParameter("@MediaArray", SqlDbType.NVarChar, 500); pMediaArray.Value = model.MediaArray; myCommand.Parameters.Add(pMediaArray); SqlParameter pDanhMuc = new SqlParameter("@DanhMuc", SqlDbType.NVarChar, 200); pDanhMuc.Value = model.DanhMuc; myCommand.Parameters.Add(pDanhMuc); SqlParameter pPageTitle = new SqlParameter("@PageTitle", SqlDbType.NVarChar, 200); pPageTitle.Value = model.PageTitle; myCommand.Parameters.Add(pPageTitle); SqlParameter pMetaKeyword = new SqlParameter("@MetaKeyword", SqlDbType.NVarChar, 200); pMetaKeyword.Value = model.MetaKeyword; myCommand.Parameters.Add(pMetaKeyword); SqlParameter pMetaDescription = new SqlParameter("@MetaDescription", SqlDbType.NVarChar, 300); pMetaDescription.Value = model.MetaDescription; myCommand.Parameters.Add(pMetaDescription); SqlParameter pUrl = new SqlParameter("@Url", SqlDbType.NVarChar, 200); pUrl.Value = model.Url; myCommand.Parameters.Add(pUrl); try { myConnection.Open(); myCommand.ExecuteNonQuery(); return(true); } catch { return(false); } } } }