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