コード例 #1
0
        public ActionResult Edit([Bind(Include = "LocationID,LocationName,Address,City,State,ZipCode,AuditionLimit,AuditionPhoto,AuditionDetails,AuditionDate,IsActive, LManagerID")] AuditionLocation auditionLocation, HttpPostedFileBase alphoto)
        {
            if (ModelState.IsValid)
            {
                #region Image Upload

                if (alphoto != null)
                {
                    /**/
                    string imgName = alphoto.FileName;

                    /*1*/
                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    /*2*/
                    string[] goodExts = { ".jpeg", ".jpg", ".gif", ".png" };

                    /*3*/
                    if (goodExts.Contains(ext.ToLower()) && (alphoto.ContentLength <= 4193404))
                    {
                        /*4*/
                        imgName = Guid.NewGuid() + ext.ToLower();

                        //commented this out and followed this other project file
                        //actorheadshot.SaveAs(Server.MapPath("~/Content/auditionlocations/" + imgName));

                        #region Resize Image
                        /*5*/
                        string savePath = Server.MapPath("~/Content/auditionlocations/");
                        //taking the contents of this file and creating a stream of bytes, http file base type is becoming a stream of bytes into a type of image. this conversion has to take place for us to be able to resize the image
                        /*6*/
                        Image convertedImage = Image.FromStream(alphoto.InputStream);
                        int   maxImageSize   = 500;
                        int   maxThumbSize   = 100;
                        //if you allowed image uploads for magazine and books - you would need to repeat that code - that's why the image service code is in an imageservice area
                        /*7*/
                        UploadUtility.ResizeImage(savePath, imgName, convertedImage, maxImageSize, maxThumbSize);

                        UploadUtility.Delete(savePath, auditionLocation.AuditionPhoto);

                        auditionLocation.AuditionPhoto = imgName;
                        //saves image onto server - but doesn't update db need to make sure to update what is stored in the db
                        #endregion
                    }
                    else
                    {
                        imgName = "nouserimg.png";
                    }
                    auditionLocation.AuditionPhoto = imgName;
                }

                #endregion

                db.Entry(auditionLocation).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(auditionLocation));
        }
コード例 #2
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AuditionLocation auditionLocation = db.AuditionLocations.Find(id);

            if (auditionLocation == null)
            {
                return(HttpNotFound());
            }
            return(View(auditionLocation));
        }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            AuditionLocation auditionLocation = db.AuditionLocations.Find(id);

            #region Image utility
            if (auditionLocation.AuditionPhoto != null && auditionLocation.AuditionPhoto != "nouserimg.png")
            {
                UploadUtility.Delete(Server.MapPath("~/Content/auditionlocations/"), auditionLocation.AuditionPhoto);
            }

            #endregion

            db.AuditionLocations.Remove(auditionLocation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }