public async Task <List <AreaSolicitante> > migrateCsvData(string file) { List <AreaSolicitante> colection = new List <AreaSolicitante>(); string[] st = System.IO.File.ReadAllLines(file); List <String> filas = st.ToList(); filas .Where(fila => fila != filas[0]) .ToList() .ForEach(fila => { string[] atributo = fila.Split(";"); AreaSolicitante areaSolicitante = new AreaSolicitante(); //tipoRequerimiento.Id = int.Parse(atributo[ID]); areaSolicitante.Nombre = atributo[NOMBRE]; areaSolicitante.Encargado = atributo[ENCARGADO]; areaSolicitante.Dml = "I"; dbContext.AreaSolicitantes.AddAsync(areaSolicitante); colection.Add(areaSolicitante); }); await dbContext.SaveChangesAsync(); return(colection); }
public async Task <AreaSolicitante> save(AreaSolicitante areasolicitante) { areasolicitante.Dml = "I"; areasolicitante.UpDateTime = new DateTime(); areasolicitante.CreateTime = new DateTime(); dbContext.AreaSolicitantes.Add(areasolicitante); await dbContext.SaveChangesAsync(); return(areasolicitante); }
public async Task <AreaSolicitante> findById(int Id) { if (Id == null || Id == 0) { return(new AreaSolicitante()); } AreaSolicitante areasolicitante = await dbContext.AreaSolicitantes.FindAsync(Id); return(areasolicitante); }
/******************************************METHOD'S*******************************/ public async Task <AreaSolicitante> deleteById(int Id) { AreaSolicitante areasolicitante = findById(Id).Result; areasolicitante.Dml = "D"; dbContext.AreaSolicitantes.Update(areasolicitante); await dbContext.SaveChangesAsync(); return(areasolicitante); }
public IActionResult DeleteProductById(int Id) { IAreaSolicitanteService service = new AreaSolicitanteService(DbContext); Response <AreaSolicitante> response = new Response <AreaSolicitante>(); try { AreaSolicitante p = service.deleteById(Id).Result; response.ok(true, p, "Se cambio el estado a DELETE"); return(Ok(response)); } catch (Exception ex) { response.ok(false, new AreaSolicitante(), "Error al cambiar estado " + ex.Message); return(BadRequest(response)); } }
public IActionResult SaveAreaSolicitante(AreaSolicitante areasolicitante) { Response <AreaSolicitante> response = new Response <AreaSolicitante>(); try { IAreaSolicitanteService service = new AreaSolicitanteService(DbContext); Task <AreaSolicitante> p = service.save(areasolicitante); response.ok(true, p.Result, "Se inserto el area solicitante"); return(Ok(response)); } catch (Exception ex) { response.ok(false, null, "Error en el servicio " + ex.Message); return(BadRequest(response)); } }