public async Task <ActionResult <SubServicesWareHouse> > Update([FromBody] SubServicesWareHouse _SubServicesWareHouse) { SubServicesWareHouse _SubServicesWareHouseq = _SubServicesWareHouse; try { using (var transaction = _context.Database.BeginTransaction()) { try { _SubServicesWareHouseq = await(from c in _context.SubServicesWareHouse .Where(q => q.SubServicesWareHouseId == _SubServicesWareHouse.SubServicesWareHouseId) select c ).FirstOrDefaultAsync(); _context.Entry(_SubServicesWareHouseq).CurrentValues.SetValues((_SubServicesWareHouse)); //_context.SubServicesWareHouse.Update(_SubServicesWareHouseq); await _context.SaveChangesAsync(); BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _SubServicesWareHouseq.SubServicesWareHouseId, DocType = "SubServicesWareHouse", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_SubServicesWareHouseq, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Update", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _SubServicesWareHouseq.UsuarioCreacion, UsuarioModificacion = _SubServicesWareHouseq.UsuarioModificacion, UsuarioEjecucion = _SubServicesWareHouseq.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(_SubServicesWareHouseq))); }
public async Task <IActionResult> GetSubServicesWareHouseById(Int64 SubServicesWareHouseId) { SubServicesWareHouse Items = new SubServicesWareHouse(); try { Items = await _context.SubServicesWareHouse.Where(q => q.SubServicesWareHouseId == SubServicesWareHouseId).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))); }