//registers modelcopies of selected items to the client public async Task <IActionResult> Borrow() { List <SessionModel> modelsToBorrow = HttpContext.Session.GetObject <List <SessionModel> >("Items") ?? new List <SessionModel>(); Client client = await _cm.FindByEmailAsync(User.Identity.Name); List <ModelCopy> alreadyBorrowed = await _identityMap.FindModelCopiesByClient(client.clientId); //Borrow all available copies of selected items Boolean successfulReservation = await _identityMap.ReserveModelCopiesToClient(modelsToBorrow, client.clientId); //if not all items were borrowed, determine which ones were not borrowed and display them to the client if (!successfulReservation) { List <ModelCopy> nowBorrowed = await _identityMap.FindModelCopiesByClient(client.clientId); HashSet <ModelCopy> borrowed = nowBorrowed.Except(alreadyBorrowed).ToHashSet(); List <SessionModel> notBorrowed = modelsToBorrow .Select(m => new { Id = m.Id, MT = m.ModelType }) .Except(borrowed .Select(m => new { Id = m.modelID, MT = m.modelType })) .Select(c => new SessionModel { Id = c.Id, ModelType = c.MT }) .ToList(); HttpContext.Session.SetObject("Items", notBorrowed); HttpContext.Session.SetInt32("ItemsCount", notBorrowed.Count); return(RedirectToAction(nameof(Index))); } //TODO Return to Home? HttpContext.Session.SetObject("Items", null); HttpContext.Session.SetInt32("ItemsCount", 0); return(RedirectToAction(nameof(Index))); }