Esempio n. 1
0
    public void lstPhoto_InsertItem([QueryString("PhotoAlbumId")] int photoAlbumId)
    {
        Picture picture = new Picture();

        TryUpdateModel(picture);
        FileUpload FileUpload1 = (FileUpload)lstPhoto.InsertItem.FindControl("FileUpload1");

        if (!FileUpload1.HasFile || !FileUpload1.FileName.ToLower().EndsWith(".jpg"))
        {
            CustomValidator cusValImage =
                (CustomValidator)lstPhoto.InsertItem.FindControl("cusValImage");
            cusValImage.IsValid = false;
            ModelState.AddModelError("Invalid", cusValImage.ErrorMessage);
        }

        if (ModelState.IsValid && Page.IsValid)
        {
            if (ModelState.IsValid)
            {
                using (var myEntities = new PlanetWroxEntities())
                {
                    picture.PhotoAlbumId = photoAlbumId;
                    string virtualFolder  = "~/GigPics/";
                    string physicalFolder = Server.MapPath(virtualFolder);
                    string fileName       = Guid.NewGuid().ToString();
                    string extension      = System.IO.Path.GetExtension(FileUpload1.FileName);

                    FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension));
                    picture.ImageUrl = virtualFolder + fileName + extension;
                    myEntities.Pictures.Add(picture);
                    myEntities.SaveChanges();
                }
            }
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int    reviewId = Convert.ToInt32(Request.QueryString.Get("ReviewId"));
        string cacheKey = "Reviews" + reviewId.ToString();
        Review myReview = Cache[cacheKey] as Review;

        if (myReview == null)
        {
            using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
            {
                myReview = (from r in myEntities.Reviews
                            where r.Id == reviewId
                            select r).SingleOrDefault();
                if (myReview != null)
                {
                    Cache.Insert(cacheKey, myReview, null, DateTime.Now.AddMinutes(20),
                                 System.Web.Caching.Cache.NoSlidingExpiration);
                }
            }
        }
        if (myReview != null)
        {
            TitleLabel.Text   = myReview.Title;
            SummaryLabel.Text = myReview.Summary;
            BodyLabel.Text    = myReview.Body;
            Title             = myReview.Title;
            MetaDescription   = myReview.Summary;
        }
    }
 // The return type can be changed to IEnumerable, however to support
 // paging and sorting, the following parameters must be added:
 //     int maximumRows
 //     int startRowIndex
 //     out int totalRowCount
 //     string sortByExpression
 public IQueryable ListView1_GetData([QueryString("PhotoAlbumId")] int photoAlbumId)
 {
     var myEntities = new PlanetWroxEntities();
     return from p in myEntities.Pictures
        where p.PhotoAlbumId == photoAlbumId
        select p;
 }
Esempio n. 4
0
 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 (PlanetWroxEntities myEntities = new PlanetWroxEntities())
         {
             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 SaveButton_Click(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         Review myReview;
         if (_id == -1) // Insert new item
         {
             myReview = new Review();
             myReview.CreateDateTime = DateTime.Now;
             myReview.UpdateDateTime = myReview.CreateDateTime;
             myEntities.Reviews.Add(myReview);
         }
         else // update existing item
         {
             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");
     }
 }
Esempio n. 6
0
 protected void SaveButton_Click(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         Review myReview;
         if (_id == -1) // Insert new item
         {
             myReview = new Review();
             myReview.CreateDateTime = DateTime.Now;
             myReview.UpdateDateTime = myReview.CreateDateTime;
             myEntities.AddToReviews(myReview);
         }
         else // update existing item
         {
             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");
     }
 }
Esempio n. 7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     int reviewId = Convert.ToInt32(Request.QueryString.Get("ReviewId"));
     string cacheKey = "Reviews" + reviewId.ToString();
     Review myReview = Cache[cacheKey] as Review;
     if (myReview == null)
     {
       using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
       {
     myReview = (from r in myEntities.Reviews
                 where r.Id == reviewId
                 select r).SingleOrDefault();
     if (myReview != null)
     {
       Cache.Insert(cacheKey, myReview, null, DateTime.Now.AddMinutes(20), System.Web.Caching.Cache.NoSlidingExpiration);
     }
       }
     }
     if (myReview != null)
     {
       TitleLabel.Text = myReview.Title;
       SummaryLabel.Text = myReview.Summary;
       BodyLabel.Text = myReview.Body;
       Title = myReview.Title;
       MetaDescription = myReview.Summary;
     }
 }
