Esempio n. 1
0
        public void ProcessRequest(HttpContext context)
        {
            string filename = context.Request.QueryString["filename"].ToString();
            int Mag_ID = int.Parse(context.Request.QueryString["Mag_id"].ToString());
            string Mag_Issue = context.Request.QueryString["Mag_Issue"].ToString();
            string Shoot = context.Request.QueryString["Shoot"].ToString();
            DateTime ShootDate = DateTime.Parse(context.Request.QueryString["ShootDate"].ToString());
            string keywords = context.Request.QueryString["keywords"].ToString();
            string description = context.Request.QueryString["description"].ToString();
            string photographer = context.Request.QueryString["photographer"].ToString();

            using(FileStream fs = File.Create(HttpContext.Current.Server.MapPath("~/photos/" + filename)))
            {
                SaveFile(context.Request.InputStream, fs);
            }

            IImageRepository db = new ImageRepository();
            IUserRepository userdb = new UserRepository();
            tbl_Image newImage = new tbl_Image();
            newImage.date_uploaded = DateTime.Now;
            newImage.magazine_id = Mag_ID;
            newImage.magazine_issue = Mag_Issue;
            newImage.shoot_description = Shoot;
            newImage.shoot_date = ShootDate;
            newImage.keywords = keywords;
            newImage.description = description;
            newImage.photographer = userdb.getUserbyUsername(photographer).id;
            newImage.date_updated = DateTime.Now;

            db.Add(newImage);
            db.Save();
        }
Esempio n. 2
0
 private void attach_tbl_Images(tbl_Image entity)
 {
     this.SendPropertyChanging();
     entity.tbl_user = this;
 }
Esempio n. 3
0
 private void detach_tbl_Images(tbl_Image entity)
 {
     this.SendPropertyChanging();
     entity.tbl_user = null;
 }
Esempio n. 4
0
 partial void Deletetbl_Image(tbl_Image instance);
Esempio n. 5
0
 private void detach_tbl_Images(tbl_Image entity)
 {
     this.SendPropertyChanging();
     entity.tbl_publication = null;
 }
Esempio n. 6
0
 partial void Inserttbl_Image(tbl_Image instance);
Esempio n. 7
0
 partial void Updatetbl_Image(tbl_Image instance);
Esempio n. 8
0
        public void SLUpload()
        {
            //Get all Values from Request
            string filename = HttpContext.Request.QueryString["filename"].ToString();
            int Mag_ID = int.Parse(HttpContext.Request.QueryString["Mag_id"].ToString());
            string Mag_Issue = HttpContext.Request.QueryString["Mag_Issue"].ToString();
            string Shoot = HttpContext.Request.QueryString["Shoot"].ToString();
            DateTime ShootDate = DateTime.Parse(HttpContext.Request.QueryString["ShootDate"].ToString());
            string keywords = HttpContext.Request.QueryString["keywords"].ToString();
            string description = HttpContext.Request.QueryString["description"].ToString();
            string photographer = HttpContext.Request.QueryString["photographer"].ToString();

            //Save image as tempImage in "photos" folder
            string tempFileName = System.Guid.NewGuid().ToString("N") + ".jpg";
            using (FileStream fs = System.IO.File.Create(HttpContext.Server.MapPath("~/photos/" + tempFileName)))
            {
                SaveFile(HttpContext.Request.InputStream, fs);
            }

            //Save image details to database
            tbl_Image newImage = new tbl_Image();
            newImage.date_uploaded = DateTime.Now;
            newImage.magazine_id = Mag_ID;
            newImage.magazine_issue = Mag_Issue;
            newImage.shoot_description = Shoot;
            newImage.shoot_date = ShootDate;
            newImage.keywords = keywords;
            newImage.description = description;
            newImage.photographer = userdb.getUserbyUsername(photographer).id;
            newImage.date_updated = DateTime.Now;
            newImage.name = tempFileName;
            imagedb.Add(newImage);
            imagedb.Save();

            //Create Thumbnail and Preview and Delete Temp
            string oldName = newImage.name;
            newImage.name = newImage.tbl_publication.name.Replace(' ', '_') +
            "_" +
            newImage.magazine_issue.Replace(' ', '_') +
            "_" +
            ((DateTime)newImage.shoot_date).ToString("dd_MMM_yyyy") +
            "_" +
            newImage.id.ToString() + ".jpg";
            newImage.preview_location = "pv_" + newImage.name;
            newImage.thumb_location = "th_" + newImage.name;

            CreateThumbAndPreview("~/photos", oldName, newImage.name);

            DeleteCurrentFile("~/photos", oldName);
            imagedb.Save();
        }
