0

I am trying to write logs to the table. - Actions that are performed in sequence

but unfortunately I ran into an error


        [HttpGet(nameof(SendEmailToManagers))]
        public async Task<ActionResult> SendEmailToManagers()
        {
            //LOG: Start
            InsertLogs("System", "Start");
            //LOG: Pobieram managerów do wysyłki 
            InsertLogs("System", "Pobieram managerów do wysyłki");
            var listOfManagers = _ecpContext.Akceptacje_UnionAll_V
                .Where(f => f.DoAkceptacji == 1)
                .Where(f => f.ManagerADLogin != null)
                .Select(f => f.ManagerADLogin)
                .Distinct()
                .ToList();

            //LOG: Pobieram wyjątki
            InsertLogs("System", "Pobieram wyjątki");
            var notsException =  _emailContext
                .NotsExceptionsManager
                .Select(f => f.ADLogin)
                .Distinct()
                .ToList();


            //LOG: Except
            InsertLogs("System", "Except");
            var listOfManagersAfterExcept = listOfManagers.Except(notsException).ToList();

}
  [HttpGet]
        public async Task<ActionResult> InsertLogs(string ADLogin, string Details)
        {
            //List<Log> objModel = new List<Log>();
            var model = new Log()
            {
                Details = Details,
                ADLogin = ADLogin
            };
            //objModel.Add(model);

            //await _ecpContext.Log.AddRangeAsync(objModel);
             await _ecpContext.Log.AddRangeAsync(model);
             await _ecpContext.SaveChangesAsync();

            return Ok();
        }

error

InvalidOperationException: A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913.

0 Answers0