Created
February 23, 2020 19:50
-
-
Save TheFo2sh/4f1638eca01f4bd45f5788923fd6df64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Option<ReservationViewModel> AddItemToReservation(string id, string itemId) | |
{ | |
var reservationOptinal = _restaurant.GetReservation(id); | |
var itemOptional = _inventory.GetItem(itemId); | |
return reservationOptinal.Intersect(itemOptional) | |
.Select(AddItemFunc) | |
.Select(reservation => (reservation, _ClientsManger.GetUser(reservation.UserId))) | |
.Select(MapToViewModel); | |
Reservation AddItemFunc(( Reservation , Item ) tuple) | |
{ | |
var (reservation, item) = tuple; | |
reservation.Items.Add(item); | |
return reservation; | |
} | |
ReservationViewModel MapToViewModel((Reservation , Option<User>) tuple) | |
{ | |
var (reservation, userOption) = tuple; | |
return new ReservationViewModel() | |
{ | |
From = reservation.From, | |
User = userOption.Select(user => $"{user.FirstName} {user.SecondName}").ValueOr("Not a client"), | |
Id = reservation.Id, | |
Name = reservation.Name, | |
To = reservation.To | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment