public async Task DeleteAsync(Guid id, UserAndOrganizationDto userOrg) { var @event = await _eventsDbSet .Include(e => e.EventOptions) .Include(e => e.EventParticipants) .SingleOrDefaultAsync(e => e.Id == id && e.OrganizationId == userOrg.OrganizationId); _eventValidationService.CheckIfEventExists(@event); var isAdmin = await _permissionService.UserHasPermissionAsync(userOrg, AdministrationPermissions.Event); // ReSharper disable once PossibleNullReferenceException _eventValidationService.CheckIfUserHasPermission(userOrg.UserId, @event.ResponsibleUserId, isAdmin); _eventValidationService.CheckIfEventEndDateIsExpired(@event.EndDate); var timestamp = DateTime.UtcNow; @event.Modified = timestamp; @event.ModifiedBy = userOrg.UserId; await _eventParticipationService.DeleteByEventAsync(id, userOrg.UserId); await _eventUtilitiesService.DeleteByEventAsync(id, userOrg.UserId); _eventsDbSet.Remove(@event); await _uow.SaveChangesAsync(false); await _wallService.DeleteWallAsync(@event.WallId, userOrg, WallType.Events); }
public async Task <IHttpActionResult> DeleteWall(int wallId) { if (wallId <= 0) { return(BadRequest()); } try { var userAndOrg = GetUserAndOrganization(); await _wallService.DeleteWallAsync(wallId, userAndOrg, WallType.UserCreated); return(Ok()); } catch (ValidationException e) { return(BadRequestWithError(e)); } catch (UnauthorizedException) { return(Unauthorized()); } }
public async Task DeleteAsync(int id, UserAndOrganizationDto userOrg) { var project = await _projectsDbSet .Include(p => p.Members) .Include(p => p.Wall.Members) .Include(p => p.Wall.Moderators) .Include(p => p.Attributes) .FirstOrDefaultAsync(p => p.Id == id && p.OrganizationId == userOrg.OrganizationId); if (project == null) { throw new ValidationException(ErrorCodes.ContentDoesNotExist, "Project not found"); } await ValidateOwnershipPermissionsAsync(project.OwnerId, userOrg); _projectsDbSet.Remove(project); await _wallService.DeleteWallAsync(project.WallId, userOrg, WallType.Project); await _uow.SaveChangesAsync(userOrg.UserId); }