protected void DeleteButton_Click(object sender, EventArgs e) { if (_id > -1) { OfferTorrent offer = myEntities.OfferTorrents.Where(o => o.Id == _id).Single(); myEntities.OfferTorrents.Remove(offer); myEntities.SaveChanges(); Response.Redirect(string.Format("~/NavigationViews/Offers.aspx")); } }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString.Get("Id"))) { _id = Convert.ToInt32(Request.QueryString.Get("Id")); } if (!Page.IsPostBack && _id > -1) { NoIdTable.Visible = false; OfferDetailsTable.Visible = true; if (User.IsInRole("CHD")) { AuthorizationButton.Visible = true; } OfferTorrent offer = myEntities.OfferTorrents.Where(o => o.Id == _id).Single(); if (User.IsInRole("CHD") || User.Identity.Name == offer.AuthorName) { EditButton.Visible = true; DeleteButton.Visible = true; } if (User.IsInRole("CHD") || (User.Identity.Name == offer.AuthorName && offer.Authorized == true)) { UploadButton.Visible = true; } if (offer.Authorized == false) { AuthorizationButton.Text = "允许"; } else { AuthorizationButton.Text = "不允许"; } UserLink.Text = offer.AuthorName; CreateDateTimeLabel.Text = offer.CreateDateTime.ToString(); TitleLabel.Text = offer.Title; SubTitleLabel.Text = offer.SubTitle; TypeLabel.Text = offer.Ttype.Tname; BodyLabel.Text = offer.Body; } }
protected void OfferGrid_RowDataBound(object sender, GridViewRowEventArgs e) { switch (e.Row.RowType) { case DataControlRowType.DataRow: { OfferTorrent offer = (OfferTorrent)e.Row.DataItem; int userId = myEntities.Users.Where(u => u.UserName == offer.AuthorName).Select(u => u.UID).Single(); LinkButton authorLink = e.Row.FindControl("AuthorLink") as LinkButton; if (authorLink != null) { authorLink.PostBackUrl = string.Format("~/UserDetailsViews/UserDetails.aspx?Id={0}", userId); } } break; } }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString.Get("Id"))) { _id = Convert.ToInt32(Request.QueryString.Get("Id")); } if (!Page.IsPostBack && _id > -1) { OfferTorrent offer = myEntities.OfferTorrents.Where(o => o.Id == _id).Single(); TypeList.SelectedIndex = offer.TypeId; TorrentTitle.Text = offer.Title; TorrentSubtitle.Text = offer.SubTitle; BodyText.Text = offer.Body; OfferDeatilsLink.Text = offer.Title; OfferEditTitle.Visible = true; } }
protected void AuthorizationButton_Click(object sender, EventArgs e) { OfferTorrent offer = myEntities.OfferTorrents.Where(o => o.Id == _id).Single(); if (offer.Authorized == false) { offer.Authorized = true; AuthorizationButton.Text = "不允许"; myEntities.SaveChanges(); return; } else { offer.Authorized = false; AuthorizationButton.Text = "允许"; myEntities.SaveChanges(); return; } }
protected void UploadButton_Click(object sender, EventArgs e) { OfferTorrent offer = myEntities.OfferTorrents.Where(o => o.Id == _id).Single(); Torrent torrent = new Torrent(); torrent.TypeId = offer.TypeId; torrent.Title = offer.Title; torrent.SubTitle = offer.SubTitle; torrent.CreateDateTime = offer.CreateDateTime; torrent.UpdateDateTime = offer.UpdateDateTime; torrent.Body = offer.Body; torrent.AuthorName = offer.AuthorName; torrent.TorrentFileUrl = offer.TorrentFileUrl; myEntities.Torrents.Add(torrent); myEntities.OfferTorrents.Remove(offer); try { myEntities.SaveChanges(); } catch (DbEntityValidationException ex) { StringBuilder errors = new StringBuilder(); IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors; foreach (DbEntityValidationResult result in validationResult) { ICollection <DbValidationError> validationError = result.ValidationErrors; foreach (DbValidationError err in validationError) { errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n"); } } ErrorSubmitTable.Visible = true; ErrorSubmit.Text = errors.ToString(); } finally { Response.Redirect(string.Format("~/TorrentView/TorrentDetails.aspx?Id={0}", torrent.Id)); } }
protected void SubmitButton_Click(object sender, EventArgs e) { OfferTorrent offer; if (_id == -1) { offer = new OfferTorrent(); offer.CreateDateTime = DateTime.Now; offer.UpdateDateTime = offer.CreateDateTime; offer.AuthorName = User.Identity.Name; offer.Authorized = false; myEntities.OfferTorrents.Add(offer); } else { offer = myEntities.OfferTorrents.Where(o => o.Id == _id).Single(); offer.UpdateDateTime = DateTime.Now; } FileUpload torrentFileUpload = (FileUpload)OfferAddEditTable.FindControl("TorrentFileUpload"); if (!torrentFileUpload.HasFile || !torrentFileUpload.FileName.ToLower().EndsWith(".torrent")) { CustomValidator cusValTorrent = (CustomValidator)OfferAddEditTable.FindControl("CusValTorrent"); cusValTorrent.IsValid = false; ModelState.AddModelError("Invalid", cusValTorrent.ErrorMessage); } if (ModelState.IsValid && Page.IsValid) { string virtualFolder = "~/TorrentFolder/"; string physicalFolder = Server.MapPath(virtualFolder); string fileName = torrentFileUpload.FileName; string extension = System.IO.Path.GetExtension(torrentFileUpload.FileName); torrentFileUpload.SaveAs(System.IO.Path.Combine(physicalFolder, fileName)); offer.TorrentFileUrl = virtualFolder + fileName; } offer.TypeId = TypeList.SelectedIndex; offer.Title = TorrentTitle.Text; offer.SubTitle = TorrentSubtitle.Text; offer.Body = BodyText.Text; try { myEntities.SaveChanges(); } catch (DbEntityValidationException ex) { StringBuilder errors = new StringBuilder(); IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors; foreach (DbEntityValidationResult result in validationResult) { ICollection <DbValidationError> validationError = result.ValidationErrors; foreach (DbValidationError err in validationError) { errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n"); } } ErrorSubmitTable.Visible = true; ErrorSubmit.Text = errors.ToString(); } finally { Response.Redirect(string.Format("~/TorrentView/OfferDetails.aspx?Id={0}", offer.Id)); } }