public ActionResult CategoryNew(CategoryViewModel model) { try { if (ModelState.IsValid) { using (UnitOfWork uow = new UnitOfWork()) { string fileName = null; if (model.File != null && model.File.ContentLength > 0) { //SALVA IL FILE fileName = Path.GetFileName(model.File.FileName); var path = Path.Combine(Server.MapPath("/Uploads"), fileName); model.File.SaveAs(path); model.FileName = fileName; } CategoryRepository cr = new CategoryRepository(uow.Current); Category c = new Category(model.Nome, model.Descrizione); c.SetImagePath(fileName); cr.SaveOrUpdate(c); uow.Commit(); model.Message = "Salvataggio eseguito correttamente!"; } } return View(model); } catch (Exception ex) { return Error(ex); } }