Ejemplo n.º 1
0
        public int CreateFile(FileModel fileModel)
        {
            int id = FileRepository.Create(fileModel);

            CacheRepository.Add(fileModel, $"{FileCache}-{fileModel.Id}");
            UnitOfWork.Save();
            return(id);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }