public ActionResult Add(Game game, HttpPostedFileBase picture, int categoryId) { if (ModelState.IsValid) { if (picture != null) { if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png") { Image image = Image.FromStream(picture.InputStream); if (image.Height > 200 || image.Width > 200) { Image smallImage = Class.ImageHelper.ScaleImage(image, 200, 200); Bitmap b = new Bitmap(smallImage); Guid guid = Guid.NewGuid(); string imageName = guid.ToString() + ".jpg"; b.Save(Server.MapPath("~/uploads/game/" + imageName), ImageFormat.Jpeg); smallImage.Dispose(); b.Dispose(); game.ImageName = imageName; } else { picture.SaveAs(Server.MapPath("~/uploads/game/" + picture.FileName)); } } } GameCategoryDao gameCategoryDao = new GameCategoryDao(); GameCategory gameCategory = gameCategoryDao.GetById(categoryId); game.Category = gameCategory; GameDao gameDao = new GameDao(); gameDao.Create(game); TempData["message-success"] = "Hra byla úspěšně vytvořena"; } else { return(View("Create", game)); } return(RedirectToAction("Index")); }