public IHttpActionResult PutTripPicture(int id, TripPicture tripPicture)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tripPicture.Id)
            {
                return(BadRequest());
            }

            db.Entry(tripPicture).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TripPictureExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetTripPicture(int id)
        {
            TripPicture tripPicture = db.TripPictures.Find(id);

            if (tripPicture == null)
            {
                return(NotFound());
            }

            return(Ok(tripPicture));
        }
        public IHttpActionResult PostTripPicture(TripPicture tripPicture)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TripPictures.Add(tripPicture);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = tripPicture.Id }, tripPicture));
        }
 public ActionResult Create(TripPicture model, HttpPostedFileBase ImageData)
 {
     if (ImageData != null)
     {
         model.TripId = 1;
         model.Image  = this.ConvertToBytes(ImageData);
     }
     _tripPicturesRepository.Add(model);
     _unitOfWork.Commit();
     //_db.TripPictures.Add(model);
     //_db.SaveChanges();
     return(View(model));
 }
Exemplo n.º 5
0
        public ActionResult AddImage(TripPicture model)
        {
            HttpPostedFileBase file = Request.Files["ImageData"];

            /*ContentRepository service = new ContentRepository();
             * int i = service.UploadImageInDataBase(file, model);
             * if (i == 1)
             * {
             *  return RedirectToAction("Index");
             * }*/
            this.UploadImageInDataBase(file, model);
            return(View(model));
        }
        public IHttpActionResult DeleteTripPicture(int id)
        {
            TripPicture tripPicture = db.TripPictures.Find(id);

            if (tripPicture == null)
            {
                return(NotFound());
            }

            db.TripPictures.Remove(tripPicture);
            db.SaveChanges();

            return(Ok(tripPicture));
        }
Exemplo n.º 7
0
        public void UploadImageInDataBase(HttpPostedFileBase file, TripPicture contentViewModel)
        {
            contentViewModel.Image = ConvertToBytes(file);
            var Content = new TripPicture
            {
                Title       = contentViewModel.Title,
                Description = contentViewModel.Description,
                Contents    = contentViewModel.Contents,
                Image       = contentViewModel.Image
            };

            _tripPictureRepository.Add(Content);
            _unitOfWork.Commit();
        }
Exemplo n.º 8
0
        public ActionResult UploadPicture(UploadImageFile image)
        {
            var f = Request.Files[0];

            bool   success   = false;
            string urlSuffix = image.TripUserId + DateTime.Now.ToString() + ".jpg";
            string bucket    = "trip-app-pictures";
            double lat       = 0;
            double lon       = 0;

            try
            {
                IAmazonS3 client = new AmazonS3Client("AKIAJWFD6TJO7NXPGCOA", "0MiV/p3r411kt9L5PE/Lwwg1n/2VLzbwXgRXIZLk", Amazon.RegionEndpoint.USEast1);

                // get lat lon
                if (!String.IsNullOrEmpty(image.Location))
                {
                    if (image.UseCurrentLocation)
                    {
                        var latlon = image.Location.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                        lat = Convert.ToDouble(latlon[0]);
                        lon = Convert.ToDouble(latlon[1]);
                    }

                    else if (!String.IsNullOrEmpty(image.Location))
                    {
                        var address = image.Location;

                        var requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(address));

                        var georequest = WebRequest.Create(requestUri);
                        var response   = georequest.GetResponse();
                        var xdoc       = XDocument.Load(response.GetResponseStream());

                        var result          = xdoc.Element("GeocodeResponse").Element("result");
                        var locationElement = result.Element("geometry").Element("location");
                        lat = Convert.ToDouble(locationElement.Element("lat").Value);
                        lon = Convert.ToDouble(locationElement.Element("lng").Value);
                    }
                }

                if (!String.IsNullOrEmpty(image.Description) && !String.IsNullOrEmpty(image.TripUserId) && f.InputStream != null)
                {
                    var request = new PutObjectRequest()
                    {
                        BucketName  = bucket,
                        CannedACL   = S3CannedACL.PublicRead,
                        Key         = string.Format(urlSuffix),
                        InputStream = f.InputStream
                    };

                    client.PutObject(request);

                    success = true;
                }
            }
            catch (Exception ex)
            {
                success = false;
            }

            if (success)
            {
                TripAppEntities entities = new TripAppEntities();
                var             user     = entities.TripUsers.Where(r => r.TripCode == image.TripUserId).FirstOrDefault();


                var url = "https://s3.amazonaws.com/trip-app-pictures/" + urlSuffix;

                TripPicture picture = new TripPicture();
                picture.TripUserId   = user.Id;
                picture.Description  = image.Description;
                picture.Date         = DateTime.Now;
                picture.PictureUrl   = url;
                picture.LocationName = !image.UseCurrentLocation ? image.Location : null;
                picture.Lat          = lat;
                picture.Lon          = lon;

                entities.TripPictures.Add(picture);
                entities.SaveChanges();
            }

            return(RedirectToAction("../Trip/Pictures/" + image.TripUserId));
        }
