public async Task <ActionResult <SubProduct> > Insert([FromBody] SubProduct _subproduct) { SubProduct subProduct = _subproduct; try { subProduct.ProductTypeName = await _context.ProductType .Where(q => q.ProductTypeId == _subproduct.ProductTypeId) .Select(q => q.ProductTypeName) .FirstOrDefaultAsync(); _context.SubProduct.Add(subProduct); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = subProduct.SubproductId, DocType = "SubProducto", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_subproduct, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }) , Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _subproduct.UsuarioCreacion, UsuarioModificacion = _subproduct.UsuarioModificacion , UsuarioEjecucion = _subproduct.UsuarioModificacion, }); 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(subProduct))); // return Ok(currency); }
public async Task <ActionResult <InsurancesCertificate> > Update([FromBody] InsurancesCertificate _InsurancesCertificateP) { InsurancesCertificate _InsurancesCertificateq = _InsurancesCertificateP; try { using (var transaction = _context.Database.BeginTransaction()) { try { _InsurancesCertificateq = await(from c in _context.InsurancesCertificate .Where(q => q.InsurancesCertificateId == _InsurancesCertificateP.InsurancesCertificateId) select c ).FirstOrDefaultAsync(); _context.Entry(_InsurancesCertificateq).CurrentValues.SetValues((_InsurancesCertificateP)); //_context.Alert.Update(_Alertq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _InsurancesCertificateq.InsurancesCertificateId, DocType = "Insurances", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_InsurancesCertificateq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_InsurancesCertificateq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _InsurancesCertificateP.CreatedUser, UsuarioModificacion = _InsurancesCertificateP.ModifiedUser, UsuarioEjecucion = _InsurancesCertificateP.ModifiedUser, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } 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(_InsurancesCertificateq))); }
public async Task <IActionResult> Insert([FromBody] HoursWorked hoursworked) { HoursWorked HoursWorked = hoursworked; try { using (var transaction = _context.Database.BeginTransaction()) { try { _context.HoursWorked.Add(HoursWorked); //await _context.SaveChangesAsync(); foreach (var item in hoursworked.idhorastrabajadasconstrains) { item.IdHorasTrabajadas = hoursworked.IdHorastrabajadas; _context.HoursWorkedDetail.Add(item); } await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = HoursWorked.IdHorastrabajadas, DocType = "HoursWorked", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(hoursworked, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(HoursWorked, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = HoursWorked.UsuarioCreacion, UsuarioModificacion = HoursWorked.UsuarioModificacion, UsuarioEjecucion = HoursWorked.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } // this.UpdateSalesOrder(salesOrder.SalesOrderId); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(HoursWorked))); }
public async Task <ActionResult <Boleto_Ent> > Update([FromBody] Boleto_Ent _Boleto_Ent) { Boleto_Ent _Boleto_Entq = _Boleto_Ent; try { using (var transaction = _context.Database.BeginTransaction()) { try { _Boleto_Entq = await(from c in _context.Boleto_Ent .Where(q => q.clave_e == _Boleto_Ent.clave_e) select c ).FirstOrDefaultAsync(); _context.Entry(_Boleto_Entq).CurrentValues.SetValues((_Boleto_Ent)); //_context.Boleto_Ent.Update(_Boleto_Entq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Boleto_Ent.clave_e, DocType = "Boleto_Ent", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Boleto_Ent, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_Boleto_Ent, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, //UsuarioCreacion = _Boleto_Ent.UsuarioCreacion, //UsuarioModificacion = _Boleto_Ent.UsuarioModificacion, //UsuarioEjecucion = _Boleto_Ent.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(Ok(_Boleto_Entq)); }
public async Task <IActionResult> Insert([FromBody] SalesOrder salesorder) { SalesOrder salesOrder = salesorder; try { using (var transaction = _context.Database.BeginTransaction()) { try { _context.SalesOrder.Add(salesOrder); //await _context.SaveChangesAsync(); foreach (var item in salesorder.SalesOrderLines) { item.SalesOrderId = salesorder.SalesOrderId; _context.SalesOrderLine.Add(item); } await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = salesOrder.SalesOrderId, DocType = "SalesOrder", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(salesorder, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(salesOrder, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = salesOrder.UsuarioCreacion, UsuarioModificacion = salesOrder.UsuarioModificacion, UsuarioEjecucion = salesOrder.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } // this.UpdateSalesOrder(salesOrder.SalesOrderId); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(salesOrder))); }
public async Task <ActionResult <Contrato_plan_pagos> > Update([FromBody] Contrato_plan_pagos _Contrato_plan_pagos) { Contrato_plan_pagos _Contrato_plan_pagosq = _Contrato_plan_pagos; try { using (var transaction = _context.Database.BeginTransaction()) { try { _Contrato_plan_pagosq = await(from c in _context.Contrato_plan_pagos .Where(q => q.Nro_cuota == _Contrato_plan_pagos.Nro_cuota) select c ).FirstOrDefaultAsync(); _context.Entry(_Contrato_plan_pagosq).CurrentValues.SetValues((_Contrato_plan_pagos)); //_context.Contrato_plan_pagos.Update(_Contrato_plan_pagosq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Contrato_plan_pagos.Nro_cuota, DocType = "Contrato_plan_pagos", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Contrato_plan_pagosq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_Contrato_plan_pagos, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _Contrato_plan_pagos.UsuarioCreacion, UsuarioModificacion = _Contrato_plan_pagos.UsuarioModificacion, UsuarioEjecucion = _Contrato_plan_pagos.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } 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(_Contrato_plan_pagosq))); }
public async Task <ActionResult <Employees> > Insert([FromBody] Employees _Employees) { Employees Employees = _Employees; try { using (var transaction = _context.Database.BeginTransaction()) { try { _context.Employees.Add(Employees); //await _context.SaveChangesAsync(); foreach (var item in _Employees._EmployeeSalary) { item.IdEmpleado = _Employees.IdEmpleado; _context.EmployeeSalary.Add(item); } await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = Employees.IdEmpleado, DocType = "Employees", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Employees, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(Employees, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = Employees.Usuariocreacion, UsuarioModificacion = Employees.Usuariomodificacion, UsuarioEjecucion = Employees.Usuariomodificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } // this.UpdateSalesOrder(salesOrder.SalesOrderId); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(Employees))); }
// public async Task<ActionResult<JournalEntry>> Update([FromBody]JournalEntry _JournalEntry) public async Task <ActionResult <JournalEntry> > Update([FromBody] dynamic dto) { //JournalEntry _JournalEntryq = _JournalEntry; JournalEntry _JournalEntry = new JournalEntry(); JournalEntry _JournalEntryq = new JournalEntry(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _JournalEntry = JsonConvert.DeserializeObject <JournalEntry>(dto.ToString()); _JournalEntryq = await(from c in _context.JournalEntry .Where(q => q.JournalEntryId == _JournalEntry.JournalEntryId) select c ).FirstOrDefaultAsync(); _context.Entry(_JournalEntryq).CurrentValues.SetValues((_JournalEntry)); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _JournalEntry.JournalEntryId, DocType = "JournalEntry", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_JournalEntry, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _JournalEntry.CreatedUser, UsuarioModificacion = _JournalEntry.ModifiedUser, UsuarioEjecucion = _JournalEntry.ModifiedUser, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_JournalEntryq))); }
public async Task <IActionResult> Update([FromBody] ControlAsistencias payload) { ControlAsistencias ControlAsistencias = payload; try { using (var transaction = _context.Database.BeginTransaction()) { try { ControlAsistencias = (from c in _context.ControlAsistencias .Where(q => q.Id == payload.Id) select c ).FirstOrDefault(); payload.FechaCreacion = ControlAsistencias.FechaCreacion; payload.UsuarioCreacion = ControlAsistencias.UsuarioCreacion; _context.Entry(ControlAsistencias).CurrentValues.SetValues(payload); // _context.ControlAsistencias.Update(payload); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = ControlAsistencias.Id, DocType = "ControlAsistencias", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(ControlAsistencias, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = ControlAsistencias.UsuarioCreacion, UsuarioModificacion = ControlAsistencias.UsuarioModificacion, UsuarioEjecucion = ControlAsistencias.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(ControlAsistencias))); }
public async Task <ActionResult <Warehouse> > Update([FromBody] Warehouse _Warehouse) { try { using (var transaction = _context.Database.BeginTransaction()) { try { Warehouse warehouseq = (from c in _context.Warehouse .Where(q => q.WarehouseId == _Warehouse.WarehouseId) select c ).FirstOrDefault(); _Warehouse.FechaCreacion = warehouseq.FechaCreacion; _Warehouse.UsuarioCreacion = warehouseq.UsuarioCreacion; _context.Entry(warehouseq).CurrentValues.SetValues((_Warehouse)); // _context.Warehouse.Update(_Warehouse); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Warehouse.WarehouseId, DocType = "Warehouse", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(warehouseq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_Warehouse, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _Warehouse.UsuarioCreacion, UsuarioModificacion = _Warehouse.UsuarioModificacion, UsuarioEjecucion = _Warehouse.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } } } 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(_Warehouse))); }
public async Task <IActionResult> Delete([FromBody] CostCenter _CostCenter) { CostCenter _CostCenterq = new CostCenter(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _CostCenterq = _context.CostCenter .Where(x => x.CostCenterId == (Int64)_CostCenter.CostCenterId) .FirstOrDefault(); _context.CostCenter.Remove(_CostCenterq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _CostCenterq.CostCenterId, DocType = "ContactPerson", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_CostCenterq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_CostCenterq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Eliminar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _CostCenterq.UsuarioCreacion, UsuarioModificacion = _CostCenterq.UsuarioModificacion, UsuarioEjecucion = _CostCenterq.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } 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(_CostCenterq))); }
public async Task <ActionResult <Conciliacion> > Insert([FromBody] Conciliacion _Conciliacion) { try { using (var transaction = _context.Database.BeginTransaction()) { try { foreach (var linea in _Conciliacion.ConciliacionLinea) { if (linea.MotivoId == 0) { linea.MotivoId = null; } linea.VoucherTypeId = null; } _context.Conciliacion.Add(_Conciliacion); //await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Conciliacion.ConciliacionId, DocType = "Conciliacion", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Conciliacion, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _Conciliacion.UsuarioCreacion, UsuarioModificacion = _Conciliacion.UsuarioModificacion, UsuarioEjecucion = _Conciliacion.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_Conciliacion))); }
public async Task <ActionResult <Accounting> > Insert([FromBody] Accounting _Account) { Accounting _Accountq = new Accounting(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _Accountq = _Account; _context.Accounting.Add(_Accountq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Accountq.AccountId, DocType = "Accounting", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Accountq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _Accountq.UsuarioCreacion, UsuarioModificacion = _Accountq.UsuarioModificacion, UsuarioEjecucion = _Accountq.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_Accountq))); /* * return await Task.Run(() => Ok(_ConfigurationVendorq)); */ }
public async Task <ActionResult <PaymentScheduleRulesByCustomer> > Insert([FromBody] PaymentScheduleRulesByCustomer _PaymentScheduleRulesByCustomer) { PaymentScheduleRulesByCustomer _PaymentScheduleRulesByCustomerq = new PaymentScheduleRulesByCustomer(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _PaymentScheduleRulesByCustomerq = _PaymentScheduleRulesByCustomer; Customer _custo = await _context.Customer .Where(q => q.CustomerId == _PaymentScheduleRulesByCustomer.CustomerId).FirstOrDefaultAsync(); _PaymentScheduleRulesByCustomerq.CustomerName = _custo.CustomerName; _context.PaymentScheduleRulesByCustomer.Add(_PaymentScheduleRulesByCustomerq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _PaymentScheduleRulesByCustomerq.PaymentScheduleRulesByCustomerId, DocType = "PaymentScheduleRulesByCustomer", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_PaymentScheduleRulesByCustomerq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _PaymentScheduleRulesByCustomerq.UsuarioCreacion, UsuarioModificacion = _PaymentScheduleRulesByCustomerq.UsuarioModificacion, UsuarioEjecucion = _PaymentScheduleRulesByCustomerq.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _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(_PaymentScheduleRulesByCustomerq))); }
public async Task <ActionResult <SeveridadRiesgo> > Update([FromBody] SeveridadRiesgo _SeveridadRiesgo) { SeveridadRiesgo _SeveridadRiesgoq = _SeveridadRiesgo; try { using (var transaction = _context.Database.BeginTransaction()) { try { _SeveridadRiesgoq = await(from c in _context.SeveridadRiesgo .Where(q => q.IdSeveridad == _SeveridadRiesgo.IdSeveridad) select c ).FirstOrDefaultAsync(); _context.Entry(_SeveridadRiesgoq).CurrentValues.SetValues((_SeveridadRiesgo)); //_context.Bank.Update(_Bankq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _SeveridadRiesgoq.IdSeveridad, DocType = "SeveridadRiesgo", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_SeveridadRiesgoq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _SeveridadRiesgoq.UsuarioCreacion, UsuarioModificacion = _SeveridadRiesgoq.UsuarioModificacion, UsuarioEjecucion = _SeveridadRiesgoq.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_SeveridadRiesgoq))); }
public async Task <ActionResult <Contrato_movimientos> > Insertar_Prima([FromBody] Contrato_movimientos _Contrato_movimientos) { //solo es para verificar el git Contrato_movimientos _Contrato_movimientosq = new Contrato_movimientos(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _Contrato_movimientosq = _Contrato_movimientos; //ASIGNAR TIPO DE MOVIMIENTO A PRIMA _Contrato_movimientosq.Tipo_movimiento = Helpers.Tipo_Movimiento.Prima; _context.Contrato_movimientos.Add(_Contrato_movimientosq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Contrato_movimientos.Contrato_movimientosId, DocType = "Contrato_movimientos", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Contrato_movimientos, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _Contrato_movimientos.UsuarioCreacion, UsuarioModificacion = _Contrato_movimientos.UsuarioModificacion, UsuarioEjecucion = _Contrato_movimientos.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_Contrato_movimientosq))); }
public async Task <ActionResult <ControlPallets> > Insert([FromBody] ControlPallets _ControlPallets) { ControlPallets _ControlPalletsq = new ControlPallets(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _ControlPalletsq = _ControlPallets; _context.ControlPallets.Add(_ControlPalletsq); foreach (var item in _ControlPalletsq._ControlPalletsLine) { item.ControlPalletsId = _ControlPalletsq.ControlPalletsId; _context.ControlPalletsLine.Add(item); } // await _context.SaveChangesAsync(); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _ControlPallets.ControlPalletsId, DocType = "ControlPallets", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_ControlPallets, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _ControlPallets.UsuarioCreacion, UsuarioModificacion = _ControlPallets.UsuarioModificacion, UsuarioEjecucion = _ControlPallets.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); 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(_ControlPalletsq))); }
public async Task <ActionResult <RecipeDetail> > Update([FromBody] RecipeDetail _RecipeDetail) { RecipeDetail _RecipeDetailq = _RecipeDetail; try { using (var transaction = _context.Database.BeginTransaction()) { try { _RecipeDetailq = await(from c in _context.RecipeDetail .Where(x => x.IngredientCode == (Int64)_RecipeDetail.IngredientCode && x.RecipeId == (Int64)_RecipeDetail.RecipeId) select c ).FirstOrDefaultAsync(); _context.Entry(_RecipeDetailq).CurrentValues.SetValues((_RecipeDetail)); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _RecipeDetailq.IngredientCode, DocType = "RecipeDetail", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_RecipeDetailq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _RecipeDetailq.UsuarioCreacion, UsuarioModificacion = _RecipeDetailq.UsuarioModificacion, UsuarioEjecucion = _RecipeDetailq.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_RecipeDetailq))); }
public async Task <IActionResult> Delete([FromBody] ScheduleSubservices _ScheduleSubservices) { ScheduleSubservices _ScheduleSubservicesq = new ScheduleSubservices(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _ScheduleSubservicesq = _context.ScheduleSubservices .Where(x => x.ScheduleSubservicesId == (Int64)_ScheduleSubservices.ScheduleSubservicesId) .FirstOrDefault(); _context.ScheduleSubservices.Remove(_ScheduleSubservicesq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _ScheduleSubservicesq.ScheduleSubservicesId, DocType = "ScheduleSubservices", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_ScheduleSubservicesq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Delete", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _ScheduleSubservicesq.UsuarioCreacion, UsuarioModificacion = _ScheduleSubservicesq.UsuarioModificacion, UsuarioEjecucion = _ScheduleSubservicesq.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _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(_ScheduleSubservicesq))); }
public async Task <ActionResult <State> > Insert([FromBody] State _State) { State _Stateq = new State(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _Stateq = _State; _context.State.Add(_Stateq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Stateq.Id, DocType = "Customer", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Stateq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_State, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, //UsuarioCreacion = _State.UsuarioCreacion, //UsuarioModificacion = _State.UsuarioModificacion, //UsuarioEjecucion = _State.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_Stateq))); }
public async Task <ActionResult <Insurances> > Insert([FromBody] Insurances _Insurances) { Insurances _Insurancesq = new Insurances(); // Alert _Alertq = new Alert(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _Insurancesq = _Insurances; _context.Insurances.Add(_Insurancesq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Insurances.InsurancesId, DocType = "Insurances", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Insurances, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _Insurances.CreatedUser, UsuarioModificacion = _Insurances.ModifiedUser, UsuarioEjecucion = _Insurances.ModifiedUser, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_Insurancesq))); }
public async Task <ActionResult <SeveridadRiesgo> > Insert([FromBody] SeveridadRiesgo _SeveridadRiesgo) { SeveridadRiesgo SeveridadRiesgoq = new SeveridadRiesgo(); try { using (var transaction = _context.Database.BeginTransaction()) { try { SeveridadRiesgoq = _SeveridadRiesgo; _context.SeveridadRiesgo.Add(SeveridadRiesgoq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = SeveridadRiesgoq.IdSeveridad, DocType = "SeveridadRiesgo", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(SeveridadRiesgoq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = SeveridadRiesgoq.UsuarioCreacion, UsuarioModificacion = SeveridadRiesgoq.UsuarioModificacion, UsuarioEjecucion = SeveridadRiesgoq.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(SeveridadRiesgoq))); }
public async Task <ActionResult <BitacoraCierreProcesos> > Insert([FromBody] BitacoraCierreProcesos _BitacoraCierreProcesos) { BitacoraCierreProcesos _BitacoraCierreProcesosq = new BitacoraCierreProcesos(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _BitacoraCierreProcesosq = _BitacoraCierreProcesos; _context.BitacoraCierreProceso.Add(_BitacoraCierreProcesosq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _BitacoraCierreProcesos.IdProceso, DocType = "BitacoraCierreProcesos", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_BitacoraCierreProcesos, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_BitacoraCierreProcesos, 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(_BitacoraCierreProcesosq))); }
public async Task <IActionResult> Update([FromBody] SalesOrder _salesorder) { try { SalesOrder salesOrderq = (from c in _context.SalesOrder .Where(q => q.SalesOrderId == _salesorder.SalesOrderId) select c ).FirstOrDefault(); _salesorder.FechaCreacion = salesOrderq.FechaCreacion; _salesorder.UsuarioCreacion = salesOrderq.UsuarioCreacion; _context.Entry(salesOrderq).CurrentValues.SetValues((_salesorder)); //_context.SalesOrder.Update(_salesorder); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _salesorder.SalesOrderId, DocType = "SalesOrder", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(salesOrderq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_salesorder, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Update", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _salesorder.UsuarioCreacion, UsuarioModificacion = _salesorder.UsuarioModificacion, UsuarioEjecucion = _salesorder.UsuarioModificacion, }); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_salesorder))); }
public async Task <IActionResult> Remove([FromBody] SalesOrder payload) { try { SalesOrder salesOrder = _context.SalesOrder .Where(x => x.SalesOrderId == (int)payload.SalesOrderId) .FirstOrDefault(); _context.SalesOrder.Remove(salesOrder); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = payload.SalesOrderId, DocType = "SalesOrder", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(payload, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(salesOrder, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Update", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = payload.UsuarioCreacion, UsuarioModificacion = payload.UsuarioModificacion, UsuarioEjecucion = payload.UsuarioModificacion, }); await _context.SaveChangesAsync(); return(Ok(salesOrder)); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } }
public async Task <ActionResult <GoodsDelivered> > Insert([FromBody] GoodsDeliveredDTO _GoodsDelivered) { GoodsDelivered _GoodsDeliveredq = new GoodsDelivered(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _GoodsDeliveredq = _GoodsDelivered; BoletaDeSalida _boletadesalida = new BoletaDeSalida { BranchId = _GoodsDelivered.BranchId, BranchName = _GoodsDelivered.BranchName, CustomerId = _GoodsDelivered.CustomerId, CustomerName = _GoodsDelivered.CustomerName, DocumentDate = _GoodsDelivered.DocumentDate, FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, Marca = _GoodsDelivered.Marca, Placa = _GoodsDelivered.Placa, Motorista = _GoodsDelivered.Name, Quantity = _GoodsDelivered._GoodsDeliveredLine.Select(q => q.QuantitySacos).Sum(), SubProductId = _GoodsDelivered.SubProductId, SubProductName = _GoodsDelivered.SubProductName, GoodsDeliveryAuthorizationId = _GoodsDelivered.GoodsDeliveryAuthorizationId, GoodsDeliveredId = _GoodsDeliveredq.GoodsDeliveredId, CargadoId = 13, Cargadoname = "Cargado", UsuarioCreacion = _GoodsDelivered.UsuarioCreacion, UsuarioModificacion = _GoodsDelivered.UsuarioModificacion, UnitOfMeasureId = _GoodsDelivered._GoodsDeliveredLine[0].UnitOfMeasureId, UnitOfMeasureName = _GoodsDelivered._GoodsDeliveredLine[0].UnitOfMeasureName, WeightBallot = _GoodsDelivered.WeightBallot, }; _context.BoletaDeSalida.Add(_boletadesalida); await _context.SaveChangesAsync(); _GoodsDeliveredq.ExitTicket = _boletadesalida.BoletaDeSalidaId; _context.GoodsDelivered.Add(_GoodsDeliveredq); foreach (var item in _GoodsDeliveredq._GoodsDeliveredLine) { item.GoodsDeliveredId = _GoodsDeliveredq.GoodsDeliveredId; _context.GoodsDeliveredLine.Add(item); Kardex _kardexmax = await(from c in _context.Kardex .OrderByDescending(q => q.DocumentDate) // .Take(1) join d in _context.KardexLine on c.KardexId equals d.KardexId where c.CustomerId == _GoodsDeliveredq.CustomerId && d.SubProducId == item.SubProductId && c.DocumentName != "CD" && d.WareHouseId == item.WareHouseId select c ) .FirstOrDefaultAsync(); if (_kardexmax == null) { _kardexmax = new Kardex(); } KardexLine _KardexLine = await _context.KardexLine .Where(q => q.KardexId == _kardexmax.KardexId) .Where(q => q.SubProducId == item.SubProductId) .Where(q => q.WareHouseId == item.WareHouseId) .Where(q => q.BranchId == _GoodsDeliveredq.BranchId) .OrderByDescending(q => q.KardexLineId) .Take(1) .FirstOrDefaultAsync(); SubProduct _subproduct = await(from c in _context.SubProduct .Where(q => q.SubproductId == item.SubProductId) select c ).FirstOrDefaultAsync(); if (_KardexLine.Total > item.Quantity) { item.Total = _KardexLine.TotalCD - item.Quantity; } else { return(await Task.Run(() => BadRequest("Inventario insuficiente!"))); } _GoodsDelivered.Kardex._KardexLine.Add(new KardexLine { DocumentDate = _GoodsDeliveredq.DocumentDate, ProducId = _GoodsDeliveredq.ProductId, ProductName = _GoodsDeliveredq.ProductName, SubProducId = item.SubProductId, SubProductName = item.SubProductName, QuantityEntry = 0, QuantityOut = item.Quantity, BranchId = _GoodsDeliveredq.BranchId, BranchName = _GoodsDeliveredq.BranchName, WareHouseId = item.WareHouseId, WareHouseName = item.WareHouseName, UnitOfMeasureId = item.UnitOfMeasureId, UnitOfMeasureName = item.UnitOfMeasureName, TypeOperationId = 1, TypeOperationName = "Salida", Total = item.Total, TotalBags = _KardexLine.TotalBags - item.QuantitySacos, QuantityOutCD = item.Quantity - (item.Quantity * _subproduct.Merma), TotalCD = _KardexLine.TotalCD - (item.Quantity - (item.Quantity * _subproduct.Merma)), }); } await _context.SaveChangesAsync(); _GoodsDelivered.Kardex.DocType = 0; _GoodsDelivered.Kardex.DocName = "EntregaMercaderia/GoodsDelivered"; _GoodsDelivered.Kardex.DocumentDate = _GoodsDeliveredq.DocumentDate; _GoodsDelivered.Kardex.FechaCreacion = DateTime.Now; _GoodsDelivered.Kardex.FechaModificacion = DateTime.Now; _GoodsDelivered.Kardex.TypeOperationId = 1; _GoodsDelivered.Kardex.TypeOperationName = "Salida"; _GoodsDelivered.Kardex.KardexDate = DateTime.Now; _GoodsDelivered.Kardex.DocumentName = "CE"; _GoodsDelivered.Kardex.CustomerId = _GoodsDeliveredq.CustomerId; _GoodsDelivered.Kardex.CustomerName = _GoodsDeliveredq.CustomerName; _GoodsDelivered.Kardex.CurrencyId = _GoodsDeliveredq.CurrencyId; _GoodsDelivered.Kardex.CurrencyName = _GoodsDeliveredq.CurrencyName; _GoodsDelivered.Kardex.DocumentId = _GoodsDeliveredq.GoodsDeliveredId; _GoodsDelivered.Kardex.UsuarioCreacion = _GoodsDeliveredq.UsuarioCreacion; _GoodsDelivered.Kardex.UsuarioModificacion = _GoodsDeliveredq.UsuarioModificacion; _context.Kardex.Add(_GoodsDelivered.Kardex); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _GoodsDelivered.GoodsDeliveredId, DocType = "GoodsDelivered", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_GoodsDelivered, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_GoodsDelivered, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _GoodsDelivered.UsuarioCreacion, UsuarioModificacion = _GoodsDelivered.UsuarioModificacion, UsuarioEjecucion = _GoodsDelivered.UsuarioModificacion, }); await _context.SaveChangesAsync(); _boletadesalida.GoodsDeliveredId = _GoodsDeliveredq.GoodsDeliveredId; _context.Entry(_boletadesalida).CurrentValues.SetValues((_boletadesalida)); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); 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(_GoodsDeliveredq))); }
public async Task <ActionResult <ApplicationUser> > CambiarPasswordPoliticas([FromBody] UserInfo model) { try { ApplicationUser ApplicationUserq = _context.Users.Where(q => q.Email == model.Email).FirstOrDefault(); //string password = ApplicationUserq.PasswordHash; var passwordValidator = new PasswordValidator <ApplicationUser>(); //_userManager.Options.Password.RequireDigit = true; //_userManager.Options.Password.RequiredLength = Convert.ToInt32(_context.ElementoConfiguracion.Where(w => w.Id == 21).FirstOrDefault().Valordecimal); var resultvalidador = await passwordValidator.ValidateAsync(_userManager, null, model.Password); if (resultvalidador.Succeeded) { //Verifica en los historicos //var validarhistoricos = _context.PasswordHistory.Where(w => w.UserId == ApplicationUserq.Id.ToString() & w.CreatedDate >= DateTime.Now.AddMonths(-6)).ToList(); //if (validarhistoricos != null) //{ // foreach (var item in validarhistoricos) // { // PasswordVerificationResult passwordMatch = _userManager.PasswordHasher.VerifyHashedPassword(ApplicationUserq, item.PasswordHash, model.Password); // if (passwordMatch == PasswordVerificationResult.Success) // { // return await Task.Run(() => BadRequest(@"Error Ya ha utilizado esta contraseña")); // } // } //} ApplicationUserq.LastPasswordChangedDate = ApplicationUserq.LastPasswordChangedDate = DateTime.Now; var result = await _userManager.ChangePasswordAsync(ApplicationUserq, model.PasswordAnterior, model.Password); if (result.Succeeded) { _context.PasswordHistory.Add(new PasswordHistory() { UserId = ApplicationUserq.Id.ToString(), PasswordHash = ApplicationUserq.PasswordHash, }); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { // IdOperacion =, Descripcion = ApplicationUserq.Id.ToString(), DocType = "Usuario", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(ApplicationUserq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(ApplicationUserq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "ChangePassword", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = ApplicationUserq.UsuarioCreacion, UsuarioModificacion = ApplicationUserq.UsuarioModificacion, UsuarioEjecucion = ApplicationUserq.UsuarioModificacion, }); //await _context.SaveChangesAsync(); await _context.SaveChangesAsync(); return(await Task.Run(() => Ok(ApplicationUserq))); } else { return(await Task.Run(() => BadRequest(@"Contraseña o usuario incorrecto"))); } } else { string errores = "La Contraseña "; foreach (var item in resultvalidador.Errors) { switch (item.Code) { case ("PasswordTooShort"): errores += "es muy corta, "; break; case ("PasswordRequiresUniqueChars"): errores += "requiere caracteres unicos, "; break; case ("PasswordRequiresNonAlphanumeric"): errores += "requiere caracteres alfanumericos, "; break; case ("PasswordRequiresDigit"): errores += "requiere caracteres numeros, "; break; case ("PasswordRequiresLower"): errores += "requiere minúsculas, "; break; case ("PasswordRequiresUppe"): errores += "requiere mayúsculas, "; break; } } return(await Task.Run(() => BadRequest($"{errores}"))); //return await Task.Run(() => BadRequest($" El password debe tener mayusculas, minusculas y caracteres especiales!")); } } catch (Exception ex) { // ILogger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error: {ex.Message}"))); } }
public async Task <ActionResult <PurchaseOrder> > InsertWithInventory([FromBody] PurchaseOrderDTO _PurchaseOrders) { PurchaseOrder _PurchaseOrdersq = new PurchaseOrder(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _context.PurchaseOrder.Add(_PurchaseOrders); // await _context.SaveChangesAsync(); foreach (var item in _PurchaseOrders.PurchaseOrderLines) { item.Id = _PurchaseOrders.Id; _context.PurchaseOrderLine.Add(item); Kardex _kardexmax = await(from c in _context.Kardex .OrderByDescending(q => q.DocumentDate) // .Take(1) join d in _context.KardexLine on c.KardexId equals d.KardexId where d.ProducId == item.ProductId select c ) .FirstOrDefaultAsync(); if (_kardexmax == null) { _kardexmax = new Kardex(); } KardexLine _KardexLine = await _context.KardexLine .Where(q => q.KardexId == _kardexmax.KardexId) .Where(q => q.ProducId == item.ProductId) //.Where(q => q.WareHouseId == item.WareHouseId) //.Where(q => q.BranchId == _GoodsDeliveredq.BranchId) .OrderByDescending(q => q.KardexLineId) .Take(1) .FirstOrDefaultAsync(); Product _subproduct = await(from c in _context.Product .Where(q => q.ProductId == item.ProductId) select c ).FirstOrDefaultAsync(); item.QtyReceivedToDate = _KardexLine.Total + item.QtyReceived; _PurchaseOrders.Kardex._KardexLine.Add(new KardexLine { DocumentDate = _PurchaseOrders.DatePlaced, ProducId = Convert.ToInt64(item.ProductId), ProductName = item.ProductDescription, SubProducId = 0, SubProductName = "N/A", QuantityEntry = Convert.ToDouble(item.QtyReceived), QuantityOut = 0, BranchId = Convert.ToInt64(_PurchaseOrders.BranchId), //BranchName = _PurchaseOrders.Branch.BranchName, WareHouseId = 0, WareHouseName = "N/A", UnitOfMeasureId = item.UnitOfMeasureId, UnitOfMeasureName = item.UnitOfMeasureName, TypeOperationId = 1, TypeOperationName = "Orden de Compra", Total = Convert.ToDouble(item.QtyReceivedToDate), // TotalBags = item.QuantitySacos - _KardexLine.TotalBags, //QuantityOutCD = item.Quantity - (item.Quantity * _subproduct.Merma), //TotalCD = _KardexLine.TotalCD - (item.Quantity - (item.Quantity * _subproduct.Merma)), }); } await _context.SaveChangesAsync(); _PurchaseOrders.Kardex.DocType = 0; _PurchaseOrders.Kardex.DocName = "FacturaProforma/PurchaseOrders"; _PurchaseOrders.Kardex.DocumentDate = _PurchaseOrders.DatePlaced; _PurchaseOrders.Kardex.FechaCreacion = DateTime.Now; _PurchaseOrders.Kardex.FechaModificacion = DateTime.Now; _PurchaseOrders.Kardex.TypeOperationId = 1; _PurchaseOrders.Kardex.TypeOperationName = "Salida"; _PurchaseOrders.Kardex.KardexDate = DateTime.Now; _PurchaseOrders.Kardex.DocumentName = "FacturaProforma"; _PurchaseOrders.Kardex.CustomerId = 0; _PurchaseOrders.Kardex.CustomerName = "N/A"; _PurchaseOrders.Kardex.CurrencyId = Convert.ToInt32(_PurchaseOrders.CurrencyId); _PurchaseOrders.Kardex.CurrencyName = _PurchaseOrders.CurrencyName; _PurchaseOrders.Kardex.DocumentId = _PurchaseOrders.Id; _PurchaseOrders.Kardex.UsuarioCreacion = _PurchaseOrders.UsuarioCreacion; _PurchaseOrders.Kardex.UsuarioModificacion = _PurchaseOrders.UsuarioModificacion; _context.Kardex.Add(_PurchaseOrders.Kardex); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _PurchaseOrders.VendorId, DocType = "PurchaseOrders", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_PurchaseOrders, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_PurchaseOrders, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _PurchaseOrders.UsuarioCreacion, UsuarioModificacion = _PurchaseOrders.UsuarioModificacion, UsuarioEjecucion = _PurchaseOrders.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } //_PurchaseOrdersq = _PurchaseOrders; //_context.PurchaseOrders.Add(_PurchaseOrdersq); //await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_PurchaseOrdersq))); }
public async Task <ActionResult <EmployeeSalary> > Update([FromBody] EmployeeSalary _EmployeeSalary) { EmployeeSalary _EmployeeSalaryq = _EmployeeSalary; try { using (var transaction = _context.Database.BeginTransaction()) { try { _EmployeeSalaryq = await(from c in _context.EmployeeSalary .Where(q => q.EmployeeSalaryId == _EmployeeSalary.EmployeeSalaryId) select c ).FirstOrDefaultAsync(); _context.Entry(_EmployeeSalaryq).CurrentValues.SetValues((_EmployeeSalary)); //_context.Alert.Update(_Alertq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _EmployeeSalary.EmployeeSalaryId, DocType = "EmployeeSalary", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_EmployeeSalaryq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_EmployeeSalary, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _EmployeeSalary.CreatedUser, UsuarioModificacion = _EmployeeSalary.ModifiedUser, UsuarioEjecucion = _EmployeeSalary.ModifiedUser, }); //await _context.SaveChangesAsync(); if (_EmployeeSalary.IdEstado == 1) { Employees _Employee = new Employees(); _Employee = await _context.Employees.Where(q => q.IdEmpleado == _EmployeeSalary.IdEmpleado).FirstOrDefaultAsync(); var Salario = _EmployeeSalary.QtySalary; _Employee.Salario = Salario; _context.Entry(_Employee).CurrentValues.SetValues((_Employee)); //_context.Alert.Update(_Alertq); //await _context.SaveChangesAsync(); BitacoraWrite _writeejec = new BitacoraWrite(_context, new Bitacora { IdOperacion = _EmployeeSalary.EmployeeSalaryId, DocType = "Employeed", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_EmployeeSalaryq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_EmployeeSalary, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _EmployeeSalary.CreatedUser, UsuarioModificacion = _EmployeeSalary.ModifiedUser, UsuarioEjecucion = _EmployeeSalary.ModifiedUser, }); } await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } 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(_EmployeeSalaryq))); }
public async Task <ActionResult <EmployeeSalary> > Insert([FromBody] EmployeeSalary _EmployeeSalary) { EmployeeSalary _EmployeeSalaryq = new EmployeeSalary(); Alert _Alertq = new Alert(); string employeeName = _context.Employees.Where(e => e.IdEmpleado == _EmployeeSalary.IdEmpleado).FirstOrDefault().NombreEmpleado; try { using (var transaction = _context.Database.BeginTransaction()) { try { _EmployeeSalaryq = _EmployeeSalary; _context.EmployeeSalary.Add(_EmployeeSalaryq); //////////////Alerta al guardar un nuevo Salario///////////// _Alertq.AlertName = "Cambio de Salario"; _Alertq.DocumentName = "EMPLEADO"; _Alertq.Code = "PERSON005"; _Alertq.FechaCreacion = DateTime.Now; _Alertq.FechaModificacion = DateTime.Now; _Alertq.UsuarioCreacion = _EmployeeSalary.CreatedUser; _Alertq.UsuarioModificacion = _EmployeeSalary.ModifiedUser; _Alertq.AlertType = "PERSONA"; _Alertq.Description = "Se Modifico el Salario al Empleado: " + employeeName; _context.Alert.Add(_Alertq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _EmployeeSalary.EmployeeSalaryId, DocType = "EmployeeSalary", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_EmployeeSalary, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insertar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _EmployeeSalary.CreatedUser, UsuarioModificacion = _EmployeeSalary.ModifiedUser, UsuarioEjecucion = _EmployeeSalary.ModifiedUser, }); List <EmployeeSalary> _EmployeeSalaryU = new List <EmployeeSalary>(); _EmployeeSalaryU = await(from c in _context.EmployeeSalary .Where(q => q.IdEmpleado == _EmployeeSalary.IdEmpleado && q.EmployeeSalaryId != _EmployeeSalary.EmployeeSalaryId) select c).ToListAsync(); //_EmployeeSalaryU = await _context.EmployeeSalary.Where(q => q.IdEmpleado == _EmployeeSalary.IdEmpleado && q.EmployeeSalaryId != _EmployeeSalary.EmployeeSalaryId).FirstOrDefaultAsync(); foreach (EmployeeSalary p in _EmployeeSalaryU) { p.IdEstado = 2; _context.Entry(p).CurrentValues.SetValues((p)); } Employees _Employee = new Employees(); _Employee = await _context.Employees.Where(q => q.IdEmpleado == _EmployeeSalary.IdEmpleado).FirstOrDefaultAsync(); var Salario = _EmployeeSalary.QtySalary; _Employee.Salario = Salario; _context.Entry(_Employee).CurrentValues.SetValues((_Employee)); //await _context.SaveChangesAsync(); //_Employee = await (from c in _context.Employees // .Where(q => q.IdEmpleado == _EmployeeSalary.IdEmpleado) // select c // ).FirstOrDefaultAsync(); //_context.Alert.Update(_Alertq); //await _context.SaveChangesAsync(); BitacoraWrite _writeejec = new BitacoraWrite(_context, new Bitacora { IdOperacion = _EmployeeSalary.EmployeeSalaryId, DocType = "Employeed", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_EmployeeSalaryq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_EmployeeSalary, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Actualizar", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _EmployeeSalary.CreatedUser, UsuarioModificacion = _EmployeeSalary.ModifiedUser, UsuarioEjecucion = _EmployeeSalary.ModifiedUser, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; // return BadRequest($"Ocurrio un error:{ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_EmployeeSalaryq))); }