Esempio n. 1
0
        public async Task <ActionResult> DeleteAsync(string offerName)
        {
            AADAuthHelper.VerifyUserAccess(this.HttpContext, _logger, true);
            _logger.LogInformation($"Delete offer {offerName}.");
            await _offerService.DeleteAsync(offerName);

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <ActionResult <bool> > Delete(Guid id)
        {
            var result = await _offerService.DeleteAsync(id);

            if (result)
            {
                return(Ok("Offer is deleted"));
            }
            return(BadRequest("Offer not found"));
        }
        public async Task <IActionResult> DeleteAsync(int id)
        {
            var result = await _offerService.DeleteAsync(id);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var offerResource = _mapper.Map <Offer, OfferResource>(result.Resource);

            return(Ok(offerResource));
        }
Esempio n. 4
0
    public static async Task <IResult> Delete(int offerid, IOfferService offerService, IUserService userService, IHttpContextAccessor contextAccessor)
    {
        if (offerid <= 0)
        {
            return(Results.BadRequest(new ApiError(string.Format(Strings.Invalid, "offer id"))));
        }
        var offer = await offerService.ReadAsync(offerid);

        if (offer is null)
        {
            return(Results.BadRequest(new ApiError(string.Format(Strings.ItemNotFound, "offer", "id", offerid))));
        }
        var request = contextAccessor.HttpContext?.Request;

        if (request is null)
        {
            return(Results.BadRequest(new ApiError(Strings.ContextNotFound)));
        }
        var token = request.GetToken();

        if (token is null)
        {
            return(Results.BadRequest(new ApiError(Strings.NotAuthenticated)));
        }
        var user = await userService.ReadAsync(token.Requester());

        if (user is null)
        {
            return(Results.BadRequest(new ApiError(string.Format(Strings.ItemNotFound, "user", "email", token.Requester()))));
        }
        if (user.Id != offer.UserId)
        {
            return(Results.BadRequest(new ApiError(Strings.NotAuthorized)));
        }
        var result = await offerService.DeleteAsync(offer);

        if (result.Successful)
        {
            return(Results.Ok());
        }
        return(Results.BadRequest(new ApiError(result.ErrorMessage())));
    }
Esempio n. 5
0
 public async Task <IActionResult> DeleteAsync([FromRoute] long id)
 {
     return(Ok(await _offerService.DeleteAsync(id)));
 }