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) { using (CosaNostraPRODEntities myEntities = new CosaNostraPRODEntities()) { var review = (from r in myEntities.Reviews where r.Id == _id select r).SingleOrDefault(); if (review != null) { TitleText.Text = review.Title; SummaryText.Text = review.Summary; BodyText.Text = review.Body; GenreList.DataBind(); ListItem myItem = GenreList.Items.FindByValue(review.GenreId.ToString()); if (myItem != null) { myItem.Selected = true; } Authorized.Checked = review.Authorized; } } } }
protected void Page_Load(object sender, EventArgs e) { using (CosaNostraPRODEntities myEntities = new CosaNostraPRODEntities()) { var allGeneres = from genre in myEntities.Genres.Include("Reviews") orderby genre.Name where genre.Reviews.Count() > 0 select new { genre.Name, genre.Reviews }; Repeater1.DataSource = allGeneres; Repeater1.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { using (CosaNostraPRODEntities myEntities = new CosaNostraPRODEntities()) { var authorizedReviews = from review in myEntities.Reviews where review.Authorized == true orderby review.CreateDateTime descending select review; GridView1.DataSource = authorizedReviews; GridView1.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { using (CosaNostraPRODEntities myEntities = new CosaNostraPRODEntities()) { var recentReviews = (from reviews in myEntities.Reviews where reviews.Authorized == true orderby reviews.CreateDateTime descending select new { reviews.Title, reviews.Genre.Name }).Take(10); GridView1.DataSource = recentReviews; GridView1.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { int pictureId = Convert.ToInt32(Request.QueryString.Get("Id")); using (CosaNostraPRODEntities myEntities = new CosaNostraPRODEntities()) { var imageUrl = from myPicture in myEntities.Pictures where myPicture.Id == pictureId select myPicture; Image1.ImageUrl = imageUrl.Single().ImageUrl; } }
protected void SaveButton_Click(object sender, EventArgs e) { if (Page.IsValid) { using (CosaNostraPRODEntities myEntities = new CosaNostraPRODEntities()) { Review myReview; if (_id == -1) { myReview = new Review(); myReview.CreateDateTime = DateTime.Now; myReview.UpdateDateTime = myReview.CreateDateTime; myEntities.AddToReviews(myReview); } else { myReview = (from r in myEntities.Reviews where r.Id == _id select r).Single(); myReview.UpdateDateTime = DateTime.Now; } myReview.Title = TitleText.Text; myReview.Summary = SummaryText.Text; myReview.Body = BodyText.Text; myReview.GenreId = Convert.ToInt32(GenreList.SelectedValue); myReview.Authorized = Authorized.Checked; myEntities.SaveChanges(); Response.Redirect("Reviews.aspx"); } } }