コード例 #1
0
        public List <AppointmentsDateAndTimeInformation> GetOldAppointmentsForACustomer(int userId)
        {
            var                user = Context.Users.First(c => c.Id == userId);
            var                appointmentsForCustomers = new List <AppointmentsDateAndTimeInformation>();
            Customer           customer     = Context.Customers.First(c => c.Id == user.IdCustomer);
            List <Appointment> appointments = Context.Appointments.Where(c => c.IdCustomer == customer.Id).ToList();

            foreach (var appointment in appointments)
            {
                var timeSlot = Context.TimeSlots.First(c => c.Id == appointment.IdTimeSlot);
                if (timeSlot.StartDateTime.Date <= DateConverter.CurrentEasternDateTime().Date)
                {
                    AppointmentsDateAndTimeInformation newAppointment = new AppointmentsDateAndTimeInformation
                    {
                        Appointment = appointment,
                        Date        = timeSlot.StartDateTime.Date.ToString(),
                        StartTime   = timeSlot.StartDateTime.TimeOfDay.ToString(),
                        EndTime     = timeSlot.EndDateTime.TimeOfDay.ToString()
                    };
                    appointmentsForCustomers.Add(newAppointment);
                }
            }
            appointmentsForCustomers = appointmentsForCustomers.OrderBy(c => c.Date).OrderBy(c => c.StartTime).ToList();
            return(appointmentsForCustomers);
        }
コード例 #2
0
        internal object AddNewSurveyForAUser(ResponseInformation responses)
        {
            foreach (var response in responses.Responses)
            {
                DisableOldQuestionsIfExists(response, responses.CustomerId);
                Response newResponse = new Response
                {
                    IdCustomer = responses.CustomerId,
                    IdQuestion = response.IdQuestion
                };
                if (response.AnswerType == "bool")
                {
                    newResponse.ResponseBool = response.ResponseBool;
                }
                else
                {
                    newResponse.ResponseString = response.ResponseString;
                }
                newResponse.CreatedOn = DateConverter.CurrentEasternDateTime();
                newResponse.IsActive  = true;
                Context.Add(newResponse);
            }

            Context.SaveChanges();
            return(1);
        }
コード例 #3
0
        public List <AppointmentsDateAndTimeInformation> GetAppointmentsForCustomer(int userId)
        {
            var user = Context.Users.Where(c => c.Id == userId).First();
            List <AppointmentsDateAndTimeInformation> appointmentsForCustomer = new List <AppointmentsDateAndTimeInformation>();
            Customer           customer     = Context.Customers.Where(c => c.Id == user.IdCustomer).First();
            List <Appointment> appointments = Context.Appointments.Where(c => c.IdCustomer == customer.Id && c.IsActive == true).ToList();

            foreach (var appointment in appointments)
            {
                DateTime startTime = Context.TimeSlots.Where(c => c.Id == appointment.IdTimeSlot).First().StartDateTime;
                DateTime endTime   = Context.TimeSlots.Where(c => c.Id == appointment.IdTimeSlot).First().EndDateTime;
                if (startTime.Date >= DateConverter.CurrentEasternDateTime().Date)
                {
                    AppointmentsDateAndTimeInformation oneAppointment = new AppointmentsDateAndTimeInformation
                    {
                        Appointment = appointment,
                        Date        = startTime.Date.ToString(),
                        StartTime   = startTime.TimeOfDay.ToString(),
                        EndTime     = endTime.TimeOfDay.ToString()
                    };
                    appointmentsForCustomer.Add(oneAppointment);
                }
            }
            appointmentsForCustomer = appointmentsForCustomer.OrderBy(c => c.Date).OrderBy(c => c.StartTime).ToList();
            return(appointmentsForCustomer);
        }
コード例 #4
0
        public int RegisterNewUser(RegistrationInformation registerInformation)
        {
            Address            address      = registerInformation.PhysicalAddress;
            Customer           customer     = registerInformation.Customer;
            User               user         = registerInformation.User;
            List <PhoneNumber> phoneNumbers = registerInformation.PhoneNumbers;

            if (address != null && customer != null && user != null && phoneNumbers.First() != null)
            {
                address.IsActive  = true;
                customer.IsActive = true;
                user.IsActive     = true;
                Context.Add(address);
                Context.SaveChanges();
                customer.IdAddress = address.Id;
                Context.Add(customer);
                Context.SaveChanges();
                if (user.Email != "" && user.Password != "")
                {
                    user.IdCustomer = customer.Id;
                    user.LastLogin  = DateConverter.CurrentEasternDateTime();
                    user.CreatedOn  = DateConverter.CurrentEasternDateTime();
                    Context.Add(user);
                }
                Context.SaveChanges();
                foreach (var phone in phoneNumbers)
                {
                    phone.IsActive   = true;
                    phone.IdCustomer = customer.Id;
                    Context.Add(phone);
                }
            }
            Context.SaveChanges();
            return(customer.Id);
        }
