public void SetReservationsOfEmployee(int employeeId, ReservationInfo[] reservations)
        {
            if (reservations == null) throw new ArgumentNullException("reservations");

            Employee employeeEntity = this.repository.GetEmployee(employeeId);
            if (employeeEntity == null)
            {
                var error = String.Format("Employee with Id '{0}' not found.", employeeId);
                throw new ArgumentException(error, "employeeId");
            }

            IEnumerable<Reservation> reservationEntities = reservations.Select(this.CreateReservationEntity);
            employeeEntity.Reservations.Clear();
            employeeEntity.Reservations.AddRange(reservationEntities);

            this.repository.SetEmployee(employeeEntity);
        }
Пример #2
0
        private ReservationViewModel ConvertToViewModel(ReservationInfo reservation)
        {
            var reservationViewModel = new ReservationViewModel
            {
                Start = reservation.Start,
                End = reservation.End,
                CustomerName = string.Empty,
            };

            if (reservation.CustomerId != null)
            {
                IEnumerable<CustomerInfo> customers = this.customerService.GetCustomers();
                CustomerInfo customer = customers.FirstOrDefault(c => c.Id == reservation.CustomerId);
                if (customer == null)
                {
                    throw new ArgumentException("Unknown customer Id");
                }
                reservationViewModel.CustomerName = customer.Name;
            }

            return reservationViewModel;
        }
Пример #3
0
        private ReservationInfo ConvertToDataObject(ReservationViewModel reservationViewModel)
        {
            var reservation = new ReservationInfo
                                  {
                                      Start = reservationViewModel.Start,
                                      End = reservationViewModel.End
                                  };

            if (!String.IsNullOrEmpty(reservationViewModel.CustomerName))
            {
                IEnumerable<CustomerInfo> customers = this.customerService.GetCustomers();
                CustomerInfo customer = customers.FirstOrDefault(
                    c => String.Compare(c.Name, reservationViewModel.CustomerName, StringComparison.InvariantCultureIgnoreCase) == 0);
                if (customer == null)
                {
                    throw new ArgumentException("Invalid customer name" + reservationViewModel.CustomerName);
                }
                reservation.CustomerId = customer.Id;
            }

            return reservation;
        }
Пример #4
0
 private Reservation CreateReservationEntity(ReservationInfo reservation)
 {
     return new Reservation
                {
                    CustomerId = reservation.CustomerId,
                    Start = reservation.Start,
                    End = reservation.End
                };
 }
 public void SetReservationsOfEmployee(int employeeId, ReservationInfo[] reservations)
 {
     throw new NotImplementedException();
 }