static void LogException2Db(LogEntry lg) { try { LogEntry log = new LogEntry() { ErrorCode = lg.ErrorCode, LogTime = lg.LogTime, Message = lg.Message, StackTrace = lg.StackTrace, Title = lg.Title }; if (lg.UserId > 0) { log.UserId = lg.UserId; } using (FileStoreModel db = new FileStoreModel()) { db.LogEntries.Add(log); db.SaveChanges(); } } catch (Exception ex) { LogException2File(lg); LogException2File(ex); } }
internal bool DeleteFile(int fileId) { bool result = false; try { using (FileStoreModel db = new FileStoreModel()) { PersonalFile pf = db.PersonalFiles.Find(fileId); if (pf != null) { pf.IsActive = false; db.Entry(pf).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } LogManager.LogTransaction("PersonalFile", AppVariables.UserId, fileId, TransactionTypes.Delete); result = true; } catch (Exception ex) { result = false; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "DeleteFile"); } return(result); }
internal FileContentModel GetFileById(int fileId) { FileContentModel result = new FileContentModel(); try { using (FileStoreModel db = new FileStoreModel()) { result = (from p in db.PersonalFiles where p.IsActive == true && p.Id == fileId select new FileContentModel { Id = fileId, FileName = p.FileName, Content = p.FileContent }).FirstOrDefault <FileContentModel>(); } if (result == null) { result = new FileContentModel(); } if (result.Content == null) { result.Content = new byte[] { }; } } catch (Exception ex) { result = null; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "GetFileById"); } return(result); }
internal User Login(LoginModel model) { User result = null; try { using (FileStoreModel db = new FileStoreModel()) { result = (from u in db.Users where (string.Equals(u.UserName, model.UserName) && string.Equals(u.Pass, model.Pass) && u.IsActive == true) select u).FirstOrDefault <User>(); } if (result != null) { result.Pass = string.Empty; if (result.Id == 0) { result = null; } } } catch (Exception ex) { result = null; LogManager.LogException(ex, AppVariables.UserId, "UserManager", "Login"); } return(result); }
public void Save(FileStoreModel fileStoreModel) { _fileStore = fileStoreModel; var json = JsonConvert.SerializeObject(_fileStore); File.WriteAllText(FileStorePath, json); }
public void Update(IList <DepositWithdrawlModel> depositWithdrawls) { var fileStore = new FileStoreModel { DepositWithdrawls = depositWithdrawls.ToList(), Exchanges = ExchangesService.Instance.GetAll().ToList() }; FileStoreService.Instance.Save(fileStore); }
public FileStoreModel Load() { if (_fileStore == null && HasSaves()) { var fileContent = File.ReadAllText(FileStorePath); _fileStore = JsonConvert.DeserializeObject <FileStoreModel>(fileContent); } return(_fileStore); }
/// <summary> /// Logs Transaction to Db. /// </summary> /// <param name="tableName"></param> /// <param name="entityId"></param> /// <param name="transactionType"></param> public void LogTransaction(string tableName, int entityId, string transactionType) { try { TransactionLog transLog = new TransactionLog() { LogTime = DateTime.Now, TableName = tableName, EntityId = entityId, TransactionType = transactionType }; using (FileStoreModel db = new FileStoreModel()) { db.TransactionLogs.Add(transLog); db.SaveChanges(); } } catch (DbEntityValidationException dex) { LogException2File(new LogEntry { LogTime = DateTime.Now, Title = "DbEntity", ErrorCode = "Validation_Error", Message = dex.Message, StackTrace = dex.StackTrace }); foreach (DbEntityValidationResult error in dex.EntityValidationErrors) { foreach (DbValidationError validationError in error.ValidationErrors) { LogException2File(new LogEntry { LogTime = DateTime.Now, Title = validationError.PropertyName, ErrorCode = validationError.ErrorMessage }); } } } catch (Exception exc) { LogException2File(exc); } }
internal bool AddFile(PersonalFile file) { bool result = false; try { using (FileStoreModel db = new FileStoreModel()) { db.PersonalFiles.Add(file); db.SaveChanges(); } LogManager.LogTransaction("PersonalFile", AppVariables.UserId, file.Id, TransactionTypes.Insert); result = true; } catch (Exception ex) { result = false; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "AddFile"); } return(result); }
internal bool UpdateFile(PersonalFile file) { bool result = false; try { if (file != null) { using (FileStoreModel db = new FileStoreModel()) { PersonalFile pf = null; pf = db.PersonalFiles.Find(file.Id); if (pf != null) { pf.FileName = file.FileName; pf.FileContent = file.FileContent; db.Entry(pf).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); result = true; } } } if (result) { LogManager.LogTransaction("PersonalFile", AppVariables.UserId, file.Id, TransactionTypes.Update); } } catch (Exception ex) { result = false; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "UpdateFile"); } return(result); }
// private FileStoreModel db = new FileStoreModel(); #endregion [ Private Fields ] #region [ Files method ] internal List <FileModel> Files() { List <FileModel> result = new List <FileModel>(); try { using (FileStoreModel db = new FileStoreModel()) { result = (from p in db.PersonalFiles join u in db.Users on p.CreatedBy equals u.Id where p.IsActive == true select new FileModel { Id = p.Id, FileName = p.FileName, CreationDate = p.CreationDate, CreatedUser = u.FirstName + " " + u.LastName, //CreatedUser = p.User == null ? "NULL" : string.Format("{0} {1}", p.User.FirstName, p.User.LastName), CreatedBy = p.CreatedBy }).ToList <FileModel>(); } if (result == null) { result = new List <FileModel>(); } result = result.OrderByDescending(r => r.CreationDate).ToList <FileModel>(); } catch (Exception ex) { result = null; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "Files"); } return(result); }
public static void LogException(Exception ex, int userId, string className, string methodName) { LogEntry log = null; try { if (ex is DbEntityValidationException) { DbEntityValidationException dex = ex as DbEntityValidationException; foreach (DbEntityValidationResult error in dex.EntityValidationErrors) { foreach (DbValidationError validationError in error.ValidationErrors) { log = new LogEntry { LogTime = DateTime.Now, Title = validationError.PropertyName, Message = validationError.ErrorMessage, ErrorCode = string.Format("ERR_{0}_{1}", className, methodName) }; if (userId > 0) { log.UserId = userId; } LogException2Db(log); } } } else { log = new LogEntry() { LogTime = DateTime.Now, ErrorCode = string.Format("ERR_{0}_{1}", className, methodName), Title = string.Format("An Exception handled at {1} method in {0}.", className, methodName) }; if (userId > 0) { log.UserId = userId; } if (ex != null) { log.Message = ex.Message; log.StackTrace = ex.StackTrace; } using (FileStoreModel db = new FileStoreModel()) { db.LogEntries.Add(log); db.SaveChanges(); } } } catch (DbEntityValidationException dex) { try { log = new LogEntry { LogTime = DateTime.Now, Title = "DbEntity", ErrorCode = "Validation_Error", Message = dex.Message, StackTrace = dex.StackTrace }; LogException2File(log); foreach (DbEntityValidationResult error in dex.EntityValidationErrors) { foreach (DbValidationError validationError in error.ValidationErrors) { log = new LogEntry { LogTime = DateTime.Now, Title = validationError.PropertyName, Message = validationError.ErrorMessage }; LogException2File(log); } } } catch (Exception) { } } catch (Exception exc) { LogException2File(log); LogException2File(exc); } }