public async Task <IActionResult> PutUsuario([FromRoute] int id, [FromBody] Usuario usuario) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != usuario.IdUsuario) { return(BadRequest()); } _context.Entry(usuario).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsuarioExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
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)); } } }
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(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)); } } }
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)); } } }
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)); } } }
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)); } } }