public async Task <IActionResult> Delete([FromBody] sdnListM payload) { try { List <sdnListM> rangelist = _context.sdnList.ToList(); _context.sdnList.RemoveRange(rangelist); // _context.Database.ExecuteSqlCommand("TRUNCATE TABLE [TableName]"); await _context.SaveChangesAsync(); return(await Task.Run(() => Ok(rangelist.Count))); // return Ok(customerType); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error: { ex.Message }"))); } }
public async Task <IActionResult> Insert([FromBody] sdnListM payload) { try { using (var transaction = _context.Database.BeginTransaction()) { try { sdnListM customerType = payload; _context.Database.SetCommandTimeout(TimeSpan.FromMinutes(70)); // List<sdnListPublshInformationM> _publis = new List<sdnListPublshInformationM>(); // _publis.Add( customerType.publshInformation); //_context.BulkInsert(_publis); // _context.BulkInsert(customerType.sdnEntry); List <sdnListM> rangelist = _context.sdnList.ToList(); _context.sdnList.RemoveRange(rangelist); // _context.Database.ExecuteSqlCommand("TRUNCATE TABLE [TableName]"); await _context.SaveChangesAsync(); _context.sdnList.Add(customerType); await _context.SaveChangesAsync(); transaction.Commit(); return(await Task.Run(() => Ok(customerType))); } catch (Exception ex) { transaction.Rollback(); throw ex; } } // return Ok(customerType); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error: { ex.Message }"))); } }