public async Task <ActionResult> Create(AppointmentModel appointmentModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var appointment  = new Appointment();
                    var patient      = context.User.Where(u => u.Id == appointmentModel.IdPatient).First();
                    var professional = context.User.Where(u => u.Id == appointmentModel.IdProfessional).First();

                    appointment.Patient      = (Patient)patient;
                    appointment.Professional = (Professional)professional;

                    appointment.Date = appointmentModel.Date;

                    await context.Appointment.AddAsync(appointment);

                    await context.SaveChangesAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(Ok(false));
                }
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> SendMessage(UserModel userModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var patient = context.Patient.Where(p => p.Id == userModel.Id).FirstOrDefault();

                    var professionals = context.Professional.Where(p => p.Patients.Contains(patient)).ToList();

                    TwilioClient.Init("AC0dbc1caba6d2ff26d915796a0ae581c0", "b717f4c11dc57234ff4671fefbf2e54a");

                    foreach (var prof in professionals)
                    {
                        MessageResource.Create(
                            body: "Seu paciente " + patient.Name + " esta com uma emergêcia. Por favor entre em contato no número: " + patient.Phone,
                            from: new Twilio.Types.PhoneNumber("+12057548800"),
                            to: new Twilio.Types.PhoneNumber(prof.Phone));
                    }
                    return(Ok(true));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return(Ok(false));
                }
            }
        }
        public async Task <ActionResult> GetListAppointment(AppointmentModel appointmentModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var appointment = context.Appointment.ToList();
                    if (appointmentModel.IdPatient > 0)
                    {
                        appointment = appointment.Where(a => a.Patient.Id == appointmentModel.IdPatient).ToList();
                    }

                    if (appointmentModel.IdProfessional > 0)
                    {
                        appointment = appointment.Where(a => a.Professional.Id == appointmentModel.IdProfessional).ToList();
                    }

                    return(Ok(appointment.ToArray()));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return(Ok(false));
                }
            }
        }
Esempio n. 4
0
        public async Task <ActionResult> Auth([FromBody] LoginModel model)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    return(Ok(await context.User.AnyAsync(p => p.UserName.ToLower() == model.userName.ToLower() && Crypter.CheckPassword(p.Password, model.password))));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return(Ok(false));
                }
            }
        }
Esempio n. 5
0
        public async Task <ActionResult> Get(DiaryModel diaryModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var diary = context.Diary.Where(d => d.Id == diaryModel.Id).FirstOrDefault();

                    return(Ok(diary));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return(Ok(false));
                }
            }
        }
Esempio n. 6
0
        public async Task <ActionResult> Get()
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var users = context.User.Select(u => u);


                    return(Ok(users.ToArray()));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return(Ok(false));
                }
            }
        }
Esempio n. 7
0
        public async Task <ActionResult> GetListPatient(ProfessionalModel professionalModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var professionalPatiens = context.Professional.Where(u => u.Id == professionalModel.IdProfessional).Select(p => p.Patients).ToList().FirstOrDefault();
                    var patients            = professionalPatiens.Select(p => p);


                    return(Ok(patients.ToArray()));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(Ok(false));
                }
            }
        }
Esempio n. 8
0
        public async Task <ActionResult> Create(UserModel userModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    if ((Models.FlyWeight.Type)userModel.Type == Models.FlyWeight.Type.Professional)
                    {
                        var user = new Professional(userModel.UserName, userModel.Password, userModel.Email);
                        user.Name      = userModel.Name;
                        user.Gender    = (Gender)userModel.Gender;
                        user.Type      = (Models.FlyWeight.Type)userModel.Type;
                        user.Phone     = userModel.Phone;
                        user.DateBirth = userModel.DateBirth;

                        user.CRP        = userModel.CRP;
                        user.Specialty  = (Specialty)userModel.Specialty;
                        user.CareerTime = userModel.CareerTime;

                        await context.Professional.AddAsync(user);
                    }
                    else if ((Models.FlyWeight.Type)userModel.Type == Models.FlyWeight.Type.Patient)
                    {
                        var user = new Patient(userModel.UserName, userModel.Password, userModel.Email);
                        user.Name      = userModel.Name;
                        user.Gender    = (Gender)userModel.Gender;
                        user.Type      = (Models.FlyWeight.Type)userModel.Type;
                        user.Phone     = userModel.Phone;
                        user.DateBirth = userModel.DateBirth;

                        await context.Patient.AddAsync(user);
                    }
                    await context.SaveChangesAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(Ok(false));
                }
            }
        }
        public async Task <ActionResult> Delete(AppointmentModel appointmentModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var appointment = context.Appointment.Where(u => u.Id == appointmentModel.Id).First();

                    context.Appointment.Remove(appointment);

                    await context.SaveChangesAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return(Ok(false));
                }
            }
        }
Esempio n. 10
0
        public async Task <ActionResult> Delete(UserModel userModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var user = context.User.Where(u => u.Id == userModel.Id).First();

                    context.User.Remove(user);

                    await context.SaveChangesAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return(Ok(false));
                }
            }
        }
Esempio n. 11
0
        public async Task <ActionResult> SetPatient(ProfessionalModel professionalModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var patient      = context.Patient.Where(u => u.Id == professionalModel.IdPatient).First();
                    var professional = context.Professional.Where(u => u.Id == professionalModel.IdProfessional).First();

                    professional.Patients.Add(patient);

                    await context.SaveChangesAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(Ok(false));
                }
            }
        }
Esempio n. 12
0
        public async Task <ActionResult> Create(DiaryModel diaryModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var diary = new Diary();

                    diary.Date        = diaryModel.Date;
                    diary.Description = diaryModel.Description;

                    await context.Diary.AddAsync(diary);

                    await context.SaveChangesAsync();

                    return(Ok(diary.Id));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(Ok(false));
                }
            }
        }
 public CompanyRepository(MegaHackContext context)
 {
     _context = context;
 }
Esempio n. 14
0
 public ClientRepository(MegaHackContext context)
 {
     _context = context;
 }
Esempio n. 15
0
 public BonusBLL(MegaHackContext context)
 {
     _context = context;
 }
Esempio n. 16
0
 public CompanyBLL(MegaHackContext context)
 {
     _context = context;
 }
 public UsuariosController(MegaHackContext context)
 {
     _context = context;
 }
Esempio n. 18
0
 public ClientBLL(MegaHackContext context)
 {
     _context = context;
 }
 public BonusRepository(MegaHackContext context)
 {
     _context = context;
 }