Esempio n. 8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
       {
       /*
       var reviews = (from review in myEntities.Review.Include("Genre")
                     where review.Authorized == true
                     orderby review.CreateDateTime descending
                     select review).Skip(10).Take(10);
       */
       var allReviews = from review in myEntities.Review
                        where review.Authorized == true
                        select new { review.Id, review.Title, review.Genre.Name, review.Summary, review.Body };
       /*
       var allReviewss = from review in myEntities.Review
                         select new
                         {
                             Number = review.Id,
                             Title = review.Title.Substring(0, 20),
                             review.Genre.Name,
                             HasBeenUpdated = (review.UpdateDateTime > review.CreateDateTime)
                         };
       */
       /*
       var allGenres = from genre in myEntities.Genre
                       orderby genre.Name
                       select genre;
       */
       Repeater1.DataSource = allReviews;
       Repeater1.DataBind();
       }
 }
 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 (PlanetWroxEntities myEntities = new PlanetWroxEntities())
         {
             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;
             }
         }
     }
 }
    public void ListView1_InsertItem([QueryString("PhotoAlbumId")] int photoAlbumId)
    {
        Picture picture = new Picture();
        TryUpdateModel(picture);
        FileUpload FileUpload1 = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1");
        if (!FileUpload1.HasFile || !FileUpload1.FileName.ToLower().EndsWith(".jpg"))
        {
          CustomValidator cusValImage = (CustomValidator)ListView1.InsertItem.FindControl("cusValImage");
          cusValImage.IsValid = false;
          ModelState.AddModelError("Invalid", cusValImage.ErrorMessage);
        }
        if (ModelState.IsValid && Page.IsValid)
        {
          using (var myEntities = new PlanetWroxEntities())
          {
        picture.PhotoAlbumId = photoAlbumId;

        string virtualFolder = "~/GigPics/";
        string physicalFolder = Server.MapPath(virtualFolder);
        string fileName = Guid.NewGuid().ToString();
        string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
        FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension));
        picture.ImageUrl = virtualFolder + fileName + extension;

        myEntities.Pictures.Add(picture);
        myEntities.SaveChanges();
          }
        }
    }
Esempio n. 11
0
    // The return type can be changed to IEnumerable, however to support
    // paging and sorting, the following parameters must be added:
    //     int maximumRows
    //     int startRowIndex
    //     out int totalRowCount
    //     string sortByExpression
    public IQueryable lstPhoto_GetData([QueryString("PhotoAlbumId")] int photoAlbumId)
    {
        var myEntities = new PlanetWroxEntities();

        return(from p in myEntities.Pictures
               where p.PhotoAlbumId == photoAlbumId
               select p);
    }
 public IEnumerable<Genre> GenreList_GetData()
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         return (from genre in myEntities.Genres
                 orderby genre.SortOrder
                 select genre).ToList();
     }
 }
 public IEnumerable <Genre> GenreList_GetData()
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         return((from genre in myEntities.Genres
                 orderby genre.SortOrder
                 select genre).ToList());
     }
 }
Esempio n. 14
0
 /*
  * Name: PreferredGenres_GetData
  * Abstract: get data
  */
 public IEnumerable <Genre> cblPreferredGenres_GetData()
 {
     using (var myEntities = new PlanetWroxEntities())
     {
         return((from genre in myEntities.Genres
                 orderby genre.Name
                 select genre).ToList());
     }
 }
Esempio n. 15
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
       var allGenres = from genre in myEntities.Genres
                   orderby genre.Name
                   select new { genre.Name, genre.Reviews };
       Repeater1.DataSource = allGenres;
       Repeater1.DataBind();
     }
 }
