public async Task <int> AddAsync(AddLocationViewModel addLocationViewModel)
        {
            Location locationToAdd = mapper.Map <Location>(addLocationViewModel);

            if (addLocationViewModel.Image != null)
            {
                if (addLocationViewModel.Image.ContentType.ToLower().Contains("image") && addLocationViewModel.Image.Length <= maxImageSize)
                {
                    using (System.IO.Stream imageFileStream = addLocationViewModel.Image.OpenReadStream())
                    {
                        string imageUrl = await imagesService.UploadImageAsync(imageFileStream);

                        locationToAdd.Image = new Image {
                            Url = imageUrl
                        };
                    }
                }
            }

            if (locationToAdd.Title == null)
            {
                locationToAdd.Title = configuration["DefaultLocationName"];
            }
            locationToAdd.AddedOn = DateTime.UtcNow;

            dbContext.Locations.Add(locationToAdd);
            await dbContext.SaveChangesAsync();

            return(locationToAdd.Id);
        }
Beispiel #2
0
 public LocationAddressesPopup(Position tapPosition)
 {
     InitializeComponent();
     _tapPosition   = tapPosition;
     vm             = BindingContext as AddLocationViewModel;
     vm.TapPosition = _tapPosition;
 }
Beispiel #3
0
 public Location(AddLocationViewModel model)
 {
     LocationId = Guid.NewGuid();
     Latitude   = model.Latitude;
     Longitude  = model.Longitude;
     Address    = model.Address;
 }
        public void AddLocationTest()
        {
            Mock <IImagesService> imagesServiceMock = new Mock <IImagesService>();

            imagesServiceMock
            .Setup(ls => ls.UploadImageAsync(new StreamMock()))
            .Returns(Task.FromResult("url"));

            using (ApplicationDbContext dbContext = serviceProvider.GetService <ApplicationDbContext>())
            {
                LocationsService locationsService = new LocationsService(dbContext,
                                                                         serviceProvider.GetService <IMapper>(),
                                                                         serviceProvider.GetService <IConfiguration>(),
                                                                         imagesServiceMock.Object);

                AddLocationViewModel locationViewModel = new AddLocationViewModel
                {
                    Title       = "LocationTitle",
                    Description = "LocationDescription",
                    TownId      = 1,
                };

                locationsService.AddAsync(locationViewModel).GetAwaiter().GetResult();

                Location location = dbContext.Locations.First();

                Assert.Equal(locationViewModel.Title, location.Title);
            }
        }
        public void AddLocation(AddLocationViewModel model)
        {
            try
            {
                if (model != null)
                {
                    MasterLocation entity = new MasterLocation();
                    entity.LocationName  = model.LocationName;
                    entity.PinCode       = model.PinCode;
                    entity.CountryRowID  = model.CountryRowID;
                    entity.StateRowID    = model.StateRowID;
                    entity.DistrictRowID = model.DistrictRowID;
                    //entity.CityRowID = model.CityRowID;

                    db.MasterLocations.Add(entity);
                }
                else
                {
                    throw new Exception("Location could not be blank!");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void AddLocationWithoutName()
        {
            Mock <IImagesService> imagesServiceMock = new Mock <IImagesService>();

            imagesServiceMock
            .Setup(ls => ls.UploadImageAsync(new StreamMock()))
            .Returns(Task.FromResult("url"));

            using (ApplicationDbContext dbContext = serviceProvider.GetService <ApplicationDbContext>())
            {
                IConfiguration configuration = serviceProvider.GetService <IConfiguration>();

                LocationsService locationsService = new LocationsService(dbContext,
                                                                         serviceProvider.GetService <IMapper>(),
                                                                         configuration,
                                                                         imagesServiceMock.Object);

                AddLocationViewModel locationViewModel = new AddLocationViewModel
                {
                    Description = "LocationDescription",
                    TownId      = 1,
                };

                locationsService.AddAsync(locationViewModel).GetAwaiter().GetResult();

                int      locations           = dbContext.Locations.CountAsync().GetAwaiter().GetResult();
                Location locationWithoutName = dbContext.Locations.FirstAsync().GetAwaiter().GetResult();

                Assert.Equal(configuration["DefaultLocationName"], locationWithoutName.Title);

                Assert.True(locations == 1);
            }
        }
        public IActionResult Add()
        {
            IList <Place>        places = context.Places.ToList();
            AddLocationViewModel addLocationViewModel = new AddLocationViewModel(places);

            return(View(addLocationViewModel));
        }
        public ActionResult Add(AddLocationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                if (!this.IsMegaAdmin())
                {
                    model.SeletedOrganisationId = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId());
                }
                else
                {
                    model.Organisations = this.organisationService.GetAll().ToList()
                                          .ConvertAll(x => new OrganisationViewModel
                    {
                        Id   = x.Id,
                        Name = x.Name
                    });
                }
                return(View(model));
            }

            //Check is there a location with the same code
            if (this.locationService.Exist(model.Code))
            {
                if (!this.IsMegaAdmin())
                {
                    model.SeletedOrganisationId = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId());
                }
                else
                {
                    model.Organisations = this.organisationService.GetAll().ToList()
                                          .ConvertAll(x => new OrganisationViewModel
                    {
                        Id   = x.Id,
                        Name = x.Name
                    });
                }
                this.ModelState.AddModelError("", LocationTr.ExistLocation);
                return(View(model));
            }

            if ((model.Longitude != null && model.Latitude != null) ||
                (model.Country != null && model.Town != null && model.Street != null))
            {
                this.locationService.Add(new Location
                {
                    Code           = model.Code,
                    Country        = model.Country,
                    Latitude       = model.Latitude,
                    Longitude      = model.Longitude,
                    Street         = model.Street,
                    StreetNumber   = model.StreetNumber != null ? model.StreetNumber.Value : 0,
                    Town           = model.Town,
                    OrganisationId = model.SeletedOrganisationId
                });

                return(Redirect("/HelpModule/Location/Index"));
            }
            ModelState.AddModelError("", LocationTr.Validate);
            return(View(model));
        }
 public AddLocationPage()
 {
     InitializeComponent();
     _viewModel      = new AddLocationViewModel();
     _viewModel.Date = DateTime.Now;
     _viewModel.Time = DateTime.Now.TimeOfDay;
     BindingContext  = _viewModel;
     ProgenyCollectionView.ItemsSource = _viewModel.ProgenyCollection;
 }
