private void Add_Region_Button_Click(object sender, RoutedEventArgs e)
        {
            string           input          = this.RegionInput.Text;
            List <Locations> locations      = _context.Locations.ToList();
            List <string>    locationsNames = new List <string>();

            foreach (Locations loc in locations)
            {
                locationsNames.Add(loc.Name);
            }
            if (string.IsNullOrWhiteSpace(input))
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "Region Input is Empty", Brushes.Red);
            }
            else if (locationsNames.Contains(input))
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "Region already added", Brushes.Red);
            }
            else
            {
                int id = Utilities.Utilities.GenerateId();
                _context.Add(new Locations {
                    LocationId = id, Name = input
                });
                _context.SaveChanges();
                List <Locations> newLocations = _context.Locations.ToList();
                DoctorLocationInput.ItemsSource = newLocations;
                Utilities.Utilities.SetErrorMessage(errorMessage, "Region Added Correctly", Brushes.Green);
            }
        }
        public ActionResult Create([Bind(Include = "AppointmentId")] Appointment appointment)
        {
            if (ModelState.IsValid)
            {
                db.Appointments.Add(appointment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(appointment));
        }
        public IActionResult AddMeeting([FromBody] ModelMeeting content)
        {
            int statusPending = 1;

            Meetings newMeeting = new Meetings
            {
                IdDay      = content.IdDay,
                IdTimeslot = content.IdTimeslot,
                IdStatus   = statusPending
            };

            db.Meetings.Add(newMeeting);
            db.SaveChanges();
            return(Created(Url.Link("GetMeeting", new { id = newMeeting.IdMeeting }), newMeeting));
        }
Esempio n. 4
0
 public IActionResult AddAppointment(Appointment newApt)
 {
     if (ModelState.IsValid)
     {
         _context.Appointments.Add(newApt);
         _context.SaveChanges();
         return(RedirectToAction("ViewAppointments"));
     }
     else
     {
         return(View());
     }
 }
        public IActionResult AddMeeting()
        {
            TblMeetings newMeeting = new TblMeetings()
            {
                IdDay      = 1,
                IdTimeslot = 2
            };

            db.TblMeetings.Add(newMeeting);
            db.SaveChanges();

            return(ListAllMeetings());
        }
Esempio n. 6
0
        private void Add_Visit_Button_Click(object sender, RoutedEventArgs e)
        {
            int selectedLocationId       = _context.Locations.ToList()[LocationVisitInput.SelectedIndex].LocationId;
            int selectedDoctorId         = _doctors[DoctorVisitInput.SelectedIndex].Id;
            int selectedDoctorLocationId = _context.Doctors
                                           .Where(d => d.DoctorId == selectedDoctorId).FirstOrDefault().LocationId;
            int fromTimeId = _fromHours[FromTimeVisitInput.SelectedIndex].Id;
            int toTimeId   = _toHours[ToVisitInput.SelectedIndex].Id;

            if (selectedDoctorLocationId != selectedLocationId)
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "Selected Doctor isn't available at Selected Location", Brushes.Red);
            }
            else if (fromTimeId > toTimeId)
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "Visit End Time can't be lower than Visit Start Time", Brushes.Red);
            }
            else if (fromTimeId == toTimeId)
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "Visit End Time can't be equal to Visit Start Time", Brushes.Red);
            }
            else if (string.IsNullOrWhiteSpace(LocationVisitInput.Text))
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "Location not selected", Brushes.Red);
            }
            else if (string.IsNullOrWhiteSpace(CustomerVisitInput.Text))
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "Customer not selected", Brushes.Red);
            }
            else if (string.IsNullOrWhiteSpace(FromTimeVisitInput.Text))
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "From hour not selected", Brushes.Red);
            }
            else if (string.IsNullOrWhiteSpace(ToVisitInput.Text))
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "To hour not selected", Brushes.Red);
            }
            else if (string.IsNullOrWhiteSpace(DoctorVisitInput.Text))
            {
                Utilities.Utilities.SetErrorMessage(errorMessage, "Doctor not selected", Brushes.Red);
            }
            else
            {
                int visitTimeId = new Random().Next();
                _context.Add(new VisitTime
                {
                    VisitTimeId = visitTimeId,
                    From        = TimeSpan.Parse(_fromHours[FromTimeVisitInput.SelectedIndex].Name),
                    To          = TimeSpan.Parse(_toHours[ToVisitInput.SelectedIndex].Name)
                });
                _context.SaveChanges();
                _context.Add(new Visits
                {
                    VisitId     = Utilities.Utilities.GenerateId(),
                    ClientId    = _context.Clients.ToList()[CustomerVisitInput.SelectedIndex].ClientId,
                    DoctorId    = selectedDoctorId,
                    LocationId  = selectedLocationId,
                    VisitTimeId = visitTimeId
                });
                _context.SaveChanges();
                Utilities.Utilities.SetErrorMessage(errorMessage, "Visit Added Correctly", Brushes.Green);
            }
        }
        public async Task <IActionResult> ConfirmAppointment([FromBody] AInfo info)
        {
            byte[] newRowVersion = null;
            try
            {
                var appointment = await _dbContext.Appointments.AsNoTracking().Include(a => a.Doctor).Include(a => a.Info).SingleOrDefaultAsync(a => a.Id == info.id);

                if (appointment == null)
                {
                    return(Ok("Fail"));
                }

                bool update = false;
                if (appointment.Status == "Confirmed")
                {
                    update = true;
                }


                appointment.RowVersion = info.rowVersion;
                appointment.Status     = "Confirmed";

                var start = DateTime.ParseExact(info.date + " " + info.start, "yyyy-MM-dd HH:mm", null);
                appointment.Start = start;
                appointment.End   = start.AddMinutes(info.duration);
                appointment.Info.AdditionalInfo = info.info;



                var appointments = _dbContext.Appointments.AsNoTracking().Include(ft => ft.Doctor)
                                   .Where(a => a.Status == "Confirmed" && a.Doctor.Name == appointment.Doctor.Name && a.Start.Date == appointment.Start.Date);

                var intersectingElements = CalculateIntersectingElements(appointment, appointments);
                if (intersectingElements.Count > 0)
                {
                    return(Ok("Intersection in time"));
                }

                if (!update)
                {
                    appointment.EventId = Guid.NewGuid().ToString("N");
                }

                _dbContext.Appointments.Update(appointment);
                _dbContext.SaveChanges();

                newRowVersion = appointment.RowVersion;


                Event newEvent = new Event()
                {
                    Id          = appointment.EventId,
                    Summary     = appointment.Info.PatientName + " - " + appointment.Doctor.Name,
                    Description = "Procedure: " + appointment.Info.AdditionalInfo +
                                  "\nDoctor Name: " + appointment.Doctor.Name + "\nPatient Name: " + appointment.Info.PatientName,
                    //Attendees = new EventAttendee[]
                    //{
                    //  new EventAttendee{ DisplayName = info.patient, Email = "" },
                    //  new EventAttendee{ DisplayName = info.doctor, Email = "" },
                    //},
                    Start = new EventDateTime()
                    {
                        DateTime = appointment.Start,
                    },
                    End = new EventDateTime()
                    {
                        DateTime = appointment.End,
                    }
                };

                if (update)
                {
                    var   eventId      = appointment.EventId;
                    var   request      = _calendar.Service.Events.Update(newEvent, _calendar.CalendarId, eventId);
                    Event createdEvent = request.Execute();
                }
                else
                {
                    var   request      = _calendar.Service.Events.Insert(newEvent, _calendar.CalendarId);
                    Event createdEvent = await request.ExecuteAsync();
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Ok("Fail"));
            }

            return(Ok(new { status = "Confirmed", newRowVersion = newRowVersion }));
        }