示例#1
0
        public int CreateFile(FileModel fileModel)
        {
            int id = FileRepository.Create(fileModel);

            CacheRepository.Add(fileModel, $"{FileCache}-{fileModel.Id}");
            UnitOfWork.Save();
            return(id);
        }
示例#2
0
        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();
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }