コード例 #1
0
        public void ThrowsExcepionWhenAddingGeolocationWithURLThatCannotBeResolvedToIPToDb()
        {
            // assuming IP address is more important to location and we cannot depend on URL as it can point to many IPs
            var geolocationVM = new GeolocationViewModel()
            {
                City      = "Warszawa",
                Continent = "Africa",
                Country   = "Poland",
                IP        = null,
                IPType    = null,
                Lat       = 20,
                Lng       = 21,
                Url       = "somenotexistingcrazyurl.pl"
            };

            Assert.Throws <MongoWriteException>(() => controller.Post(geolocationVM).GetAwaiter().GetResult());
        }
コード例 #2
0
        public void ReturnsErrorsWhenValidatesGeolocationViewModelWithNoCountry()
        {
            var geolocationVM = new GeolocationViewModel()
            {
                City      = "Warszawa",
                Continent = "Africa",
                Country   = null,
                IP        = "1.1.1.1",
                IPType    = "IPv4",
                Lat       = 20,
                Lng       = 21,
                Url       = null
            };
            var validationResult = validator.Validate(geolocationVM);

            Assert.False(validationResult.IsValid);
        }
コード例 #3
0
        public void Returns200WhenAddingValidGeolocationToDb()
        {
            var geolocationVM = new GeolocationViewModel()
            {
                City      = "Warszawa",
                Continent = "Africa",
                Country   = "Poland",
                IP        = "1.1.1.1",
                IPType    = "IPv4",
                Lat       = 20,
                Lng       = 21,
                Url       = null
            };
            var actionResult = controller.Post(geolocationVM).GetAwaiter().GetResult();

            Assert.IsType <OkNegotiatedContentResult <GeolocationViewModel> >(actionResult);
        }
コード例 #4
0
        public async Task <IHttpActionResult> Put([FromUri] string id,
                                                  [FromBody] GeolocationViewModel viewModel)
        {
            if (id is null)
            {
                return(BadRequest("Id of geolocation to update cannot be null."));
            }

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

            var result = await geolocationService.UpdateGeolocationAsync(id, viewModel);

            return(Ok(result));
        }
コード例 #5
0
        public async Task <GeolocationViewModel> UpdateGeolocationAsync(string id, GeolocationViewModel viewModel)
        {
            var geo = (await geolocations.FindAsync(g => g.Id == id)).SingleOrDefault();

            if (geo == null)
            {
                throw new LocationApiEntityNotFoundException(typeof(Geolocation), id);
            }

            mapper.Map(viewModel, geo);

            await ValidateAndUpdateGeolocationBeforeDbAsync(geo);

            await geolocations.ReplaceOneAsync(g => g.Id == id, geo);

            return(mapper.Map <GeolocationViewModel>(geo));
        }
コード例 #6
0
        public void ReturnsEntityWithTruncatedURLWhenAddingValidGeolocationWithLongURLToDb()
        {
            var geolocationVM = new GeolocationViewModel()
            {
                City      = "Warszawa",
                Continent = "Africa",
                Country   = "Poland",
                IP        = null,
                IPType    = null,
                Lat       = 20,
                Lng       = 21,
                Url       = "something.very.long.here.onet.pl"
            };
            var actionResult  = controller.Post(geolocationVM).GetAwaiter().GetResult();
            var okResult      = Assert.IsType <OkNegotiatedContentResult <GeolocationViewModel> >(actionResult);
            var newGeolocaion = okResult.Content;

            Assert.Equal("onet.pl", newGeolocaion.Url);
        }
コード例 #7
0
        public void ReturnsEntityWithNewIDAndResolvedURLWhenAddingValidGeolocationWithEmptyURLToDb()
        {
            var geolocationVM = new GeolocationViewModel()
            {
                City      = "Warszawa",
                Continent = "Africa",
                Country   = "Poland",
                IP        = "1.1.1.1",
                IPType    = "IPv4",
                Lat       = 20,
                Lng       = 21,
                Url       = null
            };
            var actionResult  = controller.Post(geolocationVM).GetAwaiter().GetResult();
            var okResult      = Assert.IsType <OkNegotiatedContentResult <GeolocationViewModel> >(actionResult);
            var newGeolocaion = okResult.Content;

            Assert.NotNull(newGeolocaion.Id);
            Assert.NotNull(newGeolocaion.Url);
        }
コード例 #8
0
        // GET: Geolocations
        public ActionResult Index(int?id)
        {
            GeolocationViewModel geolocationViewModel = new GeolocationViewModel();
            Geolocation          geolocation          = new Geolocation();

            if (id != null)
            {
                geolocation = geolocationService.GetGeolocationById(id);

                geolocationViewModel = new GeolocationViewModel()
                {
                    Id       = geolocation.Id,
                    IsActive = geolocation.IsActive,
                    Address  = geolocation.Address + " " + geolocation.City.Name,
                    CityName = geolocation.City.Name
                };
            }

            ViewBag.CityList = new SelectList(genericService.GetList <City>(), "Id", "Name");

            return(View(geolocationViewModel));
        }
コード例 #9
0
 public GeolocationPage()
 {
     InitializeComponent();
     geolocationViewModel = new GeolocationViewModel(this);
 }
コード例 #10
0
        public ActionResult SaveOrUpdate(GeolocationViewModel model)
        {
            string newData = string.Empty, oldData = string.Empty;

            try
            {
                int         id             = model.Id;
                Geolocation geolocation    = null;
                Geolocation oldGeolocation = null;
                if (model.Id == 0)
                {
                    geolocation = new Geolocation
                    {
                        Address  = model.Address,
                        IsActive = true,
                        CityId   = model.CityId
                    };

                    oldGeolocation = new Geolocation();
                    oldData        = new JavaScriptSerializer().Serialize(oldGeolocation);
                    newData        = new JavaScriptSerializer().Serialize(geolocation);
                }
                else
                {
                    geolocation    = genericService.GetList <Geolocation>().Where(o => o.Id == model.Id).FirstOrDefault();
                    oldGeolocation = genericService.GetList <Geolocation>().Where(o => o.Id == model.Id).FirstOrDefault();

                    oldData = new JavaScriptSerializer().Serialize(new Geolocation()
                    {
                        Id       = oldGeolocation.Id,
                        Address  = oldGeolocation.Address,
                        IsActive = oldGeolocation.IsActive
                    });

                    geolocation.Address = model.Address;
                    bool Example = Convert.ToBoolean(Request.Form["IsActive.Value"]);
                    geolocation.IsActive = model.IsActive;
                    geolocation.CityId   = model.CityId;

                    newData = new JavaScriptSerializer().Serialize(new Geolocation()
                    {
                        Id       = geolocation.Id,
                        Address  = geolocation.Address,
                        IsActive = geolocation.IsActive
                    });
                }

                genericService.SaveOrUpdate <Geolocation>(geolocation, geolocation.Id);

                //CommonService.SaveDataAudit(new DataAudit()
                //{
                //    Entity = "Geolocations",
                //    NewData = newData,
                //    OldData = oldData,
                //    UpdatedOn = DateTime.Now,
                //    UserId = User.Identity.GetUserId()
                //});

                TempData["Message"] = ResourceData.SaveSuccessMessage;
            }
            catch (Exception ex)
            {
                TempData["Message"] = string.Format(ResourceData.SaveErrorMessage, ex.InnerException);
            }


            return(RedirectToAction("Index", "Geolocation"));
        }
コード例 #11
0
 public async Task PostLocation(GeolocationViewModel position)
 {
     await _gpsService.CreateLocation(position);
 }