protected void btnLuu_Click(object sender, EventArgs e) { WebPortal.Model.TaiNguyen taiNguyen = new Model.TaiNguyen(); if (Libs.LibSession.Get(Libs.Constants.ACCOUNT_LOGIN) != null) { if (PathLabel.Text != "") { taiNguyen.TenTaiNguyen = txtTenTN.Text; taiNguyen.MoTa = txtMoTa.Text; taiNguyen.Path = PathLabel.Text; WebPortal.TaiNguyen tintuc = new TaiNguyen(); try { int idTaiNguyen = tintuc.Add(taiNguyen); lblLuu.Text = "Lưu tài nguyên mới thành công!"; lblIDTN.Text = idTaiNguyen.ToString(); } catch (Exception ex) { lblLuu.Text = "Quá trình lưu xảy ra lỗi: " + ex.Message; } } else lblThongBao.Text = "Bạn chưa có file upload!"; } else { Response.Redirect("AdminLogin.aspx"); } }
private void AddTaiNguyen(string filename, string name, string summary) { string path = Server.MapPath("~/Resources/Files/") + filename; WebPortal.Model.TaiNguyen tn = new Model.TaiNguyen(); tn.Path = path; tn.MoTa = summary; tn.TenTaiNguyen = name; WebPortal.TaiNguyen taiNguyen = new TaiNguyen(); try { int idTaiNguyen = taiNguyen.Add(tn); int idTinTuc = Convert.ToInt32(Request.QueryString["idNews"]); WebPortal.TaiNguyen_TinTuc tnTinTuc = new TaiNguyen_TinTuc(); WebPortal.Model.TaiNguyen_TinTuc taiNguyenTinTuc = new Model.TaiNguyen_TinTuc(); taiNguyenTinTuc.IDTaiNguyen = idTaiNguyen; taiNguyenTinTuc.IDTinTuc = idTinTuc; tnTinTuc.Add(taiNguyenTinTuc); StatusSaveChange.Text = "Đính kèm file thành công!"; StatusLabel.Text = ""; FileName.Text = ""; summaryFile.Text = ""; DeleteStatus.Text = ""; } catch(Exception ex) { StatusSaveChange.Text = "Lỗi xảy ra trong khi đính kèm: " + ex.Message; StatusLabel.Text = ""; FileName.Text = ""; summaryFile.Text = ""; DeleteStatus.Text=""; } }