Esempio n. 9
0
        private void saveImage(ref tbl_Image myImage)
        {
            string oldName = myImage.name;
            myImage.name = myImage.tbl_publication.name.Replace(' ', '_') +
            "_" +
            myImage.magazine_issue.Replace(' ', '_') +
            "_" +
            ((DateTime)myImage.shoot_date).ToString("dd_MMM_yyyy") +
            "_" +
            myImage.id.ToString() + ".jpg";
            myImage.preview_location = "pv_" + myImage.name;
            myImage.thumb_location = "th_" + myImage.name;
            try
            {
                using (System.Drawing.Image image = System.Drawing.Image.FromFile(Path.Combine(HttpContext.Server.MapPath("~/photos"), Path.GetFileName(oldName))))
                {

                    var fileWidth = image.Width;
                    var fileHeight = image.Height;

                    //Create Thumbnail
                    int ThumbHeight = 110;
                    int ThumbWidth = 110;

                    if (fileWidth > fileHeight)
                    {
                        ThumbHeight = imagedb.GetProportionalImageHeight(ThumbWidth, fileHeight, fileWidth);
                    }
                    else if (fileWidth < fileHeight)
                    {
                        ThumbWidth = imagedb.GetProportionalImageWidth(ThumbHeight, fileWidth, fileHeight);
                    }

                    using (Bitmap bitmapThumb = new Bitmap(image, ThumbWidth, ThumbHeight))
                    {

                        bitmapThumb.Save(Server.MapPath("~/photos/thumb/" + myImage.thumb_location), image.RawFormat);
                    }

                    //Create Preview
                    int destinationHeight = 380;
                    int destinationWidth = 380;

                    if (fileWidth > fileHeight)
                    {
                        destinationHeight = imagedb.GetProportionalImageHeight(destinationWidth, fileWidth, fileWidth);
                    }
                    else if (fileWidth < fileHeight)
                    {
                        destinationWidth = imagedb.GetProportionalImageWidth(destinationHeight, fileWidth, fileHeight);
                    }

                    using (Bitmap bitmapPreview = new Bitmap(image, destinationWidth, destinationHeight))
                    {
                        Graphics g = Graphics.FromImage(bitmapPreview);
                        Color WaterMark = Color.FromArgb(80, Color.Gray);
                        Pen p = new Pen(WaterMark, 5);
                        g.DrawString("ImageBank Preview", new Font("Arial", 15), new SolidBrush(Color.DarkGray), new Point((bitmapPreview.Size.Width / 2) - 85, (bitmapPreview.Size.Height / 2) - 10));
                        g.DrawLine(p, new Point(0, 0), new Point((bitmapPreview.Size.Width / 2) - 50, (bitmapPreview.Size.Height / 2) - 50));
                        g.DrawLine(p, new Point((bitmapPreview.Size.Width / 2) + 50, (bitmapPreview.Size.Height / 2) + 50), new Point(bitmapPreview.Size.Width, bitmapPreview.Size.Height));
                        g.DrawLine(p, new Point((bitmapPreview.Size.Width / 2) - 50, (bitmapPreview.Size.Height / 2) + 50), new Point(0, bitmapPreview.Size.Height));
                        g.DrawLine(p, new Point((bitmapPreview.Size.Width / 2) + 50, (bitmapPreview.Size.Height / 2) - 50), new Point(bitmapPreview.Size.Width, 0));
                        bitmapPreview.Save(Server.MapPath("~/photos/preview/" + myImage.preview_location), image.RawFormat);
                    }

                }
                DeleteCurrentFile("~/photos", oldName);

            }
            catch (Exception ex)
            {
                throw new Exception("Error: " + ex.Message);
            }
        }
Esempio n. 10
0
		private void detach_tbl_Images(tbl_Image entity)
		{
			this.SendPropertyChanging();
			entity.tbl_user = null;
		}
Esempio n. 11
0
        public ActionResult Edit(tbl_Image postedmImage)
        {
            var returnUrl = Request["hdnReturnurl"];
            //Get image from the database
            tbl_Image myImage = imagedb.GetImageByID(postedmImage.id);

            //Get collections for dropdowns
            ViewData["Magazines"] = new SelectList(magdb.GetMagazines(), "id", "name");
            ViewData["Users"] = new SelectList(userdb.GetUsers(), "id", "username", userdb.getUserbyUsername(HttpContext.User.Identity.Name.ToString()).id);

            #region Validation of Input fields
            HttpPostedFileBase hpf = Request.Files["FileUp"] as HttpPostedFileBase;
            if (hpf.ContentLength > 0)
            {
                //Save updated file in photos folder as temp file
                if (hpf.ContentType != "image/jpeg")
                ModelState.AddModelError("", "Wrong File Type");
            }

            if (postedmImage.magazine_issue.Trim().Length == 0)
                ModelState.AddModelError("magazine_issue", "Magazine issue missing");
            if (postedmImage.shoot_description.Trim().Length == 0)
                ModelState.AddModelError("shoot_description", "Shoot description missing");
            try { DateTime testDate = (DateTime)postedmImage.shoot_date.Value; }
            catch { ModelState.AddModelError("shoot_date", "Invalid Shoot Date"); }
            if (postedmImage.description.Trim().Length == 0)
                ModelState.AddModelError("description", "Description issue missing");
            if (postedmImage.keywords.Trim().Length == 0)
                ModelState.AddModelError("keywords", "Keywords issue missing");

            if (!ModelState.IsValid)
            {
                return View(postedmImage);
            }
            #endregion

            //if validation is OK then execute the following

            string tempFileName = System.Guid.NewGuid().ToString("N") + ".jpg";
            if (hpf.ContentLength > 0)
            {
                //Save updated file in photos folder as temp file
                string filePath = "";
                filePath = Path.Combine(HttpContext.Server.MapPath("~/Photos"), Path.GetFileName(tempFileName));
                hpf.SaveAs(filePath);
            }

            //Update Image Object
            myImage.magazine_id = postedmImage.magazine_id;
            myImage.magazine_issue = postedmImage.magazine_issue;
            myImage.shoot_description = postedmImage.shoot_description;
            myImage.shoot_date = postedmImage.shoot_date;
            myImage.date_updated = DateTime.Now;
            myImage.keywords = postedmImage.keywords;

            string oldName = tempFileName;
            myImage.name = myImage.tbl_publication.name.Replace(' ', '_') +
            "_" +
            myImage.magazine_issue.Replace(' ', '_') +
            "_" +
            ((DateTime)myImage.shoot_date).ToString("dd_MMM_yyyy") +
            "_" +
            myImage.id.ToString() + ".jpg";
            myImage.preview_location = "pv_" + myImage.name;
            myImage.thumb_location = "th_" + myImage.name;
            myImage.thumb_location = "th_" + myImage.name;
            myImage.preview_location = "pv_" + myImage.name;

            if (hpf.ContentLength > 0)
            {
                CreateThumbAndPreview("~/photos", oldName, myImage.name);
                DeleteCurrentFile("~/photos", oldName);
            }
            else
            {
            RenameFile(myImage.thumb_location, "th_" + myImage.name, "~/photos/thumb");
            RenameFile(myImage.preview_location, "pv_" + myImage.name, "~/photos/preview");

            }

            imagedb.Save();
            return Redirect(returnUrl);
        }
Esempio n. 12
0
		private void attach_tbl_Images(tbl_Image entity)
		{
			this.SendPropertyChanging();
			entity.tbl_user = this;
		}
Esempio n. 13
0
		private void detach_tbl_Images(tbl_Image entity)
		{
			this.SendPropertyChanging();
			entity.tbl_publication = null;
		}
Esempio n. 14
0
 partial void Deletetbl_Image(tbl_Image instance);
Esempio n. 15
0
 partial void Updatetbl_Image(tbl_Image instance);
Esempio n. 16
0
 partial void Inserttbl_Image(tbl_Image instance);