public ActionResult ChangeAvatar(ChangeAvatarViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = _identityFacade.GetUserId();
                if (!_fileValidator.IsValidFiletype(model.file))
                {
                    ModelState.AddModelError("", "Invalid file format!");
                    return(View(model));
                }
                _imageRepository.AddImageToDb(userId, model.file);
                return(RedirectToAction("Index", "Manage"));
            }

            return(View());
        }
Beispiel #2
0
        public Post CreatePost(CreatePostViewModel p)
        {
            Post post = new Post()
            {
                Author   = _identityFacade.GetUserName(),
                AuthorId = _identityFacade.GetUserId(),
                PostedAt = DateTime.Now,
                Content  = p.Content,
                Title    = p.Title,
                SubTitle = p.SubTitle
            };

            if (p.file != null)
            {
                post.postPicture = new PostPicture()
                {
                    PostImageInBytes = _dataConverter.FileBaseToByteArray(p.file)
                };
            }
            return(post);
        }
        public ActionResult RatePost(int id, RatingType ratingType)
        {
            if (_postRepository.GetPost(id) == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            var visible = _displayValidator.IsAvailablePost(id);

            if (!visible)
            {
                return(RedirectToAction("Forbidden", "Error"));
            }

            _postRepository.RatePost(id, _identityFacade.GetUserId(), ratingType);

            return(RedirectToAction("SinglePost", "Post", new { id }));
        }
        public bool CanAccessPost(int id)
        {
            var post = _postRepository.GetPost(id);

            return(IsAdministration() || post.AuthorId == _identityFacade.GetUserId());
        }