Exemplo n.º 1
0
        public async Task SetLocation([Remainder] string location)
        {
            IGuildUser guser = Context.Message.Author as IGuildUser;
            EntityUser user  = new EntityUser(guser);

            if (_userRepo.GetUserById(user.Id) != null)
            {
                user = _userRepo.GetUserById(user.Id);
            }

            //check if location exists
            WeatherModel wm = await WeatherProcessor.GetWeatherDataName(location);

            if (wm == null)
            {
                throw new NoLocationFoundException();
            }

            if (_repo.UserHasLocation(user))
            {
                _repo.ChangeLocation(user, location);
                _repo.SaveChanges();
                await Context.Channel.SendMessageAsync($"Location updated to {location}");
            }
            else
            {
                _repo.AddLocation(user, location);
                _repo.SaveChanges();
                await Context.Channel.SendMessageAsync($"Location set to {location}");
            }
        }
Exemplo n.º 2
0
 public async Task <ActionResult <string> > AddLocation(Location location)
 {
     try
     {
         //var l = locationRepository.GetLocationByUserID(location.UserID);
         //if (l != null)
         //{
         //    if(await generalRepository.Update(location))
         //    {
         //        return Ok(location);
         //    }
         //    else
         //    {
         //        return StatusCode(StatusCodes.Status500InternalServerError);
         //    }
         //}
         //else
         //{
         if (await locationRepository.AddLocation(location))
         {
             return(Ok(location));
         }
         else
         {
             return(StatusCode(StatusCodes.Status500InternalServerError));
         }
         //}
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Exemplo n.º 3
0
        public bool AddLocation(Location location)
        {
            logger.LogInformation("Locations Business Logic - AddLocation");

            locationRepository.AddLocation(location);

            return(true);
        }
Exemplo n.º 4
0
        public ActionResult AddLocation(Location location)
        {
            _repo.AddLocation(location);
            var model = _repo.RetrieveLocations();

            model = SterilizeModel(model);

            return(View(model));
        }
Exemplo n.º 5
0
 public HttpResponseMessage Post(Location location)
 {
     if (base.ModelState.IsValid)
     {
         _locationsRepo.AddLocation(location);
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     return(base.Request.CreateErrorResponse(HttpStatusCode.BadRequest, base.ModelState));
 }
Exemplo n.º 6
0
 public IActionResult AddLocation(Location l)
 {
     if (ModelState.IsValid)
     {
         _repository.AddLocation(l);
         return(RedirectToAction("DetailLocation", new { id = l.locationId }));
     }
     return(View(l));
 }
Exemplo n.º 7
0
        public IActionResult AddLocation(MapViewModel mapmodel)
        {
            if (!ModelState.IsValid || User.Identity?.Name == null)
            {
                return(RedirectToAction("Error"));
            }

            var currentEmail = User.Identity.Name;

            if (mapmodel.Comment != null && mapmodel.Name != null)
            {
                _locationRepository.AddLocation(mapmodel.Lon, mapmodel.Lat, mapmodel.Comment, mapmodel.Name,
                                                mapmodel.Shared, currentEmail);
            }
            else
            {
                _locationRepository.AddLocation(mapmodel.Lon, mapmodel.Lat, mapmodel.Shared, currentEmail);
            }
            return(RedirectToAction("Map"));
        }
Exemplo n.º 8
0
        public IActionResult AddLocation(Location locationToAdd)
        {
            var wasAddSuccessful = _locationRepository.AddLocation(locationToAdd);

            if (wasAddSuccessful)
            {
                return(Ok());
            }

            return(Forbid());
        }
Exemplo n.º 9
0
 public void AddLocation(Models.Location l)
 {
     Domain.Location loc = new();
     loc.ID   = l.ID;
     loc.Name = l.Name;
     foreach (var ip in l.Inventory)
     {
         Domain.Product p = new(ip.ID, ip.Name, ip.Price);
         loc.SetProductAmount(p, ip.Amount);
     }
     _repo.AddLocation(loc);
 }
        public ActionResult <LocationDto> Createlocation(LocationForCreationDto location)
        {
            var locationEntity = _mapper.Map <Location>(location);

            _locationRepository.AddLocation(locationEntity);
            _locationRepository.Save();

            var locationToReturn = _mapper.Map <LocationDto>(locationEntity);

            return(CreatedAtRoute("GetLocation",
                                  new { locationId = locationToReturn.Id },
                                  locationToReturn));
        }
Exemplo n.º 11
0
        public async Task AddToEvent(Guid eventId, AddLocationToEventRequest request)
        {
            var @event = await _eventRepository.Get(eventId);

            EnsureEventExists(@event);

            var newLocation = _mapper.Map <Location>(request.Location);

            await ValidateLocation(newLocation);

            _locationRepository.AddLocation(@event, newLocation);

            await EnsureLocationIsSavedInDataBase();
        }
Exemplo n.º 12
0
        public void AddConference(AddEventDetailModel addEvent)
        {
            Conference current = new Conference();

            if (addEvent.isRemote == false)
            {
                current.LocationId = _locationRepository.AddLocation(addEvent.DictionaryCityId, addEvent.LocationName);
            }
            else
            {
                current.LocationId = 131;
            }
            current.ConferenceTypeId     = addEvent.ConferenceTypeId;
            current.ConferenceCategoryId = addEvent.DictionaryConferenceCategoryId;
            current.HostEmail            = addEvent.HostEmail;
            current.StartDate            = addEvent.StartDate;
            current.EndDate        = addEvent.EndDate;
            current.ConferenceName = addEvent.ConferenceName;
            this._dbContext.Conference.Add(current);
            this._dbContext.SaveChanges();
            int conferenceId = current.ConferenceId;

            AddSpeakerXConference(conferenceId, addEvent.SpeakerId);
        }
Exemplo n.º 13
0
        public ActionResult Edit(LocationBase location)
        {
            var previousRecord = _repository.GetLocation(location.ConferenceId, location.LocationId);

            if (previousRecord == null)
            {
                _repository.AddLocation(ref location, User.UserID);
            }
            else
            {
                location.CreatedOnDate   = previousRecord.CreatedOnDate;
                location.CreatedByUserID = previousRecord.CreatedByUserID;
                _repository.UpdateLocation(location, User.UserID);
            }
            return(ReturnRoute(location.ConferenceId, View("View", _repository.GetLocation(location.ConferenceId, location.LocationId))));
        }
Exemplo n.º 14
0
        public void InitializeGoogleLocations()
        {
            // Getting the place_id list and finding the details about each restaurant
            foreach (var placesId in _placesService.GetPlacesList())
            {
                // Getting the details of the information with the place_id
                DetailResult result = _placesService.GetDetailResult(placesId);

                // Creating new restaurant object with the information from Places API
                Restaurant newRestaurant = new Restaurant
                {
                    Name          = result.Name,
                    Phone         = result.FormattedPhoneNumber,
                    Address1      = result.FormattedAddress,
                    City          = result.FormattedAddress.Split(',')[1],
                    State         = result.FormattedAddress.Split(',')[2].Split(' ')[1],
                    ZipCode       = result.FormattedAddress.Split(',')[2].Split(' ')[2],
                    DateUpdated   = DateTime.Now,
                    GooglePlaceId = result.PlaceId
                };

                // Adding new restaurant
                _restaurantRepository.AddRestaurant(newRestaurant);

                // Creating a location object with the result
                Location newLocation = new Location
                {
                    Latitude     = result.Geometry.Location.Lat,
                    Longitude    = result.Geometry.Location.Lng,
                    RestaurantId = newRestaurant.RestaurantId
                };

                // Adding new location for the restaurant
                _locationRepository.AddLocation(newLocation);

                // Initializing status of the restaurant
                Status newStatus = new Status
                {
                    RestaurantId = newRestaurant.RestaurantId,
                    DriveThru    = 0,
                    InStore      = 0
                };

                // Adding the Status to Db
                _statusRepository.AddStatus(newStatus);
            }
        }
Exemplo n.º 15
0
        public ActionResult CreateLocation(Location location)
        {
            if (ModelState.IsValid)
            {
                locationRepository.AddLocation(location);
            }
            else
            {
                ModelState.AddModelError("Error", "One or more Fields were empty.");
            }
            var adminEventEditViewModel = (AdminEventEditViewModel)Session["adminEventEditViewModel"];

            adminEventEditViewModel.Location   = location;
            Session["adminEventEditViewModel"] = adminEventEditViewModel;

            return(RedirectToAction("AdminEventEdit"));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Add([FromBody] Location location)
        {
            //TODO: Handle error in the middleware and add try catch there only
            ISingleModelResponse <Location> response = new SingleModelResponse <Location>();

            try
            {
                response.Model = await _locationRepository.AddLocation(location);

                response.Message = "Location is added Successfully";
            }
            catch (Exception ex)
            {
                _logger.LogError(entities.LoggingEvents.InsertItem, ex, "Error while adding a new location");
                response.IsError      = true;
                response.ErrorMessage = "Some error occured, Please contact to administration";
                return(BadRequest(response));
            }
            return(Ok(response));
        }
Exemplo n.º 17
0
        private async Task <string> AddLocation(Message message, string[] commands, string[] locations)
        {
            var user = _pockyUserRepository.GetUser(message.Sender.UserId);

            if (!(user.HasRole(Role.Admin) || user.HasRole(Role.Config)))
            {
                return("Permission denied. You may only use the 'get' command.");
            }

            if (commands.Length != 3)
            {
                return("You must specify a location name to add.");
            }

            if (locations.Contains(commands[2], StringComparer.InvariantCultureIgnoreCase))
            {
                return($"Location value {commands[2]} has already been added.");
            }

            await _locationRepository.AddLocation(commands[2]);

            return("Location has been added.");
        }
        public async Task <ActionResult <Location> > AddLocation(Location newLocation)
        {
            try
            {
                if (newLocation == null)
                {
                    return(BadRequest());
                }
                var existingLoc = await locationRepository.CheckIfLocationExists(newLocation.LibraryName);

                if (existingLoc != null)
                {
                    return(BadRequest("Library Already Exists"));
                }

                var result = await locationRepository.AddLocation(newLocation);

                return(CreatedAtAction(nameof(GetLocation), new { id = newLocation.id }, newLocation));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database"));
            }
        }
Exemplo n.º 19
0
        /**
         * Add or update venue details in database
         */
        private void UpdateVenueDetails()
        {
            // Get all venues
            List <Venue> venues = _venueRepository.GetAllVenues();

            // Get only venues that don't have details
            List <Venue> venuesWithoutDetails = venues.Where(v => v.Address1 == null).ToList();

            foreach (var venue in venuesWithoutDetails)
            {
                // Venue owners have ability to manually update their venues, do not auto-update
                if (VenueHasOwner(venue))
                {
                    continue;
                }

                // Get Place details from Google API using GooglePlaceId
                PlaceDetailsResponse venueDetails = _placesApi.GetPlaceDetailsById(venue.GooglePlaceId);

                // Map response data to database model properties
                venue.Phone = venueDetails.Result.FormattedPhoneNumber;
                string streetAddress = null;
                foreach (var addressComponent in venueDetails.Result.AddressComponents)
                {
                    // Map Address from response to database model
                    var type = addressComponent.Types.FirstOrDefault();
                    switch (type)
                    {
                    case "street_number":
                        streetAddress += addressComponent.ShortName + " ";
                        break;

                    case "route":
                        streetAddress += addressComponent.ShortName;
                        break;

                    case "locality":
                        venue.City = addressComponent.ShortName;
                        break;

                    case "administrative_area_level_1":
                        venue.State = addressComponent.ShortName;
                        break;

                    case "postal_code":
                        venue.ZipCode = addressComponent.ShortName;
                        break;

                    default:
                        continue;
                    }

                    venue.Address1 = streetAddress;
                }

                // Update Venue entity
                _venueRepository.Edit(venue);

                // Map OpeningHours API response to BusinessHours entity
                if (venueDetails.Result.OpeningHours != null)
                {
                    // Initialize new BusinessHours entity using VenueID as foreign key
                    BusinessHours hours = new BusinessHours {
                        VenueId = venue.VenueId
                    };

                    foreach (var period in venueDetails.Result.OpeningHours.Periods)
                    {
                        hours.DayOfWeek = period.Open.Day;

                        string openTime = period.Open?.Time.Insert(2, ":");
                        if (!string.IsNullOrEmpty(openTime))
                        {
                            hours.OpenTime = DateTime.Parse(openTime).TimeOfDay;
                        }

                        string closeTime = period.Close?.Time.Insert(2, ":");
                        if (!string.IsNullOrEmpty(closeTime))
                        {
                            hours.CloseTime = DateTime.Parse(closeTime).TimeOfDay;
                        }

                        // Add BusinessHours entity
                        _businessHoursRepository.AddBusinessHours(hours);
                    }
                }

                // Map Review API response to Review database entity
                if (venueDetails.Result.Reviews != null)
                {
                    foreach (var review in venueDetails.Result.Reviews)
                    {
                        DateTime timestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

                        Review reviewEntity = new Review
                        {
                            IsGoogleReview = true,
                            GoogleAuthor   = review.AuthorName,
                            VenueId        = venue.VenueId,
                            Comments       = review.Text,
                            Rating         = review.Rating,

                            Timestamp = timestamp.AddSeconds(review.Time).ToLocalTime()
                        };

                        _reviewRepository.AddReview(reviewEntity);
                    }
                }

                // Map Location API response to Location database entity
                if (venueDetails.Result.Geometry != null)
                {
                    Location locationEntity = new Location
                    {
                        Latitude =
                            venueDetails.Result.Geometry.GeometryLocation.Latitude.ToString(CultureInfo.InvariantCulture),
                        Longitude =
                            venueDetails.Result.Geometry.GeometryLocation.Longitude.ToString(CultureInfo.InvariantCulture),
                        VenueId = venue.VenueId
                    };

                    // Add Location entity
                    _locationRepository.AddLocation(locationEntity);
                }
            }
        }
 public Result AddLocation(LocationDto location)
 {
     return(locationRepository.AddLocation(parser.ToLocation(location)));
 }
Exemplo n.º 21
0
 public IActionResult AddNewLocation(decimal lon, decimal lat, string comment, string name, string userEmail)
 {
     _locationRepository.AddLocation(lon, lat, comment, name, false, userEmail);
     return(RedirectToAction("Locations"));
 }
Exemplo n.º 22
0
 public int AddLocation(Location theLocation)
 {
     return(_repository.AddLocation(theLocation));
 }
Exemplo n.º 23
0
 public IActionResult Post([FromBody] LocationModel value)
 {
     Repository.AddLocation(value);
     return(CreatedAtAction("Get", new { id = value.Id }, value));
 }
Exemplo n.º 24
0
 public void AddLocation(Location newLocation)
 {
     _repo.AddLocation(newLocation);
 }
Exemplo n.º 25
0
        public async Task <IActionResult> CreateLocation(Location location)
        {
            await _locationRepository.AddLocation(location);

            return(View("~/Views/Rental/CreateRental.cshtml", location));
        }
Exemplo n.º 26
0
 public void AddLocation(Location newLocation)
 {
     //TODO: Add BL
     _repo.AddLocation(newLocation);
 }
        public async Task <bool> Post([FromBody] Location item)
        {
            await _locRepository.AddLocation(item);

            return(true);
        }
Exemplo n.º 28
0
 public void AddLocationTest()
 {
     Assert.AreEqual(_locationRepo.AddLocation(mock.mockLocation).LocationID, 5);
 }
Exemplo n.º 29
0
 public Task <Guid> CreateLocation(Location location)
 {
     return(_locationRepository.AddLocation(location));
 }
Exemplo n.º 30
0
 public Location AddLocation(Location newLocation)
 {
     //TODO: Add BL
     return(_repo.AddLocation(newLocation));
 }