public async Task <ActionResult <CitaDTO> > CreateCita(CreateCitaDTO citaDto) { Cita cita = mapper.Map <CreateCitaDTO, Cita>(citaDto); var newCitaId = await citaService.saveAsync(cita); if (newCitaId == null) { return(BadRequest()); } return(await GetCita((long)newCitaId)); }
//new cita public async Task <Citas> NewCita(CreateCitaDTO model) { var paciente = context.Pacientes.Include(x => x.persona).FirstOrDefaultAsync(x => x.idPaciente == model.idPaciente); logger.Information("Creatin a new cita"); var cita = mapper.Map <Citas>(model); cita.idEstado = 5; cita.fechaAsignacion = DateTime.Today; cita.edad = DateTime.Today.AddTicks(-paciente.Result.persona.fechaNacimiento.Ticks).Year - 1; await context.Citas.AddAsync(cita); await context.SaveChangesAsync(); return(cita); }
public async Task <ActionResult> newCita([FromBody] CreateCitaDTO model) { string txt = "Create cita medica"; using (var transaction = context.Database.BeginTransaction()) { logger.LogInformation("BeginTransaction {0} ", txt); try { var cita = await fundabiem.NewCita(model); transaction.Commit(); logger.LogInformation("Commit Transaction {0} ", txt); return(new CreatedAtRouteResult("ObtenerCita", new { id = cita.IdCita }, cita)); }catch (Exception ex) { transaction.Rollback(); logger.LogError("RollBack transaction {0} ", txt); logger.LogError("Error ==>> {0} ", ex.ToString()); return(BadRequest("No se completo la accion " + txt)); } } }