コード例 #1
0
        public async Task <bool> DeleteAsync(Guid activityId, Guid userId)
        {
            try
            {
                var activityToDelete = await _travelPlanActivityRepository.GetAsync(activityId);

                if (activityToDelete == null)
                {
                    //log maybe?
                    return(true);
                }
                if (activityToDelete.HostId != userId)
                {
                    throw new InsufficientRightsException("Insufficient rights to delete activity");
                }

                var isSuccessful = await _travelPlanActivityRepository.DeleteAsync(activityToDelete);

                return(isSuccessful);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
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 _activityRepository.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());
            }
        }