Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 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);
Exemplo n.º 3
0
        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)));
        }
Exemplo n.º 4
0
        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)));
        }
Exemplo n.º 5
0
 private static RawItem CreateRawItem(IGrouping <YearMonth, Reservation> monthReservations) =>
 RawItem.CreateReservations(
     primaryKey: "GLOBAL",
     sortKey: $"RESERVATIONS#{monthReservations.Key.ToString("yyyy-MM", CultureInfo.InvariantCulture)}",
     reservations: CreateRawReservations(monthReservations));
Exemplo n.º 6
0
 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));