Esempio n. 16
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         var allGenres = from genre in myEntities.Genres.Include("Reviews")
                         orderby genre.Name
                         select new { genre.Name, genre.Reviews };
         Repeater1.DataSource = allGenres.ToList();
         Repeater1.DataBind();
     } // end using
 }
 // The id parameter name should match the DataKeyNames value set on the control
 public void ListView1_DeleteItem(int id)
 {
     using (var myEntities = new PlanetWroxEntities())
     {
       var picture = (from p in myEntities.Pictures
                  where p.Id == id
                  select p).Single();
       myEntities.Pictures.Remove(picture);
       myEntities.SaveChanges();
     }
 }
Esempio n. 18
0
 // The id parameter name should match the DataKeyNames value set on the control
 public void lstPhoto_DeleteItem(int id)
 {
     using (var myEntities = new PlanetWroxEntities())
     {
         var picture = (from p in myEntities.Pictures
                        where p.Id == id
                        select p).Single();
         myEntities.Pictures.Remove(picture);
         myEntities.SaveChanges();
     }
 }
Esempio n. 19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         var authorizedReviews = from TReviews in myEntities.TReviews
                                 where TReviews.blnAuthorized == true
                                 orderby TReviews.dtmCreateDateTime descending
                                 select TReviews;
         Repeater1.DataSource = authorizedReviews;
         Repeater1.DataBind();
     }
 }
Esempio n. 20
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         var authorizedReviews = from review in myEntities.Reviews
                                 where review.Authorized == true
                                 orderby review.CreateDateTime descending
                                 select review;
         GridView1.DataSource = authorizedReviews.ToList();
         GridView1.DataBind();
     }
 }
Esempio n. 21
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         var allReviews = from Review in myEntities.Reviews
                          where Review.Authorized == true
                          orderby Review.CreateDateTime descending
                          select Review;
         GridView1.DataSource = allReviews.ToList();
         GridView1.DataBind();
     }
 }
Esempio n. 22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
            {
                var authorizeReviews = from review in myEntities.Reviews
                                       where review.Authorized == true
                                       orderby review.CreateDateTime descending
                                       select review;

                Repeater1.DataSource = authorizeReviews.ToList();
                Repeater1.DataBind();
            } // end using
        }
 public void DetailsView1_InsertItem()
 {
     PhotoAlbum photoAlbum = new PhotoAlbum();
     TryUpdateModel(photoAlbum);
     if (ModelState.IsValid)
     {
       using (var myEntities = new PlanetWroxEntities())
       {
     myEntities.PhotoAlbums.Add(photoAlbum);
     myEntities.SaveChanges();
       }
       Response.Redirect(string.Format("ManagePhotoAlbum?PhotoAlbumId={0}", photoAlbum.Id.ToString()));
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     int photoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"));
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
       string photoAlbumOwner = (from p in myEntities.PhotoAlbums
                             where p.Id == photoAlbumId
                             select p.UserName).Single();
       if (User.Identity.Name != photoAlbumOwner && !User.IsInRole("Managers"))
       {
     Response.Redirect("~/");
       }
     }
 }
Esempio n. 25
0
    public void DetailsView1_InsertItem()
    {
        PhotoAlbum photoAlbum = new PhotoAlbum();

        TryUpdateModel(photoAlbum);
        if (ModelState.IsValid)
        {
            using (var myEntities = new PlanetWroxEntities())
            {
                myEntities.PhotoAlbums.Add(photoAlbum);
                myEntities.SaveChanges();
            }
            Response.Redirect(string.Format("ManagePhotoAlbum?PhotoAlbumId={0}", photoAlbum.Id.ToString()));
        }
    }
Esempio n. 26
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int photoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"));

        using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
        {
            string photoAlbumOwner = (from p in myEntities.TPhotoAlbums
                                      where p.ID == photoAlbumId
                                      select p.strUserName).Single();
            if (User.Identity.Name != photoAlbumOwner && !User.IsInRole("Managers"))
            {
                Response.Redirect("~/");
            }
        }
    }
Esempio n. 27
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
       if (Profile.FavoriteGenres.Count > 0)
       {
     var favGenres = from genre in myEntities.Genres
                     orderby genre.Name
                     where Profile.FavoriteGenres.Contains(genre.Id)
                     select new { genre.Name, genre.Reviews };
     GenreRepeater.DataSource = favGenres;
     GenreRepeater.DataBind();
       }
       GenreRepeater.Visible = GenreRepeater.Items.Count > 0;
       NoRecords.Visible = GenreRepeater.Items.Count == 0;
     }
 }
