Пример #1
0
        public async Task <Result> Delete(long id, long userId, Role role)
        {
            var advert = await _advertRepository.Get(id);

            if (CanAdvertAccessByRole(role) || UserIsOwner(advert.Owner, userId))
            {
                await _advertRepository.Delete(id);

                return(new());
            }

            return(new Error("У вас нет прав на удаление", "403"));
        }
Пример #2
0
 public void Delete(int id)
 {
     try
     {
         _advertRepository.Delete(id);
     }
     catch (NotFoundException e)
     {
         _logger.LogError("NotFoundException at AdvertService.Delete method", id);
         throw e;
     }
     catch (Exception e)
     {
         _logger.LogError("Exception at AdvertService.Delete method", id);
         throw new ApplicationException("An error occured when deleting the advert.", e);
     }
 }
Пример #3
0
        public IActionResult Delete(int id)
        {
            if (!advertRepository.TryGetById(id, out Advert updateAdvert))
            {
                return(NotFound());
            }

            var userId = int.Parse(getUserIdHttpContext(HttpContext));
            var role   = getRoleHttpContext(HttpContext);

            if (updateAdvert.OwnerUserId != userId && role != RolesValues.ADMIN)
            {
                return(Forbid());
            }

            advertRepository.Delete(updateAdvert);

            return(Ok());
        }
Пример #4
0
        public async Task <AdvertResponse> DeleteAsync(int id)
        {
            var existingAdvert = await _advertRepository.FindByIdAsync(id);

            if (existingAdvert == null)
            {
                return(new AdvertResponse("Advert not found"));
            }

            try
            {
                _advertRepository.Delete(existingAdvert);
                await _unitOfWork.CompleteAsync();

                return(new AdvertResponse(existingAdvert));
            }
            catch (Exception e)
            {
                return(new AdvertResponse($"An error occured when saving the advert: {e.Message}"));
            }
        }
        public IActionResult Delete(int id)
        {
            // Check if user is logged in
            if (User.Identity.IsAuthenticated)
            {
                // Getting logged in user's id
                var userId = _userManager.GetUserId(HttpContext.User);

                if (_advertRepository.CanDelete(userId, id))
                {
                    _advertRepository.Delete(id);

                    // TODO: Redirect to proper page with detailed information
                    return(Redirect("/"));
                }
                else
                {
                    // TODO: Redirect to proper page with detailed information
                    return(Redirect("/"));
                }
            }

            return(Redirect("/"));
        }
 public async Task Remove(int advertId)
 {
     await _advertRepository.Delete(advertId);
 }
 public async Task Delete(long id)
 {
     await _iAdvertRepository.Delete(id);
 }