Beispiel #1
0
        /// <summary>
        /// Edit location.
        /// </summary>
        /// <param name="id">Id of the location to edit.</param>
        /// <param name="location">Location model.</param>
        /// <param name="userEmail">Current user email.</param>
        /// <returns></returns>
        public async Task <bool> EditLocationAsync(Guid id, LocationCreateRequestDto location, string userEmail)
        {
            // Get current user id
            var user = await _accountManager.GetAccountInfoAsync(userEmail);

            if (user == null)
            {
                return(false);
            }

            // Get location to edit and check user rights
            var currentLocation = await _locationRepository.GetLocationAsync(id, false);

            if (currentLocation == null || currentLocation.OwnerId != user.Id)
            {
                return(false);
            }

            currentLocation.Name         = location.Name;
            currentLocation.IsPublic     = location.IsPublic;
            currentLocation.IsSearchable = location.IsSearchable;
            currentLocation.ModifiedAt   = DateTime.UtcNow;
            await _locationRepository.EditAsync(currentLocation);

            return(true);
        }
Beispiel #2
0
        public async Task <IActionResult> EditLocationAsync(Guid id, [FromBody] LocationCreateRequestDto location)
        {
            var success = await _locationManager.EditLocationAsync(id, location, User.FindFirstValue(ClaimTypes.Email));

            if (success)
            {
                return(Ok(true));
            }
            else
            {
                return(BadRequest());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Create new location.
        /// </summary>
        /// <param name="location">Location model.</param>
        /// <param name="userEmail">Current user email.</param>
        /// <returns></returns>
        public async Task <bool> CreateLocationAsync(LocationCreateRequestDto location, string userEmail)
        {
            // Get current user id
            var user = await _accountManager.GetAccountInfoAsync(userEmail);

            if (user == null)
            {
                return(false);
            }

            var loc = new Location(location)
            {
                OwnerId = user.Id
            };
            await _locationRepository.CreateAsync(loc);

            return(true);
        }
Beispiel #4
0
 public Location(LocationCreateRequestDto loc)
 {
     this.Name         = loc.Name;
     this.IsPublic     = loc.IsPublic;
     this.IsSearchable = loc.IsSearchable;
 }