Exemple #1
0
        public async Task DeleteByIdAsync(Guid id)
        {
            await EntityValidationHelper
            .ValidateCurrentUserIsSuperAdminAsync(_currentUserService, _tripFlipDbContext);

            var userEntity = await _tripFlipDbContext.Users.FindAsync(id);

            EntityValidationHelper.ValidateEntityNotNull(
                userEntity, ErrorConstants.UserNotFound);

            _tripFlipDbContext.Remove(userEntity);
            await _tripFlipDbContext.SaveChangesAsync();
        }
Exemple #2
0
        public async Task DeleteByIdAsync(int id)
        {
            var itemEntity = await _tripFlipDbContext
                             .Items
                             .Include(item => item.ItemList)
                             .SingleOrDefaultAsync(item => item.Id == id);

            EntityValidationHelper
            .ValidateEntityNotNull(itemEntity, ErrorConstants.ItemNotFound);

            // Validate current user has route 'Admin' role.
            await EntityValidationHelper.ValidateCurrentUserRouteRoleAsync(
                currentUserService : _currentUserService,
                tripFlipDbContext : _tripFlipDbContext,
                routeId : itemEntity.ItemList.RouteId,
                routeRoleToValidate : RouteRoles.Admin,
                errorMessage : ErrorConstants.NotRouteAdmin);

            _tripFlipDbContext.Remove(itemEntity);
            await _tripFlipDbContext.SaveChangesAsync();
        }
Exemple #3
0
        public async Task DeleteByIdAsync(int id)
        {
            await EntityValidationHelper.ValidateCurrentUserTripRoleAsync(
                _currentUserService,
                _tripFlipDbContext,
                id,
                TripRoles.Admin,
                ErrorConstants.NotTripAdmin);

            var tripEntity = await _tripFlipDbContext.Trips
                             .Include(trip => trip.Routes)
                             .FirstOrDefaultAsync(trip => trip.Id == id);

            EntityValidationHelper
            .ValidateEntityNotNull(tripEntity, ErrorConstants.TripNotFound);

            _tripFlipDbContext.RemoveRange(tripEntity.Routes);
            _tripFlipDbContext.Remove(tripEntity);

            await _tripFlipDbContext.SaveChangesAsync();
        }