public async Task <IActionResult> UpdateAppointment(Guid id, UpdateAppointmentModel model)
        {
            if (ModelState.IsValid)
            {
                var cmd    = new UpdateAppointmentCommand(id, 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));
        }
        public Task <Result <AppointmentCoreModel> > Edit(UpdateAppointmentModel model)
        => Result <AppointmentCoreModel> .TryAsync(async() =>
        {
            var appointment =
                (await _repository.FirstOrDefaultAsync <Appointment>(i => i.Id == model.Id, a => a.Invoice))
                .Data;
            if (appointment == null)
            {
                return(Result <AppointmentCoreModel> .Failed(Error.WithCode(ErrorCodes.NotFound)));
            }
            var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin);

            if (!appointment.Approved && appointment.Invoice != null && !appointment.Invoice.IsPaid)
            {
                return(Result <AppointmentCoreModel> .Failed(Error.WithData(1000,
                                                                            new[] { "You cant Approved VIP consultation without the user paying it !" })));
            }
            appointment.Approved         = model.Approved;
            appointment.RepresentativeId = isAdmin ? generalDataService.User.Id : Guid.Empty;
            appointment.Date             = model.Date;
            appointment.Type             = model.Type;
            appointment.Duration         = model.Duration;


            var userIds = new List <Guid> {
                appointment.UserId
            };
            if (appointment.RepresentativeId.Value != Guid.Empty)
            {
                userIds.Add(appointment.RepresentativeId.Value);
            }
            var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(userIds)).Data;

            await _repository.CommitAsync();
            var appointmentModel = new AppointmentCoreModel
            {
                Id             = appointment.Id,
                Title          = appointment.Title,
                Description    = appointment.Description,
                User           = users.FirstOrDefault(u => u.Id == appointment.UserId),
                Representative = appointment.RepresentativeId != Guid.Empty
                        ? users.FirstOrDefault(u => u.Id == appointment.RepresentativeId)
                        : null,
                Date     = appointment.Date,
                Duration = appointment.Duration,
                Type     = appointment.Type,
                Invoice  = appointment.Invoice != null
                        ? new InvoiceCoreModel
                {
                    Id           = appointment.Invoice.Id,
                    Amount       = appointment.Invoice.Amount,
                    Enabled      = appointment.Invoice.Enabled,
                    CreationDate = appointment.Invoice.CreationDate,
                    Description  = appointment.Invoice.Description,
                    Title        = appointment.Invoice.Title
                }
                        : null,
                CreationDate = appointment.CreationDate,
                Approved     = appointment.Approved
            };


//                _coreSmtpClient.Send(appointmentModel.User.Email,
//                    $"Dear  {appointmentModel.User.Firstname} {appointmentModel.User.Lastname} ,\n Your Appointment is schedule  has changed in the system  , please check your new appointment details  . \n Best Regards",
//                    "Your Appointment ");

//                await _messageBiz.Add(new CreateMessageModel
//                {
//                    Title = "Your Appointment",
//                    Body =
//                        $"Dear  {appointmentModel.User.Firstname} {appointmentModel.User.Lastname} ,\n Your Appointment is schedule  has changed in the system  , please check your new appointment details  . \n Best Regards",
//                    ToUser = generalDataService.User.Id,
//                    Priority = MessagePriority.High
//                });

            return(Result <AppointmentCoreModel> .Successful(appointmentModel));
        });
Esempio n. 3
0
 public async Task <Result <AppointmentCoreModel> > Edit(UpdateAppointmentModel model)
 => await _AppointmentBiz.Edit(model);