コード例 #1
0
ファイル: LocationManager.cs プロジェクト: drony/spotyplace
        /// <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);
        }
コード例 #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());
            }
        }
コード例 #3
0
ファイル: LocationManager.cs プロジェクト: drony/spotyplace
        /// <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);
        }
コード例 #4
0
ファイル: Location.cs プロジェクト: drony/spotyplace
 public Location(LocationCreateRequestDto loc)
 {
     this.Name         = loc.Name;
     this.IsPublic     = loc.IsPublic;
     this.IsSearchable = loc.IsSearchable;
 }