private static User CreateUser(RawItem rawItem) { if (rawItem.EmailAddress == null) { throw new InvalidOperationException("Email address cannot be null."); } if (rawItem.FirstName == null) { throw new InvalidOperationException("First name cannot be null."); } if (rawItem.LastName == null) { throw new InvalidOperationException("Last name cannot be null."); } return(new User( userId: rawItem.PrimaryKey.Split('#')[1], alternativeRegistrationNumber: rawItem.AlternativeRegistrationNumber, commuteDistance: rawItem.CommuteDistance, emailAddress: rawItem.EmailAddress, firstName: rawItem.FirstName, lastName: rawItem.LastName, registrationNumber: rawItem.RegistrationNumber, requestReminderEnabled: rawItem.RequestReminderEnabled ?? true, reservationReminderEnabled: rawItem.ReservationReminderEnabled ?? true)); }
private static RawItem CreateRawItem(User user) => RawItem.CreateUser( primaryKey: $"USER#{user.UserId}", sortKey: "PROFILE", alternativeRegistrationNumber: user.AlternativeRegistrationNumber, commuteDistance: user.CommuteDistance, emailAddress: user.EmailAddress, firstName: user.FirstName, lastName: user.LastName, registrationNumber: user.RegistrationNumber, requestReminderEnabled: user.RequestReminderEnabled, reservationReminderEnabled: user.ReservationReminderEnabled);
private static IEnumerable <Reservation> CreateWholeMonthReservations(RawItem rawItem, YearMonth yearMonth) { var wholeMonthRawReservations = rawItem.Reservations; if (wholeMonthRawReservations == null) { throw new InvalidOperationException("Raw reservations cannot be null."); } return(wholeMonthRawReservations.SelectMany( singleDayRawReservations => CreateSingleDayReservations(yearMonth, singleDayRawReservations))); }
private static IEnumerable <Request> CreateWholeMonthRequests(RawItem rawItem, YearMonth yearMonth) { var userId = rawItem.PrimaryKey.Split('#')[1]; var wholeMonthRawRequests = rawItem.Requests; if (wholeMonthRawRequests == null) { throw new InvalidOperationException("Raw requests cannot be null."); } return(wholeMonthRawRequests.Select(singleDayRawRequest => CreateRequest(yearMonth, userId, singleDayRawRequest))); }
private static RawItem CreateRawItem(IGrouping <YearMonth, Reservation> monthReservations) => RawItem.CreateReservations( primaryKey: "GLOBAL", sortKey: $"RESERVATIONS#{monthReservations.Key.ToString("yyyy-MM", CultureInfo.InvariantCulture)}", reservations: CreateRawReservations(monthReservations));
private static RawItem CreateRawItem(string userId, IGrouping <YearMonth, Request> yearMonthRequests) => RawItem.CreateRequests( primaryKey: $"USER#{userId}", sortKey: $"REQUESTS#{yearMonthRequests.Key.ToString("yyyy-MM", CultureInfo.InvariantCulture)}", requests: yearMonthRequests.ToDictionary(CreateRawRequestDayKey, CreateRawRequestStatus));