public async Task <User> CreateNewUser(string sub, string role, string email) { var userRole = await _roles.FindByRole(role) ?? throw new NotFoundException(nameof(UserRole), $"role = {role}"); var exists = await Exists(sub); if (exists) { throw new Exception("User already exists"); } var u = new User { Sub = sub, Email = email, AllowNotifications = true, Role = userRole, IsActive = true }; _ctx.Users.Add(u); await _ctx.SaveChangesAsync(); return(u); }
public async Task <RefreshToken> CreateNewToken(string tokenKey, string sub, Instant expires) { var token = new RefreshToken { Expires = expires, Key = tokenKey, Sub = sub }; _ctx.RefreshTokens.Add(token); await _ctx.SaveChangesAsync(); return(token); }
public async Task <Resource> CreateNewResource(string displayName, JsonDocument metaData, string description, string resourceTypeName) { var resourceType = await FindResourceTypByType(resourceTypeName); var resource = new Resource(displayName, metaData, description, resourceType) { IsActive = true }; _ctx.Resources.Add(resource); await _ctx.SaveChangesAsync(); return(resource); }
public async Task <Reservation> CreateNewReservation(Instant start, Instant end, Resource resource, User owner, bool allowNotifications) { var reservation = new Reservation { StartTime = start, EndTime = end, Owner = owner, ReservedResource = resource, AllowNotifications = allowNotifications }; _ctx.Reservations.Add(reservation); await _ctx.SaveChangesAsync(); return(reservation); }