public async Task <IActionResult> SetListingEnabled([FromBody] SetListingEnabledRequest setListingEnabledRequest)
        {
            try
            {
                var id   = HttpContext.User.FindFirst(ClaimTypes.Email).Value;
                var user = await _userManager.FindByEmailAsync(id);

                if (user != null)
                {
                    if (user.Id != setListingEnabledRequest.OwnerId)
                    {
                        return(StatusCode((int)HttpStatusCode.InternalServerError,
                                          "you are not the owner of that listing"));
                    }
                    await _listingCommand.SetListingStatus(setListingEnabledRequest, user.Id);

                    return(Ok("Successfully set listing status"));
                }
                else
                {
                    _logger.LogError($"error user does not exis");
                    return(StatusCode((int)HttpStatusCode.InternalServerError, "error user does not exist"));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"error while updated the listing: {ex}");
                return(StatusCode((int)HttpStatusCode.InternalServerError, "error while updating the listing"));
            }
        }
Esempio n. 2
0
 public async Task SetListingStatus(SetListingEnabledRequest setListingEnabledRequest, string userId)
 {
     try
     {
         await _listingRepository.SetListingStatus(setListingEnabledRequest.UserListingId,
                                                   setListingEnabledRequest.OwnerId, setListingEnabledRequest.Enabled);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }