public Person[] Select() { var persons = _DBContext.Person.ToList(); _Logger.LogInformation(LogConst.GotEntireTable(nameof(_DBContext.Person))); return(persons.ToArray()); }
public string Delete(int id) { if (id < 0) { _Logger.LogError(LogConst.IdIsNegative); throw new ArgumentException(LogConst.IdIsNegative); } var person = _DBContext.Person.FirstOrDefault(p => p.Id == id); if (person != null) { try { _DBContext.Person.Remove(person); _DBContext.SaveChanges(); _Logger.LogInformation(LogConst.ElementDeleted(id, nameof(_DBContext.Person))); return("Элемент успешно удален"); } catch (Exception ex) { _Logger.LogError(ex, LogConst.ElementNotDeleted(id, nameof(_DBContext.Person))); return("Произошла ошибка при удалении из бд"); } } else { _Logger.LogInformation(LogConst.ElementNotFound(id, nameof(_DBContext.Person))); return("Элемент не найден"); } }
public Contact[] Select() { var x = _DBContext.Contact; var contacts = _DBContext.Contact.ToList(); _Logger.LogInformation(LogConst.GotEntireTable(nameof(_DBContext.Contact))); return(contacts.ToArray()); }
public Person Select(int id) { if (id < 0) { _Logger.LogError(LogConst.IdIsNegative); throw new ArgumentException(LogConst.IdIsNegative); } var person = _DBContext.Person.FirstOrDefault(p => p.Id == id); if (person == null) { _Logger.LogInformation(LogConst.ElementNotFound(id, nameof(_DBContext.Person))); } _Logger.LogInformation(LogConst.ElementIsFound(id, nameof(_DBContext.Person))); return(person); }
private static void BuildActionProcess(IBuildAction buildAction, IBuildSession buildSession) { using (Log.NamedBlock(LogLevel.Info, () => LogConst.BuildAction_Process(buildAction))) try { buildAction.Process(buildSession); } catch (Exception exception) { if (!exception.Data.Contains(ExceptionConst.Logged)) { using (Log.NamedBlock(LogLevel.Info, () => $"{LogConst.BuildAction_Process(buildAction)}.Exception: ")) exception.WriteToLog(); } throw; } }
private static void BuildActionPostProcess(IBuildAction buildAction, IBuildSession buildSession) { using (Log.NamedBlock(LogLevel.Info, () => LogConst.BuildAction_PostProcess(buildAction))) { Log.WriteLine(LogLevel.Verbose, () => $"Build.Result = {buildSession.BuildResult.ToLogString()}"); try { buildAction.PostProcess(buildSession); } catch (Exception exc) { using (Log.NamedBlock(LogLevel.Info, () => $"{LogConst.BuildAction_PostProcess(buildAction)}.Exception: ")) exc.WriteToLog(); throw; } } }
public string InsertOrUpdate(Person pers) { if (pers == null) { _Logger.LogError(LogConst.ParamCannotBeNull("Person")); throw new ArgumentException(LogConst.ParamCannotBeNull("Person")); } var person = _DBContext.Person.FirstOrDefault(p => p.Id == pers.Id); if (person == null) { try { _DBContext.Person.Add(pers); _DBContext.SaveChanges(); _Logger.LogInformation(LogConst.AddedElement(nameof(_DBContext.Person))); return("Элемент добавлен в БД"); } catch (Exception ex) { _Logger.LogError(ex, LogConst.ElementNotAdded(nameof(_DBContext.Person))); return("Произошла ошибка при добавении в бд"); } } else { try { person.Name = pers.Name; _DBContext.Person.Update(person); _DBContext.SaveChanges(); _Logger.LogInformation(LogConst.ElementUpdated(pers.Id, nameof(_DBContext.Person))); return("Элемент обновлен"); } catch (Exception ex) { _Logger.LogError(LogConst.ElementNotUpdated(pers.Id, nameof(_DBContext.Person))); return("Произошла ошибка при обновлении бд"); } } }
public ArmatureException(string message, Exception innerException) : base(message + LogConst.ArmatureExceptionPostfix(), innerException) { }
public ArmatureException(string message) : base(message + LogConst.ArmatureExceptionPostfix()) { }
public ArmatureException() : base(LogConst.ArmatureExceptionPostfix()) { }