Beispiel #10
0
 private void addModelClose(object sender, EventArgs e)
 {
     locationViewModel.Apply -= new EventHandler(addModelApply);
     locationViewModel.Close -= new EventHandler(addModelClose);
     locationWindow.Closed   -= new EventHandler(addModelClose);
     locationWindow           = null;
     locationViewModel        = null;
     Application.Current.MainWindow.Focus();
 }
        public void AddLocationTest()
        {
            AddLocationViewModel location = new AddLocationViewModel(new DataRepository());

            Assert.IsNotNull(location.CurrentLocation.Availability);
            Assert.IsNotNull(location.CurrentLocation.CostRate);
            Assert.IsNotNull(location.CurrentLocation.Id);
            Assert.IsNull(location.CurrentLocation.Name);
        }
Beispiel #12
0
 public IActionResult AddLocation([FromForm] AddLocationViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     locationService.AddLocation(model.City, model.Country, model.Address, model.OrchestraId);
     return(Redirect(Url.Action("Index", "Locations")));
 }
        public IActionResult Add(AddLocationViewModel addLocationViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(addLocationViewModel));
            }

            _meetingService.AddLocation(addLocationViewModel.Location);
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #14
0
        public IActionResult Create(AddLocationViewModel model)
        {
            if (ModelState.IsValid)
            {
                _locationService.Add(model);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <IActionResult> Add()
        {
            AddLocationViewModel addLocationViewModel = new AddLocationViewModel
            {
                AllLocationTypes = await locationTypesService.GetAllLocationTypesAsync(),
                AllTowns         = await townsService.GetAllTownsAsync()
            };

            return(View(addLocationViewModel));
        }
Beispiel #16
0
        public async Task <IActionResult> AddLocation(AddLocationViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await this.locationService.Add(viewModel.Map());

            return(Redirect("/Locations"));
        }
Beispiel #17
0
 public static Location Map(this AddLocationViewModel viewModel)
 {
     return(new Location
     {
         Name = viewModel.Name,
         Address = new Address
         {
             Text = viewModel?.Address,
             ZipOrPostcode = viewModel?.ZipOrPostcode
         }
     });
 }
Beispiel #18
0
        public async Task <IActionResult> Add(AddLocationViewModel model)
        {
            if (ModelState.IsValid)
            {
                Location location = await _client.AddLocationAsync(model.Name);

                ModelState.Clear();
                model.Clear();
                model.Message = $"Location '{location.Name}' added successfully";
            }

            return(View(model));
        }
Beispiel #19
0
        public AddLocationView()
        {
            vm = new AddLocationViewModel(App.container.Resolve <IEntityController <Locatie> >());

            BindingContext = vm;

            InitializeComponent();

            var position = new Position(52.048565, 5.095628);

            myMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMeters(400)));

            myMap.MapTapped += MyMap_MapTapped;
        }
