Ejemplo n.º 1
0
        public ActionResult Create(Attraction attraction)
        {
            attraction.AttractionType = db.AttractionType.Find(attraction.AttractionType.ID);
            attraction.Country = db.Country.Find(attraction.Country.ID);
            attraction.AvgRating = 0.0;

            //upload photos
            try
            {
                int i = 0;
                foreach (string upload in Request.Files)
                {
                    if (Request.Files[i].ContentLength == 0)
                        continue;

                    string path = AppDomain.CurrentDomain.BaseDirectory + "Content/AttractionImages/";
                    string ext = Request.Files[i].FileName.Substring(Request.Files[i].FileName.LastIndexOf('.'));
                    AttractionImage ai = new AttractionImage { AttractionID = attraction.ID, FileName = generateRandomString(32) + ext };
                    attraction.Images.Add(ai);
                    Request.Files[i].SaveAs(Path.Combine(path, ai.FileName));
                    i++;
                }
            }
            catch (NullReferenceException)
            {
                //no photo
            }
            //end of upload user photo

            db.Attraction.Add(attraction);
            db.SaveChanges();
            return RedirectToAction("Details", new { id = attraction.ID });
        }
Ejemplo n.º 2
0
        public JsonResult AddPhotoToAttraction(string tokken, int attrId, int userId = 0)
        {
            //check user role for permission??

            byte[] image = new byte[Request.InputStream.Length];
            Request.InputStream.Read(image, 0, image.Length);

            if(Request.InputStream.Length==0)
                return Json("false", JsonRequestBehavior.AllowGet);

            MemoryStream ms = new MemoryStream(image);
            Bitmap bitmap = new Bitmap(ms);
            var name = HashHelper.CalculateMD5Hash(new Guid().ToString());
            String path = HttpContext.Server.MapPath("~/Content/AttractionImages");
            bitmap.Save(path+"/"+name+".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);

            var ati = new AttractionImage() { AttractionID = attrId, FileName = name + ".jpg" };
            db.AttractionImage.Add(ati);
            db.SaveChanges();

            return Json("true", JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 3
0
        public ActionResult ImageCreate(int AttractionId, String Author, String FileName, String Title)
        {
            AttractionImage image = new AttractionImage();

            image.AttractionID = AttractionId;
            image.isApproved = 0;
            image.Author = Author;
            image.Title = Title;

            try
            {
                int i = 0;
                foreach (string upload in Request.Files)
                {
                    if (Request.Files[i].ContentLength == 0)
                        continue;
                    string path = AppDomain.CurrentDomain.BaseDirectory + "Content/AttractionImages/";
                    string ext = Request.Files[i].FileName.Substring(Request.Files[i].FileName.LastIndexOf('.'));
                    image.FileName = generateRandomString(32) + ext;
                    System.Diagnostics.Debug.WriteLine(image.FileName);
                    Request.Files[i].SaveAs(Path.Combine(path, image.FileName));
                    i++;
                }
            }
            catch (NullReferenceException)
            {
                //no photo
            }

            db.AttractionImage.Add(image);
            db.SaveChanges();

            return RedirectToAction("Details", new { id = image.AttractionID });
            //return View("GetImage", image);
        }