Ejemplo n.º 1
0
        private void AppointmentAdapter_Click(object sender, EventArgs e)
        {
            // get services;
            UserService userService = new UserService();
            var         firestoreDb = userService.GetDatabase(_context);
            // get local storage service

            View receivedView = (View)sender;
            var  appoitnId    = receivedView.GetTag(deleteBtn.Id);

            Console.WriteLine("Button clicked.");


            var deleteAppointAlert = new AlertDialog.Builder(_context);

            deleteAppointAlert.SetTitle("Sterge programare");
            deleteAppointAlert.SetMessage($"Sunteti sigur ca doriti sa stergeti aceasta programare?");
            deleteAppointAlert.SetPositiveButton("Da", async delegate {
                StorageService storage = new StorageService();
                var clientLogged       = await storage.GetClientDataLocal();
                firestoreDb.Collection("Medics").Document(clientLogged.MedicSubscribed.Id).Collection("Appointments").Document(appoitnId.ToString())
                .Delete();
                // delete appointment also from list
                List <Appointment> appointsList = _appointments.ToList <Appointment>();
                var appointToDelete             = appointsList.FirstOrDefault(appoint => appoint.Id.Equals(appoitnId.ToString()));
                appointsList.Remove(appointToDelete);

                //send notification that appointment was deleted
                Models.Notification newNotif = new Models.Notification()
                {
                    Description = $"Programarea a fost anulata de catre {clientLogged.FirstName}, {clientLogged.LastName}.",
                    Type        = "Programare anulata",
                    Timestamp   = DateTime.Now.ToLocalTime(),
                    MedicId     = clientLogged.MedicSubscribed.Id,
                };

                await _functionsService.AddNotification(newNotif, "notificationCreate");

                _appointments = appointsList.ToArray();
                deleteAppointAlert.Dispose();
                _context.Finish();
                _context.StartActivity(typeof(UpcomingAppointmentsActivity));
                return;
            });
            deleteAppointAlert.SetNegativeButton("Nu", delegate
            {
                deleteAppointAlert.Dispose();
            });
            deleteAppointAlert.Show();
        }
Ejemplo n.º 2
0
        private void Scheduler_CellTapped(object sender, CellTappedEventArgs e)
        {
            DateTimeOffset startDate  = DateTimeOffset.FromUnixTimeMilliseconds(e.Calendar.Time.Time);
            double         difference = (double)e.Calendar.Time.Hours - (double)startDate.Hour;
            // dates are inmutable object so we most create another one
            DateTimeOffset startDateConverted = startDate.AddHours(difference);

            if (startDateConverted < DateTime.Now)
            {
                var oldDaySlot = new AlertDialog.Builder(this);
                oldDaySlot.SetTitle("Nepermis.");
                oldDaySlot.SetMessage("Nu puteti face programari in zilele trecute!");
                oldDaySlot.SetNeutralButton("Ok", delegate
                {
                    oldDaySlot.Dispose();
                });
                oldDaySlot.Show();
                return;
            }
            if (e.ScheduleAppointment != null || e.ScheduleAppointments != null)
            {
                var slotTakenAlert = new AlertDialog.Builder(this);
                slotTakenAlert.SetTitle("Nepermis");
                slotTakenAlert.SetMessage("Acest loc este ocupat!");
                slotTakenAlert.SetNeutralButton("Ok", delegate
                {
                    slotTakenAlert.Dispose();
                });
                slotTakenAlert.Show();
            }
            else
            {
                var startTime = e.Calendar.Time;
                var endTime   = e.Calendar.Time;
                endTime.Minutes += (int)_consultType.Duration;
                var makeAppointmentAlert = new AlertDialog.Builder(this);
                makeAppointmentAlert.SetTitle("Programare la ora " + startDateConverted.ToString("hh-mm tt", System.Globalization.CultureInfo.InvariantCulture));
                makeAppointmentAlert.SetMessage($"Faceti programare pentru {animalSelected.Name}?");
                makeAppointmentAlert.SetPositiveButton("Da", async delegate {
                    HashMap mapAppointment = new HashMap();
                    // construct new appointment
                    mapAppointment.Put("animalName", animalSelected.Name);
                    mapAppointment.Put("clientId", clientLogged.Id);
                    mapAppointment.Put("duration", _consultType.Duration);
                    mapAppointment.Put("price", _consultType.Price);
                    mapAppointment.Put("type", _consultType.Type);
                    mapAppointment.Put("startTime", startTime);
                    mapAppointment.Put("endTime", endTime);

                    _firestoreDb.Collection("Medics").Document(clientLogged.MedicSubscribed.Id).Collection("Appointments").Document().Set(mapAppointment);
                    // send request to firebase function to create notification
                    Models.Notification newNotif = new Models.Notification()
                    {
                        Description = "O noua programare pentru " + animalSelected.Name,
                        Type        = "Programare noua",
                        Timestamp   = DateTime.Now.ToLocalTime(),
                        MedicId     = clientLogged.MedicSubscribed.Id,
                    };

                    await _functionsService.AddNotification(newNotif, "notificationCreate");


                    _scheduler.ItemsSource = null;
                    _appointments.Clear();
                    FetchAppointmentsWeek();
                    makeAppointmentAlert.Dispose();
                });
                makeAppointmentAlert.SetNegativeButton("Nu", delegate
                {
                    makeAppointmentAlert.Dispose();
                });
                makeAppointmentAlert.Show();
            }
        }
Ejemplo n.º 3
0
        private async void MedicListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            medicSelected    = _medicsFetched[e.Position];
            clientLoggedData = await _storageService.GetClientDataLocal();

            // create hashMap in order to insert the client into the selected medic database
            HashMap mapClient = new HashMap();

            mapClient.Put("Email", clientLoggedData.Email);
            mapClient.Put("FirstName", clientLoggedData.FirstName);
            mapClient.Put("LastName", clientLoggedData.LastName);
            mapClient.Put("Phone", clientLoggedData.Phone);
            mapClient.Put("NotificationToken", clientLoggedData.Token);

            if (clientLoggedData.MedicSubscribed != null)
            {
                if (clientLoggedData.MedicSubscribed.Id == medicSelected.Id)
                {
                    AlertDialog.Builder alreadySubscribedDialog = new AlertDialog.Builder(this);
                    alreadySubscribedDialog.SetTitle("Abonare");
                    alreadySubscribedDialog.SetMessage("Sunteti deja abonat la acest medic!");
                    alreadySubscribedDialog.SetNeutralButton("Ok", delegate
                    {
                        alreadySubscribedDialog.Dispose();
                    });
                    alreadySubscribedDialog.Show();
                }
                else
                {
                    AlertDialog.Builder subscribeToAnotherMedic = new AlertDialog.Builder(this);
                    subscribeToAnotherMedic.SetTitle("Abonare la alt medic");
                    subscribeToAnotherMedic.SetMessage($"Doriti sa va abonati la {medicSelected.FirstName}, {medicSelected.LastName}?");

                    subscribeToAnotherMedic.SetPositiveButton("Da", async delegate
                    {
                        Models.Notification newNotif = new Models.Notification()
                        {
                            Type        = clientLoggedData.MedicSubscribed.Id,
                            MedicId     = medicSelected.Id,
                            Description = clientLoggedData.Id,
                        };
                        await _functionsService.AddNotification(newNotif, "medicMigrate");
                        await CheckIfClientExistsAsync();
                        // TODO: check if client has been added

                        subscribeToAnotherMedic.Dispose();
                    });
                    subscribeToAnotherMedic.SetNegativeButton("Nu", delegate
                    {
                        subscribeToAnotherMedic.Dispose();
                    });

                    subscribeToAnotherMedic.Show();
                }
            }
            else
            {
                AlertDialog.Builder subscribeDialog = new AlertDialog.Builder(this);
                subscribeDialog.SetTitle("Abonare");
                subscribeDialog.SetMessage($"Doriti sa va abonati la {medicSelected.FirstName}, {medicSelected.LastName}?");

                subscribeDialog.SetPositiveButton("Da", async delegate
                {
                    // add Client to that medic DataBase
                    _firestoreDb.Collection("Medics").Document(medicSelected.Id).Collection("Clients").Document(clientLoggedData.Id).Set(mapClient)
                    .AddOnFailureListener(this);
                    clientLoggedData.MedicSubscribed = medicSelected;
                    // storing also medic that the user has subscribed to
                    await _storageService.SaveClientDataLocal(clientLoggedData);
                    Models.Notification newNotif = new Models.Notification()
                    {
                        Description = $"{clientLoggedData.FirstName}, {clientLoggedData.LastName} s-a abonat la dumneavoastra.",
                        Type        = "Client nou",
                        Timestamp   = DateTime.Now.ToLocalTime(),
                        MedicId     = clientLoggedData.MedicSubscribed.Id,
                    };

                    await _functionsService.AddNotification(newNotif, "notificationCreate");
                    subscribeDialog.Dispose();
                });
                subscribeDialog.SetNegativeButton("Nu", delegate
                {
                    subscribeDialog.Dispose();
                });
                subscribeDialog.Show();
            }
        }