public async Task <IActionResult> MakeAppointment(MakeAppointmentModel model)
        {
            if (ModelState.IsValid)
            {
                var cmd    = new MakeAppointmentCommand(model.AppointmentType, model.StartsAt, model.CandidateId, model.VacancyId);
                var result = await _mediator.Send(cmd);

                if (result.IsFailure)
                {
                    ModelState.AddModelError("", result.Error);
                }
                else
                {
                    return(RedirectToAction(nameof(AppointmentController.Index)));
                }
            }

            var candidates = await _mediator.Send(new GetCandidateDropQuery());

            var vacancies = await _mediator.Send(new GetVacanciesDropQuery());

            ViewBag.AppointmentTypes = new SelectList(Enum.GetValues(typeof(AppointmentType)).Cast <AppointmentType>());

            model.Candidates = new SelectList(candidates, "Id", "Text", model.CandidateId);
            model.Vacancies  = new SelectList(vacancies, "Id", "Text", model.VacancyId);

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult MakeAppointment(MakeAppointmentCommand command)
        {
            if (!ModelState.IsValidField("AppointmentDate"))
            {
                var builder   = new MakeAppointmentViewModelBuilder(_context);
                var viewModel = builder.Build(command.PropertyId);

                return(View(viewModel));
            }
            var handler = new MakeAppointmentCommandHandler(_context);

            command.BuyerUserId = User.Identity.GetUserId();
            handler.Handle(command);

            return(RedirectToAction("Index"));
        }