public IEnumerable <AppointmentsVM> GetAppointmentsByDay(CalendarVM selection) { List <AppointmentsVM> result = new List <AppointmentsVM>(); int slotTotalCapacity = (selection.DoctorID != 0) ? 1 : db.Doctors.Count(); List <Appointment> apps = null; if (selection.DoctorID == 0) { apps = db.Appointments.Where(a => DbFunctions.TruncateTime(a.Date) == selection.Date.Date && a.Status != (int)AppointmentStatus.Canceled).ToList(); } else { apps = db.Appointments.Where(a => DbFunctions.TruncateTime(a.Date) == selection.Date.Date && a.DoctorID == selection.DoctorID && a.Status != (int)AppointmentStatus.Canceled).ToList(); } AppointmentsVM app; for (int i = 0; i < 12; i++) { app = new AppointmentsVM(); app.Period = GetAppointmentSlotByClinic(1, i); app.TotalCapacity = slotTotalCapacity; app.Appointments = apps.Where(a => a.TimeSlot == i).Count(); result.Add(app); } return(result); }
public IEnumerable <AppointmentsVM> GetAppointmentsByWeek(CalendarVM selection) { FillDB(); List <AppointmentsVM> result = new List <AppointmentsVM>(); int dayTotalCapacity = (selection.DoctorID != 0) ? 16 : db.Doctors.Count() * 16; DateTime monday = selection.Date.AddDays(-(int)selection.Date.DayOfWeek + (int)DayOfWeek.Monday); DateTime sunday = monday.AddDays(6); List <Appointment> apps = null; if (selection.DoctorID == 0) { apps = db.Appointments.Where(a => DbFunctions.TruncateTime(a.Date) >= monday.Date && DbFunctions.TruncateTime(a.Date) <= sunday.Date).ToList(); } else { apps = db.Appointments.Where(a => DbFunctions.TruncateTime(a.Date) >= monday.Date && DbFunctions.TruncateTime(a.Date) <= sunday.Date && a.DoctorID == selection.DoctorID).ToList(); } AppointmentsVM app; DateTime day; for (int i = 0; i < 7; i++) { app = new AppointmentsVM(); day = monday.AddDays(i); app.Period = day.DayOfWeek.ToString() + ", " + day.ToString("MM/dd/yyy"); app.TotalCapacity = dayTotalCapacity; app.Appointments = apps.Where(a => a.Date.Date == day.Date).Count(); result.Add(app); } return(result); }
public FilterAppointmentsCommand( AppointmentsVM appointmentsVM, IUserRepository userRepository, ICustomerRepository customerRepository) { _appointmentsVM = appointmentsVM; _userRepository = userRepository; _customerRepository = customerRepository; }
public NewAppointmentCommand( AppointmentsVM appointmentsVM, IAppointmentRepository repository, IUserRepository userRepository, ICustomerRepository customerRepository, IStateManager <AppointmentDTO> state, User user) { _appointmentsVM = appointmentsVM; _repository = repository; _userRepository = userRepository; _customerRepository = customerRepository; _state = state; _user = user; }
public DeleteAppointmentCommand( AppointmentsVM appointmentsVM, IAppointmentRepository repository, IUserRepository userRepository, ICustomerRepository customerRepository, IStateManager <AppointmentDTO> state, User user) { _appointmentsVM = appointmentsVM; _repository = repository; _userRepository = userRepository; _customerRepository = customerRepository; _state = state; _user = user; _appointmentsVM.PropertyChanged += AppointmentChanged; }
public async Task <IHttpActionResult> PostAppointment(AppointmentsVM appointmentVM) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Appointment appointment = new Appointment(); appointment.appointment_reason = appointmentVM.Reason; appointment.appointment_date = DateTime.Parse(appointmentVM.Time); appointment.appointment_notes = appointmentVM.Notes; appointment.appointment_duration = appointmentVM.Duration; appointment.appointment_id = 0; db.Appointments.Add(appointment); await db.SaveChangesAsync(); return(CreatedAtRoute("appointmetPost", new { id = appointment.appointment_id }, appointment)); }
public async Task <IActionResult> UpdateAppointment(int Id, [FromBody] AppointmentsVM appointment) { try { if (appointment == null) { return(BadRequest(new { errorMessage = "object cannot be null" })); } if (!ModelState.IsValid) { return(BadRequest(new { errorMessage = "Invalid object" })); } //get the customer's record var existingRecord = await _repoWrapper.Appointments.GetAppointmentByIdAsync(Id); if (existingRecord == null) { return(NotFound()); } //map the incoming data to the data fetched from the db _mapper.Map(appointment, existingRecord); _repoWrapper.Appointments.UpdateAppointment(existingRecord); await _repoWrapper.SaveAsync(); return(NoContent());//success } catch (Exception) { return(this.StatusCode(500)); } }
public async Task <IActionResult> CreateAppointment(int id, [FromBody] AppointmentsVM appointment) { try { if (appointment == null) { return(BadRequest(new { errorMessage = "object can not be null" })); } if (!ModelState.IsValid) { return(BadRequest(new { errorMessage = "Invalid model" })); } //takes in consultantid - //find the consultant which the client is requesting an appointment with //send email to the consultant var consultant = await _repoWrapper.Consultants.GetConsultantByIdAsync(id); if (consultant == null) { return(BadRequest(new { message = "no matching consultant record found" })); } //get consultant email string consultantEmail = consultant.Email; //build email //string subject = "Request for Appointment"; //string messageToConsultant = $"{appointment.FirstName} {appointment.LastName} has requested to have an appointment with you"; //generate random reference number for each appointment appointment.ReferenceNumber = GenerateRandomNumber(10); appointment.RequestDate = DateTime.Now; appointment.Status = "pending"; //message body for patient -- //string messageToPatient = $"Your request has been received, {consultant.FirstName} {consultant.LastName} will contact you shortly. " + //$"your reference number is {appointment.ReferenceNumber}"; var newAppointment = _mapper.Map <Appointment>(appointment); //set appointment delete status to false newAppointment.isDeleted = false; _repoWrapper.Appointments.CreateAppointment(newAppointment); await _repoWrapper.SaveAsync(); //send email to consultant //_emailService.SendEmail(consultantEmail, subject, messageToConsultant); //send mail to client //_emailService.SendEmail(appointment.Email, subject, messageToPatient); return(Created($"/api/appointments/{newAppointment.Id}", newAppointment)); } catch (Exception) { //if an exception occurs return(this.StatusCode(500)); } }
public async Task <IActionResult> Index(int productPage = 1, string searchName = null, string searchPhone = null, string searchEmail = null, string SearchDate = null) { ClaimsPrincipal claimsUser = this.User; var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claims = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); AppointmentsVM appointmentsVM = new AppointmentsVM() { appointments = new List <Models.Appointments>() }; StringBuilder builder = new StringBuilder(); builder.Append("/Admin/Appointment?productPage=:"); builder.Append("&searchName="); if (searchName != null) { builder.Append(searchName); } builder.Append("&searchPhone="); if (searchName != null) { builder.Append(searchPhone); } builder.Append("&searchEmail="); if (searchName != null) { builder.Append(searchEmail); } builder.Append("&SearchDate="); if (searchName != null) { builder.Append(SearchDate); } appointmentsVM.appointments = _db.appointments.Include(a => a.SalesPerson).ToList(); if (User.IsInRole(SD.AdminUser)) { appointmentsVM.appointments = appointmentsVM.appointments.Where(a => a.SalesPersonID == claims.Value).ToList(); } if (searchName != null) { appointmentsVM.appointments = appointmentsVM.appointments.Where(a => a.CustomerName.ToLower().Contains(searchName.ToLower())).ToList(); } if (searchEmail != null) { appointmentsVM.appointments = appointmentsVM.appointments.Where(a => a.CustomerEmail.ToLower().Contains(searchEmail.ToLower())).ToList(); } if (searchPhone != null) { appointmentsVM.appointments = appointmentsVM.appointments.Where(a => a.CustomerPhone.ToLower().Contains(searchPhone.ToLower())).ToList(); } if (SearchDate != null) { try { DateTime searchAppDate = Convert.ToDateTime(SearchDate); appointmentsVM.appointments = appointmentsVM.appointments.Where(a => a.AppointmentDate.ToShortDateString().Equals(searchAppDate.ToShortDateString())).ToList(); } catch (Exception ex) { } } var count = appointmentsVM.appointments.Count; appointmentsVM.appointments = appointmentsVM.appointments.OrderBy(a => a.AppointmentDate) .Skip((productPage - 1) * pageSize) .Take(pageSize).ToList(); appointmentsVM.PagingInfo = new PagingInfo { CurrentPage = productPage, ItemsPerPage = pageSize, TotalItems = count, urlParam = builder.ToString() }; return(View(appointmentsVM)); }