コード例 #5
0
        public void SendAskConfirmationEmailToUsers(IConfiguration config, AppointmentService appointmentService)
        {
            DateTime dateDelay             = DateConverter.CurrentEasternDateTime().AddDays(2);
            var      appointmentsToConfirm = appointmentService.GetAppointmentsByDate(dateDelay);

            foreach (var info in appointmentsToConfirm)
            {
                ActionToken actionToken = new ActionToken
                {
                    IsActive       = true,
                    Action         = "ConfirmAppointment",
                    CreatedOn      = DateConverter.CurrentEasternDateTime(),
                    ExpirationDate = DateConverter.CurrentEasternDateTime().AddDays(2),
                    IdAppointment  = info.AppointmentInfo.Id,
                    IdUser         = info.AppointmentInfo.IdCustomer,
                    Token          = Guid.NewGuid().ToString()
                };
                Context.ActionTokens.Add(actionToken);
                Context.SaveChanges();

                Customer customer  = Context.Customers.First(c => c.Id == info.AppointmentInfo.IdCustomer);
                string   userEmail = Context.Users.First(c => c.IdCustomer == info.AppointmentInfo.IdCustomer).Email;
                EmailSender.SendAskConfirmationToUserEmail(
                    $"{customer.FirstName} {customer.LastName}",
                    userEmail,
                    actionToken.Token,
                    info.TimeSlotInfo.StartDateTime,
                    config
                    );
            }
        }
コード例 #6
0
        public void SendUnconfirmedAppointmentsToEmployees
            (IConfiguration config, AppointmentService appointmentService, PhoneNumberService phoneNumberService)
        {
            DateTime dateDelay = DateConverter.CurrentEasternDateTime().AddDays(1);
            var      unconfirmedAppointment = appointmentService.GetUnconfirmedAppointments(phoneNumberService);

            if (unconfirmedAppointment.Count() > 0)
            {
                EmailSender.SendUnconfirmedAppointmentsToEmployees(unconfirmedAppointment, config);
            }
        }
コード例 #7
0
        internal int CreateUserForCustomer(EmailAndCustomerInfo emailInfo, Microsoft.Extensions.Configuration.IConfiguration configuration, UserService userService)
        {
            var user = new User()
            {
                Password   = Guid.NewGuid().ToString(),
                Email      = emailInfo.Email,
                IdCustomer = emailInfo.CustomerId,
                IsActive   = true,
                CreatedOn  = DateConverter.CurrentEasternDateTime(),
                LastLogin  = DateConverter.CurrentEasternDateTime()
            };

            Context.Add(user);
            Context.SaveChanges();
            userService.SendChangePasswordEmail(configuration, user.Email, true);
            return(user.IdCustomer);
        }
コード例 #8
0
        public bool ReserveAnAppointment(AppointmentUserInformation appointmentService, IConfiguration configuration)
        {
            Appointment appointment = new Appointment();

            if (appointmentService != null)
            {
                appointment.CreatedOn = DateConverter.CurrentEasternDateTime();
                if (appointmentService.IdCustomer != null)
                {
                    appointment.IdCustomer = appointmentService.IdCustomer.Value;
                }
                else
                {
                    var customer = Context.Users.FirstOrDefault(c => c.Id == appointmentService.IdUser);
                    if (customer != null)
                    {
                        appointment.IdCustomer = customer.Id;
                    }
                    else
                    {
                        return(false);
                    }
                }
                appointment.IdTimeSlot         = appointmentService.IdTimeSlot;
                appointment.ConsultationReason = appointmentService.ConsultationReason;
                appointment.Therapist          = appointmentService.Therapist;
                appointment.HasSeenDoctor      = appointmentService.HasSeenDoctor;
                appointment.DoctorDiagnostic   = appointmentService.DoctorDiagnostic;
                appointment.IsNew    = true;
                appointment.IsActive = true;
                Context.Add(appointment);
                Context.SaveChanges();
                var user            = GetUser(appointment.IdCustomer);
                var appointmentDate = GetAppointmentTimeSlot(appointment).StartDateTime;
                if (user != null)
                {
                    EmailSender.SendConfirmationEmail(user.Email, appointmentDate, configuration);
                }
                return(true);
            }
            return(false);
        }
