public ActionResult BreakRegistration(BreakHospitalRegistrationCommand command)
 {
     var answer = _hospitalRegistrationsService.BreakHospitalRegistration(command);
     return RedirectToAction("Index",
     new
     {
         Token = command.Token,
         answer.DialogMessage,
         answer.HasDialogMessage
     });
 }
        public BreakHospitalRegistrationCommandAnswer BreakHospitalRegistration(BreakHospitalRegistrationCommand command)
        {
            if (command.Cause == null)
            {
                return new BreakHospitalRegistrationCommandAnswer
                {
                    Token = command.Token.Value,
                    DialogMessage = "Регистрация НЕ отменена. Пожалуйста, укажите причину отмены регистрации",
                    HasDialogMessage = true
                };
            }
            var reservation = this._reservationRepository.GetModels().FirstOrDefault(model => model.Id == command.ReservationId);
            var patient = this._reservationRepository.GetModels().Where(model => model.Id == command.ReservationId).Select(model => model.Patient).FirstOrDefault();
            var user = this._tokenManager.GetUserByToken(command.Token);

            reservation.CancelTime = DateTime.Now;
            reservation.Status = ReservationStatus.ClosedByHospital;

            this._reservationRepository.Update(command.ReservationId, reservation);

            var hospitalId = this._reservationRepository.GetModels()
                .Where(model => model.Id == command.ReservationId)
                .Select(model => model.EmptyPlaceByTypeStatistic.EmptyPlaceStatistic.HospitalSectionProfile.HospitalId)
                .FirstOrDefault();

            var reservatorId = this._reservationRepository.GetModels()
                .Where(model => model.Id == command.ReservationId)
                .Select(model => model.ReservatorId).FirstOrDefault();

            var message = new MessageStorageModel
            {
                Date = DateTime.Now.Date,
                IsRead = false,
                MessageType = MessageType.WarningMessage,
                ShowStatus = TwoSideShowStatus.Showed,
                Text = $"Бронирование пациента с номером {patient.Code} был отменено.\0\n" +
                        $"Диагноз: {reservation.Diagnosis}.\n\0" +
                        $"Причина отмены: {command.Cause}",
                Title = "Уведомление о отмене бронирования места для пациента.",
                UserFromId = user.Id,
                UserToId = reservatorId
            };

            _messageRepository.Add(message);

            _reservationRepository.SaveChanges();

            this._reservationRepository.SaveChanges();

            return new BreakHospitalRegistrationCommandAnswer
            {
                Token = command.Token.Value,
                DialogMessage = "Бронирование пациента было успешно отменено",
                HasDialogMessage = true
            };
        }
 public ActionResult BreakRegistration(BreakHospitalRegistrationCommand command)
 {
     var answer = _hospitalRegistrationsService.BreakHospitalRegistration(command);
     if (command.FullInformation != null)
     {
         return RedirectToAction("ViewDetailedInformationOnRegisteredPatients",
             new
             {
                 Token = command.Token,
                 FullInformation = command.FullInformation,
                 HospitalProfileId = command.HospitalProfileId,
                 Date = command.Date,
                 EmptyPlaceByTypeStatisticId = command.EmptyPlaceByTypeStatisticId,
                 answer.DialogMessage,
                 answer.HasDialogMessage
             });
     }
     return RedirectToAction("ViewDetailedInformationOnRegisteredPatients",
         new
         {
             Token = command.Token,
             HospitalProfileId = command.HospitalProfileId,
             Date = command.Date,
             EmptyPlaceByTypeStatisticId = command.EmptyPlaceByTypeStatisticId,
             answer.DialogMessage,
             answer.HasDialogMessage
         });
 }