public ActionResult AddGame(CreateGameVm createGameVm) { if (createGameVm == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { var gameEntity = Mapper.Map <CreateGameVm, GameEntity>(createGameVm); var minimalSystemReq = Mapper.Map <CreateSystemRequirementsVm, SystemRequirements>(createGameVm.MinimalSystemRequirements); var recommendedSystemReq = Mapper.Map <CreateSystemRequirementsVm, SystemRequirements>(createGameVm.RecommendedSystemRequirements); if (_gameLogic.Add(gameEntity)) { minimalSystemReq.GameId = gameEntity.Id; recommendedSystemReq.GameId = gameEntity.Id; if (_systemRequirementsLogic.Add(minimalSystemReq) && _systemRequirementsLogic.Add(recommendedSystemReq) && _genreLogic.AddGenresByGameId(gameEntity.Id, createGameVm.GenreIds)) { var image = WebImage.GetImageFromRequest("game-avatar"); if (image != null) { var newImage = new ImageEntity { MimeType = image.ImageFormat, Path = image.FileName, AlternativeText = "Game Avatar" }; if (_imageLogic.Add(newImage)) { var path = Path.Combine(Server.MapPath(_imagePath), image.FileName); image.Save(path); _imageLogic.SetAvatarForGame(gameEntity.Id, newImage.Id); } } return(RedirectToAction("Index", "Product")); } } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(View(createGameVm)); }