Exemplo n.º 9
0
        public ActionResult UploadPicture(UploadImageFile image)
        {
            var f = Request.Files[0];

            bool success = false;
            string urlSuffix = image.TripUserId + DateTime.Now.ToString() + ".jpg" ;
            string bucket = "trip-app-pictures";
            double lat = 0;
            double lon = 0;

            try
            {
                IAmazonS3 client = new AmazonS3Client("AKIAJWFD6TJO7NXPGCOA", "0MiV/p3r411kt9L5PE/Lwwg1n/2VLzbwXgRXIZLk", Amazon.RegionEndpoint.USEast1);

                // get lat lon
                if (!String.IsNullOrEmpty(image.Location))
                {

                    if (image.UseCurrentLocation)
                    {
                        var latlon = image.Location.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                        lat = Convert.ToDouble(latlon[0]);
                        lon = Convert.ToDouble(latlon[1]);
                    }

                    else if (!String.IsNullOrEmpty(image.Location))
                    {
                        var address = image.Location;

                        var requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(address));

                        var georequest = WebRequest.Create(requestUri);
                        var response = georequest.GetResponse();
                        var xdoc = XDocument.Load(response.GetResponseStream());

                        var result = xdoc.Element("GeocodeResponse").Element("result");
                        var locationElement = result.Element("geometry").Element("location");
                        lat = Convert.ToDouble( locationElement.Element("lat").Value );
                        lon = Convert.ToDouble( locationElement.Element("lng").Value );
                    }
                }

                if (!String.IsNullOrEmpty(image.Description) && !String.IsNullOrEmpty(image.TripUserId) && f.InputStream != null)
                {
                    var request = new PutObjectRequest()
                    {
                        BucketName = bucket,
                        CannedACL = S3CannedACL.PublicRead,
                        Key = string.Format(urlSuffix),
                        InputStream = f.InputStream
                    };

                    client.PutObject(request);

                    success = true;
                }
            }
            catch (Exception ex)
            {
                success = false;

            }

            if (success)
            {
                TripAppEntities entities = new TripAppEntities();
                var user = entities.TripUsers.Where(r => r.TripCode == image.TripUserId).FirstOrDefault();

                var url = "https://s3.amazonaws.com/trip-app-pictures/" + urlSuffix;

                TripPicture picture = new TripPicture();
                picture.TripUserId = user.Id;
                picture.Description = image.Description;
                picture.Date = DateTime.Now;
                picture.PictureUrl = url;
                picture.LocationName = !image.UseCurrentLocation ? image.Location : null;
                picture.Lat = lat;
                picture.Lon = lon;

                entities.TripPictures.Add(picture);
                entities.SaveChanges();

            }

            return RedirectToAction("../Trip/Pictures/" + image.TripUserId);
        }
        // GET: TripPictures/Create
        public ActionResult Create()
        {
            TripPicture tripPicture = new TripPicture();

            return(View(tripPicture));
        }