public ActionResult Create(Actor model, HttpPostedFileBase ImagePath) { Movie movie = CurrentSession.Get <Movie>("selectedMovie"); CurrentSession.Remove("notNormalCreate"); if (model.Id != 0) { Actor actor = actorManager.Find(I => I.Id == model.Id); movie.Actors.Add(actor); actorManager.Save(); return(RedirectToAction("Index")); } if (ModelState.IsValid) { actorManager.Insert(model); Actor actor = actorManager.Find(I => I.Name == model.Name && I.Surname == model.Surname); if (ImagePath != null) { actor.ImagePath = $"{actor.ImagePath}.{ImagePath.ContentType.Split('/')[1]}"; ImagePath.SaveAs(Server.MapPath($"~/img/ActorPhotos/{actor.ImagePath}")); } else { actor.ImagePath = "defaultPhoto.png"; } actorManager.Save(); if (movie != null) { actor.Movies.Add(movie); actorManager.Attach(actor); actorManager.Save(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } return(View()); }