Esempio n. 1
0
        public async Task <IActionResult> Delete([FromQuery] string id)
        {
            try
            {
                var userId       = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;
                var isSuccessful = await _travelPlanRepository.DeleteAsync(new Guid(id), new Guid(userId));

                if (!isSuccessful)
                {
                    return(StatusCode(500));
                }

                return(Ok());
            }
            catch (InsufficientRightsException insufRights)
            {
                return(BadRequest(new
                {
                    Message = insufRights.Message
                }));
            }
            catch (Exception exc)
            {
                return(BadRequest());
            }
        }
        public async Task <bool> DeleteAsync(Guid travelPlanId, Guid userId)
        {
            try
            {
                var travelPlanToDelete = await _travelPlanRepository.GetAsync(travelPlanId);

                if (travelPlanToDelete == null)
                {
                    return(true);
                }
                if (travelPlanToDelete.CreatedById != userId)
                {
                    throw new InsufficientRightsException("Insufficient rights to delete Travel Plan");
                }

                var isSuccessful = await _travelPlanRepository.DeleteAsync(travelPlanToDelete);

                return(isSuccessful);
            }
            catch (Exception)
            {
                throw;
            }
        }