public async Task <int?> InsertNewDepartmentRole(DepartmentRole departmentRole) { try { await _dbContext.DepartmentRoles.AddAsync(departmentRole); var result = await _dbContext.SaveChangesAsync(); return(result == 0 ? -1 : departmentRole.Id); } catch (DbUpdateException e) { await _coreLogService.InsertRoutinizeCoreLog(new RoutinizeCoreLog { Location = $"{ nameof(DepartmentRoleService) }.{ nameof(InsertNewDepartmentRole) }", Caller = $"{ new StackTrace().GetFrame(4)?.GetMethod()?.DeclaringType?.FullName }", BriefInformation = nameof(DbUpdateException), DetailedInformation = $"Error while inserting entry to DepartmentRoles.\n\n{ e.StackTrace }", ParamData = $"{ nameof(departmentRole) } = { JsonConvert.SerializeObject(departmentRole) }", Severity = SharedEnums.LogSeverity.High.GetEnumValue() }); return(null); } }
/// <summary> /// Use in a combination with SetChangesToDbContext. /// </summary> protected async Task <bool?> CommitChanges() { try { return((await _dbContext.SaveChangesAsync()) != 0); } catch (DbUpdateException e) { await _coreLogService.InsertRoutinizeCoreLog(new RoutinizeCoreLog { Location = $"{ nameof(DbServiceBase) }.{ nameof(CommitChanges) }", Caller = $"{ new StackTrace().GetFrame(4)?.GetMethod()?.DeclaringType?.FullName }", BriefInformation = nameof(DbUpdateException), DetailedInformation = $"Error while saving bulk changes to DbContext.\n\n{ e.StackTrace }", Severity = SharedEnums.LogSeverity.High.GetEnumValue() }); return(false); } }