示例#1
0
        public async Task <IActionResult> CreateReservation(CreateReservationViewModel viewModel)
        {
            var user = _userManager.GetUserAsync(User).Result;
            var vm   = _vmManager.GetVmById(viewModel.VmId).Result;

            try
            {
                await _reservationManager.CreateReservationAsync(user, vm, viewModel.StartTime, viewModel.EndTime);
            }
            catch (ArgumentException e)
            {
                ModelState.AddModelError("", e.Message);
                ViewBag.VmId = viewModel.VmId;
                return(View(viewModel));
            }

            return(RedirectToAction("Details", "Vm", new { id = vm.Id }));
        }