public ActionResult BookCompleted(
            BookVisitViewModel viewModel,
            SalesReplies.ReturnCode salesReturnCode,
            CalendarReplies.ReturnCode calendarReturnCode)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            return(RedirectToAction("Index", new { viewModel.LeadId }));
        }
        public ActionResult Book(Guid leadId)
        {
            var consultants = _employeeService.GetCurrentByDepartmentId(Constants.SalesDepartmentId);

            var viewModel = new BookVisitViewModel
            {
                Id            = Guid.NewGuid(),
                AppointmentId = Guid.NewGuid(),
                LeadId        = leadId,
                Consultants   = new SelectList(consultants, "Id", "FullName")
            };

            return(View(viewModel));
        }
        public void BookAsync(BookVisitViewModel viewModel)
        {
            AsyncManager.Parameters["viewModel"] = viewModel;

            var calendarValidationMessages = _appointmentService.ValidateBook(new ValidateBookRequest
            {
                EmployeeId   = viewModel.ConsultantId.Value,
                DepartmentId =
                    Constants.SalesDepartmentId,
                Start = viewModel.Start,
                End   = viewModel.End
            }).ToList();

            if (calendarValidationMessages.Any())
            {
                calendarValidationMessages.ForEach(message => ModelState.AddModelError("", message.Text));
                return;
            }

            var bookVisitCommand = new BookVisit
            {
                Id            = viewModel.Id,
                AppointmentId = viewModel.AppointmentId,
                LeadId        = viewModel.LeadId,
                Start         = viewModel.Start,
                End           = viewModel.End,
                ConsultantId  = viewModel.ConsultantId
            };

            var bookAppointmentCommand = new BookAppointment
            {
                Id           = viewModel.AppointmentId,
                EmployeeId   = viewModel.ConsultantId.Value,
                DepartmentId = Constants.SalesDepartmentId,
                Start        = viewModel.Start,
                End          = viewModel.End,
            };

            _bus.Send(bookVisitCommand).Register <SalesReplies.ReturnCode>(returnCode => AsyncManager.Parameters["salesReturnCode"]             = returnCode);
            _bus.Send(bookAppointmentCommand).Register <CalendarReplies.ReturnCode>(returnCode => AsyncManager.Parameters["calendarReturnCode"] = returnCode);
        }