Ejemplo n.º 1
0
        public async Task <IActionResult> DeletePhoneAsync(int id)
        {
            _logger.LogInformation($"User trying to delete phone number with identificator {id}");
            var entity = await _phones.FindPhoneAsync(id);

            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (entity == default(Phone))
            {
                _logger.LogWarning($"User requested not existing phone number");
                return(NotFound());
            }

            if (entity.CustomerId.ToString() != userId)
            {
                _logger.LogWarning($"User is tried to delete not his own phone number");
                return(Forbid());
            }

            await _phones.DeletePhoneAsync(entity);

            _logger.LogInformation($"Phone number with identificator {entity.Id} was deleted");

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> DeletePhone([FromUri] int id)
        {
            if (id < 1)
            {
                return(BadRequest());
            }
            await _phoneService.DeletePhoneAsync(id);

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeletePhone(int id)
        {
            var successful = await _phoneService.DeletePhoneAsync(id);

            if (!successful)
            {
                return(BadRequest("Could not delete phone."));
            }

            return(RedirectToAction("Phones"));
        }