コード例 #9
0
        public ActionResult <UserInformation> GetUserInformation(string email, string password)
        {
            var user = Context.Users.FirstOrDefault(c => c.Email == email && c.Password == password);

            if (user == null)
            {
                return(null);
            }
            UserInformation userInfo = new UserInformation
            {
                IsFirstLogin = user.LastLogin == user.CreatedOn
            };

            user.LastLogin = DateConverter.CurrentEasternDateTime();
            Context.SaveChanges();
            userInfo.Id = user.Id;
            var customer = Context.Customers.First(c => c.Id == user.IdCustomer);

            userInfo.FullName = $"{customer.FirstName} {customer.LastName}";
            return(userInfo);
        }
コード例 #10
0
        public int CancelAppointments(List <int> appointmentsToCancel)
        {
            int tooLateToCancel = 0;

            foreach (var appointmentId in appointmentsToCancel)
            {
                var      appointment = Context.Appointments.Where(c => c.Id == appointmentId).First();
                var      timeSlot    = Context.TimeSlots.Where(c => c.Id == appointment.IdTimeSlot).First();
                DateTime now         = DateConverter.CurrentEasternDateTime();
                if (timeSlot.StartDateTime > now.AddHours(24))
                {
                    timeSlot.IsPublic    = false;
                    appointment.IsActive = false;
                    Context.SaveChanges();
                }
                else
                {
                    tooLateToCancel++;
                }
            }
            return(tooLateToCancel);
        }
コード例 #11
0
        internal List <CustomerAppointmentInformation> GetUnconfirmedAppointments(PhoneNumberService phoneNumberService)
        {
            var appointments = (
                from appointment in Context.Appointments
                join customer in Context.Customers on appointment.IdCustomer equals customer.Id
                join timeSlot in Context.TimeSlots on appointment.IdTimeSlot equals timeSlot.Id
                where customer.IsActive && appointment.IsActive && !appointment.IsConfirmed &&
                timeSlot.StartDateTime.Date == DateConverter.CurrentEasternDateTime().Date.AddDays(1)
                select new CustomerAppointmentInformation()
            {
                Customer = customer,
                TimeSlot = timeSlot,
                Appointment = appointment
            }).AsNoTracking().ToList();

            foreach (var appointment in appointments)
            {
                appointment.PhoneNumbers = phoneNumberService
                                           .GetPhoneNumbersForCustomer(appointment.Customer.Id);
            }
            return(appointments.OrderBy(c => c.TimeSlot.StartDateTime).ToList());
        }
コード例 #12
0
        public bool SendChangePasswordEmail(IConfiguration config, string userEmail, bool isNewAccount)
        {
            var user = Context.Users.FirstOrDefault(c => c.Email == userEmail);

            if (user != null)
            {
                ActionToken actionToken = new ActionToken
                {
                    IsActive       = true,
                    Action         = "ForgotPassword",
                    CreatedOn      = DateConverter.CurrentEasternDateTime(),
                    ExpirationDate = DateConverter.CurrentEasternDateTime().AddDays(1),
                    IdUser         = user.Id,
                    Token          = Guid.NewGuid().ToString()
                };
                Context.ActionTokens.Add(actionToken);
                Context.SaveChanges();

                EmailSender.SendEmailToChangePassword(userEmail, actionToken.Token, config, isNewAccount);
                return(true);
            }
            return(false);
        }
コード例 #13
0
        public List <TimeSlot> GetFreeTimeSlots()
        {
            List <TimeSlot>    timeSlots         = Context.TimeSlots.Where(c => c.StartDateTime > DateConverter.CurrentEasternDateTime() && c.IsAvailable && c.IsPublic).ToList();
            List <Appointment> appointments      = Context.Appointments.ToList();
            List <TimeSlot>    timeSlotsToReturn = new List <TimeSlot>();

            timeSlotsToReturn.AddRange(timeSlots);
            foreach (var timeSlot in timeSlots)
            {
                foreach (var appointment in appointments)
                {
                    if (appointment.IdTimeSlot == timeSlot.Id)
                    {
                        timeSlotsToReturn.Remove(timeSlot);
                    }
                }
            }
            return(timeSlotsToReturn);
        }