Beispiel #20
0
        public async Task AddLocation_LocationViewModelInValid_ReturnsBadRequest()
        {
            // Arrange
            ILocationService    service    = Substitute.For <ILocationService>();
            LocationsController controller = GetController(locationService: service);

            controller.ModelState.AddModelError("Name", "Required");
            AddLocationViewModel viewModel = new AddLocationViewModel();

            // Act
            IActionResult result = await controller.AddLocation(viewModel);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
        public void Map_LocationViewModel_Location()
        {
            // Arrange
            AddLocationViewModel viewModel = new AddLocationViewModel {
                Name = "Contoso", Address = "Seattle", ZipOrPostcode = "54321"
            };

            // Act
            Location location = viewModel.Map();

            // Assert
            Assert.Equal("Contoso", location.Name);
            Assert.Equal("Seattle", location.Address.Text);
            Assert.Equal("54321", location.Address.ZipOrPostcode);
        }
Beispiel #22
0
        public async Task AddLocation_LocationViewModel_AddOnServiceHitWithMappedLocation()
        {
            // Arrange
            ILocationService     service    = Substitute.For <ILocationService>();
            LocationsController  controller = GetController(locationService: service);
            AddLocationViewModel viewModel  = new AddLocationViewModel {
                Name = "Contoso", Address = "Seattle", ZipOrPostcode = "54321"
            };

            // Act
            IActionResult result = await controller.AddLocation(viewModel);

            // Assert
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            service.Received(1).Add(Arg.Any <Location>());
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Assert.IsType <RedirectResult>(result);
        }
 public IActionResult AddLocation(AddLocationViewModel addLocationViewModel)
 {
     if (ModelState.IsValid)
     {
         Location newlocation = new Location
         {
             Name    = addLocationViewModel.Name.ToUpper(),
             Address = addLocationViewModel.Address.ToUpper(),
             City    = addLocationViewModel.City.ToUpper(),
             County  = CountyAPI.GetCounty(addLocationViewModel.Address, addLocationViewModel.City + "," + addLocationViewModel.State).ToUpper(),
             State   = addLocationViewModel.State.ToUpper(),
             ZIP     = addLocationViewModel.ZIP
         };
         context.Add(newlocation);
         context.SaveChanges();
         return(Redirect("/Location/Index"));
     }
     return(View(addLocationViewModel));
 }
        public ActionResult Add()
        {
            var viewModel = new AddLocationViewModel();

            if (!this.IsMegaAdmin())
            {
                viewModel.SeletedOrganisationId = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId());
            }
            else
            {
                viewModel.Organisations = this.organisationService.GetAll().ToList()
                                          .ConvertAll(x => new OrganisationViewModel
                {
                    Id   = x.Id,
                    Name = x.Name
                });
            }
            return(View(viewModel));
        }
        public async Task <IActionResult> Add(AddLocationViewModel addLocationViewModel)
        {
            if (!ModelState.IsValid)
            {
                addLocationViewModel.AllLocationTypes = await locationTypesService.GetAllLocationTypesAsync();

                addLocationViewModel.AllTowns = await townsService.GetAllTownsAsync();

                return(View(addLocationViewModel));
            }

            int locationId = await locationsService.AddAsync(addLocationViewModel);

            if (locationId > 0)
            {
                TempData["locationAdded"] = true;
            }

            return(LocalRedirect("/#locationAdded"));
        }
Beispiel #26
0
        public IActionResult Add(AddLocationViewModel addLocationViewModel)
        {
            if (ModelState.IsValid)
            {
                Place newPlace = context.Places.Single(c => c.ID == addLocationViewModel.PlaceID);

                Location newLocation = new Location
                {
                    Nation    = addLocationViewModel.Nation,
                    City      = addLocationViewModel.City,
                    Place     = newPlace,
                    PlaceName = addLocationViewModel.PlaceName
                };

                context.Locations.Add(newLocation);
                context.SaveChanges();

                return(Redirect("/Location"));
            }

            return(View(addLocationViewModel));
        }
Beispiel #27
0
 public AddLocationWindow(ILocationReader reader, IEventAggregator eventAggregator)
 {
     InitializeComponent();
     DataContext = new AddLocationViewModel(reader, eventAggregator);
 }
      public IActionResult AddLocation()
      {
          AddLocationViewModel addLocationViewModel = new AddLocationViewModel();

          return(View(addLocationViewModel));
      }
        public void CommandTestAdd()
        {
            AddLocationViewModel location = new AddLocationViewModel(new DataRepository());

            Assert.IsTrue(location.Add.CanExecute(null));
        }
 public void Add(AddLocationViewModel location)
 {
     _locationRepository.Insert(new Location(location));
 }