Esempio n. 28
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
     {
         if (Profile.FavoriteGenres.Count > 0)
         {
             var favGenres = from genre in myEntities.TGenres.Include("TReviews")
                             orderby genre.strName
                             where Profile.FavoriteGenres.Contains(genre.ID)
                             select new { genre.strName, genre.TReviews };
             GenreRepeater.DataSource = favGenres;
             GenreRepeater.DataBind();
         }
         GenreRepeater.Visible = GenreRepeater.Items.Count > 0;
         NoRecords.Visible     = !GenreRepeater.Visible;
     }
 }
    protected void EntityDataSource1_Inserting(object sender, EntityDataSourceChangingEventArgs e)
    {
        using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
        {
            int     photoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"));
            Picture myPicture    = (Picture)e.Entity;
            myPicture.PhotoAlbumId = photoAlbumId;

            // upload
            FileUpload FileUpload1    = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1");
            string     virtualFolder  = "~/GigPics/";
            string     physicalFolder = Server.MapPath(virtualFolder);
            string     fileName       = Guid.NewGuid().ToString();
            string     extension      = System.IO.Path.GetExtension(FileUpload1.FileName);

            FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension));
            myPicture.ImageUrl = virtualFolder + fileName + extension;
        }
    }
Esempio n. 30
0
 protected void lstPhotoAlbum_DataBound(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(ddlPhotoAlbumList.SelectedValue))
     {
         int photoAlbumId = Convert.ToInt32(ddlPhotoAlbumList.SelectedValue);
         using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
         {
             string photoAlbumOwner = (from p in myEntities.PhotoAlbums
                                       where p.Id == photoAlbumId
                                       select p.UserName).Single();
             if (User.Identity.IsAuthenticated &&
                 (User.Identity.Name == photoAlbumOwner || User.IsInRole("Managers")))
             {
                 EditLink.NavigateUrl = string.Format(
                     "~/ManagePhotoAlbum.aspx?PhotoAlbumId={0}", ddlPhotoAlbumList.SelectedValue);
                 EditLink.Visible = true;
             }
             else
             {
                 EditLink.Visible = false;
             }
             if (!string.IsNullOrEmpty(photoAlbumOwner))
             {
                 ProfileCommon ownerProfile = Profile.GetProfile(photoAlbumOwner);
                 lblUserName.Text            = photoAlbumOwner;
                 lblBio.Text                 = ownerProfile.Bio;
                 phPhotoAlbumDetails.Visible = true;
             }
             else
             {
                 phPhotoAlbumDetails.Visible = false;
             }
         }
     }
     else
     {
         EditLink.Visible = false;
     }
 }
Esempio n. 31
0
    protected void ListView1_DataBound(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(DropDownList1.SelectedValue))
          {
        int photoAlbumId = Convert.ToInt32(DropDownList1.SelectedValue);
        using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
        {
          string photoAlbumOwner = (from p in myEntities.PhotoAlbums
                                    where p.Id == photoAlbumId
                                    select p.UserName).Single();
          if (User.Identity.IsAuthenticated && (User.Identity.Name == photoAlbumOwner || User.IsInRole("Managers")))
          {
            EditLink.NavigateUrl = string.Format("~/ManagePhotoAlbum.aspx?PhotoAlbumId={0}", DropDownList1.SelectedValue);
            EditLink.Visible = true;
          }
          else
          {
            EditLink.Visible = false;
          }

          if (!string.IsNullOrEmpty(photoAlbumOwner))
          {
            ProfileCommon ownerProfile = Profile.GetProfile(photoAlbumOwner);
            UserNameLabel.Text = photoAlbumOwner;
            BioLabel.Text = ownerProfile.Bio;
            PhotoAlbumDetails.Visible = true;
          }
          else
          {
            PhotoAlbumDetails.Visible = false;
          }
        }
          }
          else
          {
        EditLink.Visible = false;
          }
    }