Example #1
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");
     }
 }
    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();
          }
        }
    }
 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");
     }
 }
    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();
                }
            }
        }
    }
 // 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();
     }
 }
 // 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();
     }
 }
 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()));
     }
 }
Example #8
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()));
        }
    }