public int CreateFile(FileModel fileModel) { int id = FileRepository.Create(fileModel); CacheRepository.Add(fileModel, $"{FileCache}-{fileModel.Id}"); UnitOfWork.Save(); return(id); }
public void CreateAdmin(Admin admin) { var createdAdmin = AdminRepository.GetByLogin(admin.Login); if (createdAdmin != null) { throw new AdminExistsException("An administrator with this login already exists"); } AdminRepository.Create(admin); CacheRepository.Add(admin, $"{AdminCache}-{admin.Id}"); UnitOfWork.Save(); }
public IEnumerable <Comment> GetCommentsWithTools(OptionsCollectionById options) { var comments = CacheRepository.GetItems <Comment>(GetOptionsString(options)); if (comments != null) { return(comments); } comments = CommentRepository.GetWithOptions(options); CacheRepository.Add(comments, GetOptionsString(options)); return(comments); }
public IEnumerable <Comment> GetCommentsByPostId(int id) { var comments = CacheRepository.GetItems <Comment>($"{CommentsByPostIdCache}-{id}"); if (comments != null) { return(comments); } comments = CommentRepository.GetByPostId(id).Reverse(); CacheRepository.Add(comments, $"{CommentsByPostIdCache}-{id}"); return(comments); }
public Admin GetAdmin(int id) { var admin = CacheRepository.GetItem <Admin>($"{AdminCache}-{id}"); if (admin != null) { return(admin); } admin = AdminRepository.Get(id); if (admin == null) { throw new AdminNullException(); } CacheRepository.Add(admin, $"{AdminCache}-{id}"); return(admin); }
public FileModel GetFile(int id) { var file = CacheRepository.GetItem <FileModel>($"{FileCache}-{id}"); if (file != null) { return(file); } file = FileRepository.Get(id); if (file == null) { throw new FileNullException(); } CacheRepository.Add(file, $"{FileCache}-{id}"); return(file); }