Example #1
0
        private void FlipView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var flipview = ((FlipView)sender);
            PointOfInterestViewModel viewModel = this.DataContext as PointOfInterestViewModel;

            switch (flipview.SelectedIndex)
            {
            case 0:
                flipview.BannerText        = "Star";
                viewModel.Graphics.ImageId = "star";
                setImage("pack://application:,,,/Resources/icons/032.png");
                break;

            case 1:
                flipview.BannerText        = "Map marker";
                viewModel.Graphics.ImageId = "map-marker";
                setImage("pack://application:,,,/Resources/icons/map-marker.png");
                break;

            case 2:
                flipview.BannerText        = "Flag";
                viewModel.Graphics.ImageId = "flag";
                setImage("pack://application:,,,/Resources/icons/flag-variant.png");
                break;
            }
        }
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestViewModel model)
        {
            if (model.Description == model.Name)
            {
                ModelState.AddModelError("Description", "Description must be different from the name");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound());
            }
            var pointOfInterest = _mapper.Map <PointOfInterest>(model);

            _cityInfoRepository.AddPointOfInterestForCity(cityId, pointOfInterest);
            _cityInfoRepository.Save();
            var createdPointOfInterestToReturn = _mapper.Map <PointOfInterestDto>(pointOfInterest);

            return(CreatedAtRoute("GetPointOFInterest",
                                  new { cityId, id = createdPointOfInterestToReturn.Id },
                                  createdPointOfInterestToReturn));
        }
        public IActionResult GetPointOfInterest(int cityId, int id)
        {
/*            var city = CitiesDataStore.Cities.FirstOrDefault(c => c.Id == cityId);
 *
 *          if (city == null)
 *          {
 *              return NotFound();
 *          }
 *
 *          var pointOfInterest = city.PointsOfInterest.FirstOrDefault(p => p.Id == id);*/

            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound());
            }

            var pointOfInterest = _cityInfoRepository.GetPointOfInterestForCity(cityId, id);

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

            var pointOfInterestResult = new PointOfInterestViewModel()
            {
                Id          = pointOfInterest.Id,
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            return(Ok(pointOfInterestResult));

            // var pointOfInterestResult = Mapper.Map<PointOfInterestViewModel>(pointOfInterest);
            // return Ok(pointOfInterestResult);
        }
        public IActionResult UpdatePointOfInterest(int cityId, int id, [FromBody] PointOfInterestViewModel model)
        {
            if (model.Description == model.Name)
            {
                ModelState.AddModelError("Description", "Description must be different from the name");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound("City not found"));
            }
            var oldPointOfInterest = _cityInfoRepository.GetPointOfInterestForCity(cityId, id);

            if (oldPointOfInterest == null)
            {
                return(NotFound("Point of interest not found"));
            }

            _mapper.Map(model, oldPointOfInterest);
            _cityInfoRepository.Save();

            return(NoContent());
        }
        public IActionResult PartiallyUpdatePointOfInterest(int cityId, int id,
                                                            [FromBody] JsonPatchDocument <PointOfInterestViewModel> patchDoc)
        {
            if (patchDoc == null)
            {
                return(BadRequest());
            }

            var pointOfInterestEntity = _cityInfoRepository.GetPointOfInterestForCity(cityId, id);

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

//            var pointOfInterestToPatch = Mapper.Map<PointOfInterestForUpdateDto>(pointOfInterestEntity);

            var pointOfInterestToPatch = new PointOfInterestViewModel()
            {
                Name        = pointOfInterestEntity.Name,
                Description = pointOfInterestEntity.Description
            };

            patchDoc.ApplyTo(pointOfInterestToPatch, ModelState);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TryValidateModel(pointOfInterestToPatch);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            pointOfInterestEntity.Name        = pointOfInterestToPatch.Name;
            pointOfInterestEntity.Description = pointOfInterestToPatch.Description;

            if (!_cityInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

//            return Ok(pointOfInterestFromStore);
            return(NoContent()); //204 means successful
        }
Example #6
0
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestViewModel pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            //Example of a custom validation error.  The name and desctiption cannot be the same
            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The description and name cannot be the same");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_cityRepository.CityExists(cityId))
            {
                //City was not found in the db.
                return(NotFound());
            }

            var newPointOfInterest = AutoMapper.Mapper.Map <PointOfInterest>(pointOfInterest);

            //var newPointOfInterest = new PointOfInterest()
            //{
            //    Name = pointOfInterest.Name,
            //    Description = pointOfInterest.Description
            //};

            _cityRepository.AddPointOfInterestForCity(cityId, newPointOfInterest);

            if (!_cityRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var newPointOfInterestViewModel = AutoMapper.Mapper.Map <PointOfInterestViewModel>(newPointOfInterest);

            //Will return the url of the newly created resource.
            return(CreatedAtRoute("GetPointOfInterest", new { cityId = cityId, id = newPointOfInterestViewModel.Id }, newPointOfInterestViewModel));
        }
Example #7
0
        public ActionResult CreateEdit(PointOfInterestViewModel pointOfInterest)
        {
            PointOfInterest poi = this._repository.Get(pointOfInterest.Id);

            if (ModelState.IsValid || true)
            {
                if (poi == null)
                {
                    poi = new PointOfInterest();
                    this._repository.Create(poi);
                }

                pointOfInterest.Map(poi);

                this._repository.Commit();
                return(RedirectToAction(nameof(this.Index)));
            }
            return(View("CreateEdit", pointOfInterest));
        }
        public IActionResult CreatePointOfInterest(string cityId, [FromBody] PointOfInterestCreation pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided description should be different fron the name!");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var city = CityDataStore.Current.Cities.FirstOrDefault(p => p.Id == new Guid(cityId));

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

            var newPointOfInterest = new PointOfInterestViewModel()
            {
                Id          = Guid.NewGuid(),
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            city.PointOfInterest.Add(newPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest",
                                  new
            {
                cityId = city.Id.ToString(),
                id = newPointOfInterest.Id.ToString()
            }, newPointOfInterest));
        }
Example #9
0
        private void setImage(string path)
        {
            //Define the URI location of the image
            BitmapImage myBitmapImage = new BitmapImage();

            myBitmapImage.BeginInit();
            myBitmapImage.UriSource = new Uri(path);

            // To save significant application memory, set the DecodePixelWidth or
            // DecodePixelHeight of the BitmapImage value of the image source to the desired
            // height or width of the rendered image. If you don't do this, the application will
            // cache the image as though it were rendered as its normal size rather then just
            // the size that is displayed.
            // Note: In order to preserve aspect ratio, set DecodePixelWidth
            // or DecodePixelHeight but not both.
            //Define the image display properties
            myBitmapImage.DecodePixelHeight = 50;
            myBitmapImage.EndInit();

            PointOfInterestViewModel viewModel = this.DataContext as PointOfInterestViewModel;

            viewModel.Image = myBitmapImage;
        }
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestViewModel pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound());
            }

//            var finalPointOfInterest = Mapper.Map<Entities.PointOfInterest>(pointOfInterest);

            var finalPointOfInterest = new PointOfInterest()
            {
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            _cityInfoRepository.AddPointOfInterestForCity(cityId, finalPointOfInterest);

            if (!_cityInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

//            var createdPointOfInterestToReturn = Mapper.Map<ViewModels.PointOfInterestViewModel>(finalPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest", new
                                  { cityId = cityId, id = finalPointOfInterest.Id }, finalPointOfInterest));
        }
        public IActionResult UpdatePointOfInterest(int cityId, int id,
                                                   [FromBody] PointOfInterestViewModel pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound());
            }

            var pointOfInterestEntity = _cityInfoRepository.GetPointOfInterestForCity(cityId, id);

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

//            Mapper.Map(pointOfInterest, pointOfInterestEntity);
            pointOfInterestEntity.Description = pointOfInterest.Description;
            pointOfInterestEntity.Name        = pointOfInterest.Name;

            if (!_cityInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(NoContent()); //204
        }