public async Task <IHttpActionResult> Post(CreateLocationViewModels data)
        {
            try
            {
                int userId = (await CurrentUser()).Id;

                Photo primaryPhoto             = ModelBuilder.ConvertToModels(data.PrimaryPhoto, userId);
                IEnumerable <Photo> otherPhoto = ModelBuilder.ConvertToModels(data.OtherPhotos.AsEnumerable(), userId);

                Location location = ModelBuilder.ConvertToModels(data);

                IEnumerable <BusinessHour> businessHours = ModelBuilder.ConvertToModels(data.Days);

                bool result = await _locationService.Create(location, primaryPhoto, otherPhoto, businessHours, data.Tags);

                if (result)
                {
                    WrireTree();
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                _loggingService.Write(GetType().Name, nameof(Post), ex);

                return(InternalServerError(ex));
            }
        }
        public async Task <int> CreateWithLocation(Spot spot, Location location)
        {
            await _locationService.Create(location);

            spot.Location = location;

            return(await Create(spot));
        }
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            ILocationService service = testServer.Host.Services.GetService(typeof(ILocationService)) as ILocationService;
            var model = new ApiLocationServerRequestModel();

            model.SetProperties(2, 2, "B");
            CreateResponse <ApiLocationServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.LocationDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiLocationServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Exemple #4
0
        public async Task <int> CreateWithLocation(Marina marina, Location location)
        {
            marina.ThrowIfNull();
            location.ThrowIfNull();

            // Create location for marina
            await _locationService.Create(location);

            // Create marina
            await Create(marina);

            // Assign location to marina
            marina.Location = location;

            return(marina.MarinaId);
        }
        public ActionResult Create([Bind(Include = "Id,Name,Description,CreatedAt,CreatedBy,UpdatedAt,UpdatedBy")] Location location)
        {
            if (ModelState.IsValid)
            {
                _LocationService.Create(location);
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
        public ActionResult Create([Bind(Include = "LocationId,LocationName,Phone,Email,Address,City,State,ZipCode")] LocationViewModel location)
        {
            if (ModelState.IsValid)
            {
                _locationService.Create(location);
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
Exemple #7
0
        public async Task <Guid> CreateLocation(LocationDto location)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                location.Id = _locationService.Create(location);
                await uow.Commit();

                return(location.Id);
            }
        }
Exemple #8
0
 public IActionResult Create([FromBody] Location location)
 {
     try
     {
         EnsureHasPermission((int)MenuFeatureEnum.ManageOrganisactionSetting);
         locationService.Create(locationService.OrganisationId, location);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(new Error(ex.Message)));
     }
 }
        public async Task <IActionResult> Create(LocationRequestModel model)
        {
            var dto = mapper.Map <LocationDto>(model);

            var id = await locationService.Create(dto);

            if (id == null)
            {
                return(StatusCode(409));
            }

            return(Ok(id));
        }
        public async Task <IActionResult> Create([FromBody] Location location)
        {
            try
            {
                var createdLocation = await _locationService.Create(location);

                return(Ok(createdLocation));
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Error adding location: {exception.Message}");
                return(StatusCode(500));
            }
        }
Exemple #11
0
        public async Task <IActionResult> Create()
        {
            try
            {
                var request = string.Empty;

                using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
                {
                    request = await reader.ReadToEndAsync();
                }

                if (string.IsNullOrWhiteSpace(request))
                {
                    return(StatusCode(204, "No Content"));
                }

                var createRequest = JsonConvert.DeserializeObject <LocationCreateRequest.RootObject>(request);

                var createModel = new LocationModel()
                {
                    Name = createRequest.LocationCreate.Name
                };

                var query = await _locationService.Create(createModel);

                var model = new LocationCreateResponse.RootObject
                {
                    Created        = true,
                    LocationCreate = new LocationCreateResponse.LocationCreate()
                    {
                        Id   = query.Id,
                        Name = query.Name
                    }
                };

                return(StatusCode(200, JsonConvert.SerializeObject(model)));
            }
            catch (Exception ex)
            {
                var data = JsonConvert.SerializeObject(
                    new LocationCreateResponse.RootObject
                {
                    Created  = true,
                    ErrorMsg = ex.Message
                });

                return(StatusCode(500, JsonConvert.SerializeObject(data)));
            }
        }
Exemple #12
0
        public async Task <IActionResult> Create([Bind("LocationId,Latitude,Longitude")] Location location)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _service.Create(location);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (BusinessException exception)
                {
                    ModelState.TryAddModelError(exception.Key, exception.Message);
                }
            }
            return(View(location));
        }
Exemple #13
0
        public IActionResult Create([FromBody] LocationDto locationDto)
        {
            Location location = mapper.Map <Location>(locationDto);

            try
            {
                locationService.Create(location);
                return(Ok(location));
            }
            catch (ApplicationException ex)
            {
                return(BadRequest(new
                {
                    message = ex.Message
                }));
            }
        }
Exemple #14
0
        public IActionResult PostLocation(int userId, NewLocationRequest locationRequest)
        {
            var location = _mapper.Map <Location>(locationRequest);

            if (location.Timestamp.Year < 1900)
            {
                return(BadRequest());
            }

            try
            {
                _locationService.Create(location, userId);
                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
        public IActionResult Create([FromBody] LocationDto locationDto)
        {
            // map dto to entity
            var location = _mapper.Map <Location>(locationDto);

            try
            {
                // save
                Log.Information($"Attempting to save location: {location.Name} from user: {location.UserId}");
                _locationService.Create(location);
                return(Ok(location));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                Log.Error($"Failed to save Location");
                Log.Error(ex.StackTrace.ToString());
                return(BadRequest(new { message = ex.Message }));
            }
        }
Exemple #16
0
        public async Task <IActionResult> CreateLocation(CreateLocationRequest model)
        {
            var result = await _locationService.Create(model);

            return(Ok(result));
        }
Exemple #17
0
 public CreateResponse Post(LocationRequest request)
 {
     return(_locationService.Create(request));
 }
        public async Task <IActionResult> LocationCreate(decimal latitude, decimal longitude, string name, string city, string state, string country, string countryCode, string address, string route, string placeId, string website, string phoneNumber, string url)
        {
            var user = await _UserManager.FindByNameAsync(User.Identity.Name);

            var locationToBeCreated = new Location();

            if (placeId != null)
            {
                var location = _LocationService.GetLocationByPlaceId(placeId);
                if (location == null)
                {
                    locationToBeCreated = new Location()
                    {
                        Latitude         = latitude,
                        Longitude        = longitude,
                        DistanceToCenter = 0,
                        VisitCount       = 0,
                        Name             = name,
                        City             = city,
                        Country          = country,
                        CountryCode      = countryCode,
                        Address          = address + " " + route,
                        State            = state,
                        PlaceId          = placeId,
                        Website          = website,
                        PhoneNumber      = phoneNumber,
                        GoogleMapsUrl    = url
                    };

                    if (locationToBeCreated.City == null)
                    {
                        locationToBeCreated.City  = locationToBeCreated.State;
                        locationToBeCreated.State = null;
                    }
                    _LocationService.Create(locationToBeCreated);

                    //add the country to the visited country list:


                    await UpdateCountryCodeList(user.Id.ToString(), countryCode, null);

                    return(Redirect("experiencecreate/" + locationToBeCreated.LocationId));
                }
                else
                {
                    await UpdateCountryCodeList(user.Id.ToString(), countryCode, null);

                    return(Redirect("experiencecreate/" + location.LocationId));
                }
            }
            else
            {
                locationToBeCreated = new Location()
                {
                    Latitude         = latitude,
                    Longitude        = longitude,
                    DistanceToCenter = 0,
                    VisitCount       = 0,
                    Name             = name,
                    City             = city,
                    Country          = (country == null) ? Countries.GetCountryByAlpha2(countryCode).ShortName : country,
                    CountryCode      = countryCode,
                    Address          = address + " " + route,
                    State            = state,
                    PlaceId          = placeId,
                    Website          = website,
                    PhoneNumber      = phoneNumber,
                    GoogleMapsUrl    = "https://www.google.com/maps/search/?api=1&query=" + latitude + "," + longitude
                };

                var countryToAdd = Countries.GetCountryByShortName(locationToBeCreated.Country);

                if (countryToAdd != null)
                {
                    await UpdateCountryCodeList(user.Id.ToString(), countryToAdd.Alpha2.ToString(), null);
                }

                _LocationService.Create(locationToBeCreated);

                return(Redirect("experiencecreate/" + locationToBeCreated.LocationId));
            }
        }