示例#1
0
        public IActionResult EditReservation(ReservationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.AccountList   = _accountQueryService.GetAllAccountData().AccountDataList;
                model.EquipmentList = _equipmentQueryService.GetAllEquipmentData().EquipmentDataList;
                ModelState.AddModelError(string.Empty, "入力内容が不正です。");
                return(View(model));
            }

            var request = new ChangeReservationInfoRequest()
            {
                ReservationId = model.Id,
                AccountId     = model.SelectedAccountId,
                EquipmentId   = model.SelectedEquipmentId,
                StartDateTime = model.GetStartDateTime().Value,
                EndDateTime   = model.GetEndDateTime().Value,
                PurposeOfUse  = model.PurposeOfUse
            };

            try
            {
                _reservationAppService.ChangeReservationInfo(request);
            }
            catch (ReservationDupulicationException)
            {
                model.AccountList   = _accountQueryService.GetAllAccountData().AccountDataList;
                model.EquipmentList = _equipmentQueryService.GetAllEquipmentData().EquipmentDataList;
                ModelState.AddModelError(string.Empty, "予約が重複しています。");
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }
        public void ChangeReservationInfo(ChangeReservationInfoRequest request)
        {
            _unitOfWork.Begin();

            try
            {
                _unitOfWork.ReservationRepository.Lock();

                var reservation = FindReservationWithValidation(request.ReservationId);

                reservation.ChangeAccountOfUse(new AccountId(request.AccountId));
                reservation.ChangeEquipment(new EquipmentId(request.EquipmentId));
                reservation.ChangeReservationDateTime(new ReservationDateTime(request.StartDateTime, request.EndDateTime));
                reservation.ChangePurposeOfUse(new PurposeOfUse(request.PurposeOfUse));

                SaveReservation(reservation);

                _unitOfWork.Commit();
            }
            catch
            {
                _unitOfWork.Rollback();
                throw;
            }
        }