public async Task <ActionResult <DebitNoteLine> > Insert([FromBody] DebitNoteLine _DebitNoteLine) { DebitNoteLine _DebitNoteLineq = new DebitNoteLine(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _DebitNoteLineq = _DebitNoteLine; _context.DebitNoteLine.Add(_DebitNoteLineq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _DebitNoteLine.DebitNoteLineId, DocType = "DebitNoteLine", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_DebitNoteLine, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_DebitNoteLine, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } return(await Task.Run(() => Ok(_DebitNoteLineq))); }
public async Task <IActionResult> GetDebitNoteLineById(Int64 DebitNoteLineId) { DebitNoteLine Items = new DebitNoteLine(); try { Items = await _context.DebitNoteLine.Where(q => q.DebitNoteLineId == DebitNoteLineId).FirstOrDefaultAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } return(await Task.Run(() => Ok(Items))); }
public async Task <IActionResult> Delete([FromBody] DebitNoteLine _DebitNoteLine) { DebitNoteLine _DebitNoteLineq = new DebitNoteLine(); try { _DebitNoteLineq = _context.DebitNoteLine .Where(x => x.DebitNoteLineId == (Int64)_DebitNoteLine.DebitNoteLineId) .FirstOrDefault(); _context.DebitNoteLine.Remove(_DebitNoteLineq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } return(await Task.Run(() => Ok(_DebitNoteLineq))); }
public async Task <ActionResult <DebitNoteLine> > Update([FromBody] DebitNoteLine _DebitNoteLine) { DebitNoteLine _DebitNoteLineq = _DebitNoteLine; try { _DebitNoteLineq = await(from c in _context.DebitNoteLine .Where(q => q.DebitNoteLineId == _DebitNoteLine.DebitNoteLineId) select c ).FirstOrDefaultAsync(); _context.Entry(_DebitNoteLineq).CurrentValues.SetValues((_DebitNoteLine)); //_context.DebitNoteLine.Update(_DebitNoteLineq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } return(await Task.Run(() => Ok(_DebitNoteLineq))); }