public Task <Result <AppointmentCoreModel> > Get(Core.Models.BaseCoreModel coreModel)
        => Result <AppointmentCoreModel> .TryAsync(async() =>
        {
            var result =
                await _repository.FirstOrDefaultAsNoTrackingAsync <Appointment>(s => s.Id == coreModel.Id,
                                                                                a => a.Invoice);

            if (!result.Success || result.Data == null)
            {
                return(Result <AppointmentCoreModel> .Failed(Error.WithCode(BaseErrorCodes.NotFound)));
            }

            var appointment = result.Data;

            LightUserModel user           = null;
            LightUserModel representative = null;
            user = (await _membershipServiceApi.AuthAuthApiService.Setting(new BaseModel
            {
                Id = appointment.UserId
            }))
                   .Data;
            representative = appointment.RepresentativeId != null
                    ? (await _membershipServiceApi.AuthAuthApiService.Setting(new BaseModel
            {
                Id = appointment.RepresentativeId
            })).Data
                    : null;

            var appointmentModel = new AppointmentCoreModel
            {
                Id             = appointment.Id,
                Title          = appointment.Title,
                Description    = appointment.Description,
                User           = user,
                Representative = representative,
                Date           = appointment.Date,
                Type           = appointment.Type,
                CreationDate   = appointment.CreationDate,
                Duration       = appointment.Duration,
                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,

                Approved = appointment.Approved
            };
            return(Result <AppointmentCoreModel> .Successful(appointmentModel));
        });
        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));
        });