public void Execute(CreatePostDto request)
        {
            _validator.ValidateAndThrow(request); // ValidationException

            var newFileName = Guid.NewGuid() + Path.GetExtension(request.Photo.FileName);

            using (Image image = Image.Load(request.Photo.OpenReadStream()))
            {
                image.Save(Path.Combine("wwwroot", Photo.PhotoFolderPath, newFileName));

                image.Mutate(x => x.Resize(250, 250));
                image.Save(Path.Combine("wwwroot", Photo.ThumbnailPhotoFolderPath, newFileName));
            }

            var photo = new Photo
            {
                Caption  = request.PhotoCaption,
                FileName = newFileName
            };

            _context.Photos.Add(photo);

            var post = new Post
            {
                Title = request.Title,
                Text  = request.Text,
                Photo = photo
            };

            _context.Posts.Add(post);

            _context.SaveChanges(_actor.Id);
        }
Beispiel #2
0
        public void Execute(PostDto request)
        {
            validator.ValidateAndThrow(request);
            var post = mapper.Map <Post>(request);

            context.Posts.Add(post);
            context.SaveChanges();
        }
        public void Execute(PostDto request)
        {
            validator.ValidateAndThrow(request);
            var post = context.Posts.Find(request.Id);

            if (post == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Post));
            }

            var p = context.Posts.Where(x => x.Id == request.Id).First();

            mapper.Map(request, p);
            context.SaveChanges();
        }
Beispiel #4
0
        public void Execute(PostDto request)
        {
            _validator.ValidateAndThrow(request);

            var post = new Post
            {
                Title     = request.Title,
                Content   = request.Content,
                PhotoPath = request.PhotoPath,
                UserId    = request.UserId,
                TopicId   = request.TopicId
            };

            _context.Posts.Add(post);
            _context.SaveChanges();
        }