public ActionResult Create(Post post)
        {
            // Validate that a image was selected
            if (Request.Files.Count == 0 || Request.Files[0].ContentLength == 0)
            {
                ModelState.AddModelError("ImageUpload", "Ein Bild ist erforderlich");
            }

            if (ModelState.IsValid)
            {
                // Get image from request and save
                var image = ImageUtility.SaveImageFromRequest();

                // Save image to db
                image = db.Images.Add(image);
                db.SaveChanges();

                // Assign the image to the post
                post.Image = image;

                // Only the admin can post images here, so select admin
                post.User = db.Users.FirstOrDefault(x => x.Name == "Admin");

                // Save post to db
                db.Posts.Add(post);
                db.SaveChanges();

                return RedirectToAction("Index");
            }

            return View(post);
        }
        public IHttpActionResult PostPost(AddPostDto postDto)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            // Find related user
            var user = db.Users.FirstOrDefault(u => u.Identifier == postDto.UserIdentifier);
            if (user == null)
            {
                return BadRequest("Invalid user");
            }

            // Find related image
            var image = db.Images.Find(postDto.ImageId);
            if (image == null)
            {
                return BadRequest("Image was not found");
            }

            // Map dto to post
            var post = new Post
            {
                Title = postDto.Title,
                Image = image,
                User = user
            };

            // Add to db
            db.Posts.Add(post);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = post.Id }, postDto);
        }
        public ActionResult Edit(Post post)
        {
            if (ModelState.IsValid)
            {
                db.Entry(post).State = EntityState.Modified;

                // Update image
                post.Image = ImageUtility.GetImageAndUpdateOnDisk(post.Image);

                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(post);
        }
 public ActionResult Create(Post post)
 {
     return View(post);
 }