Пример #1
0
        public async Task <ActionResult <Guid> > DeleteAdAsync(Guid adId)
        {
            var currentUserId = GetCurrentUserId();

            try
            {
                await adManager.DeleteAsync(adId, currentUserId);

                return(Ok(adId));
            }
            catch (ArgumentNullException ane)
            {
                logger.LogDebug(ane.Message + "\n" + ane.StackTrace);
                return(NotFound($"Can't find ad {adId}"));
            }
            catch (MethodAccessException mae)
            {
                logger.LogDebug(mae.Message + "\n" + mae.StackTrace);
                logger.LogDebug($"User {currentUserId} has no rights to delete ad {adId}");
                return(Forbid(JwtBearerDefaults.AuthenticationScheme, CookieAuthenticationDefaults.AuthenticationScheme));
            }
            catch (Exception ex)
            {
                logger.LogDebug(ex.Message + "\n" + ex.StackTrace);
                return(StatusCode(500));
            }
        }