I have a controller. It functions as follows:A user imports a file and decides whether the files contents contain new entries to be placed into a database, or existing entries entries to be updated.The user clicks on the import button and is sent to the controller below. If there are any warnings or errors, the validation results screen is shown - to help the users correct their data.If the file doesn't contain any errors or warnings, the validation screen will be skipped and their file contents will be inserted/updated into the database.This is clearly far too much logic for a controller as I have read that the controller is simply meant to decide which view to send the data to. I am having a rather difficult time determining how to extract out the data.I am looking for suggestions on what my next step should be. Thank you to anyone who takes time to help me.public ActionResult ValidationResultsScreen(HttpPostedFileBase file, DatabaseAccessMode databaseAccess){    try    {        var fileLocation = Path.Combine(Path.GetTempPath(), string.Join(Guid.NewGuid().ToString(), file.FileName));        Session[TempFileLocation] = fileLocation;        Session[DatabaseAccessMode] = databaseAccess;        file.SaveAs(fileLocation);        var importer= new Importer(_connectionString, _logManager, databaseAccess,Server.MapPath(..\\bin));        var parsedValues= importer.ParseFile(fileLocation);        var failedValues = ParsedValues.Where(x => x.ParsedState != ParsedState.Success);        if (failedValues.Any())//if there were any warnings or errors display the validation results screen        {            return View(processedValues);        }        //else import the file to the database        var transactionResults = importer.UploadToDatabase(parsedValues);        var failedDBTransactions= RetrieveFailedResults(transactionResults);        return failedDBTransactions.Any()             ? View(DatabaseImportErrorScreen, failedDBTransactions)             : View(DatabaseImportResults, transactionResults);    }    catch (Exception exception)    {        ViewBag.ExceptionMessage = exception.Message;        return View(DefaultErrorScreen);    }}
How could I make my controller a little less hideous?
c#;mvc;controller;asp.net mvc 4
Maybe something like this? (commentary included)://Do file locations really need to be saved in the session? I would hope not.protected string TempFileLocation {get; set;}//This assumes DatabaseAccessMode is an class of some kind.protected DatabaseAccessMode DatabaseAccess {get;set;}//place wherever your private methods go...private WhateverTypeORInterfaceParsedValuesIs GetParsedValues(HttpPostedFileBase file){        TempFileLocation  = Path.Combine(Path.GetTempPath(),             string.Join(Guid.NewGuid().ToString(),             file.FileName));        file.SaveAs(TempFileLocation);        var importer= new Importer(_connectionString,             _logManager,             DatabaseAccess ,Server.MapPath(..\\bin));        var parsedValues= importer.ParseFile(TempFileLocation);        return parsedValues;}//and of course, your new Actionpublic ActionResult ValidationResultsScreen(HttpPostedFileBase file, DatabaseAccessMode databaseAccess){    try    {        //save it for later.         //(we still need to figure out a proper lifetime        // for your Database Access mode)        DatabaseAccess = databaseAccess;         //grab parsed values.        var parsedValues = GetParsedValues(file)        //if there were any warnings or errors display the validation results screen        if (parsedValues.Where(x => x.ParsedState != ParsedState.Success).Any())        {            return View(processedValues); // what are the processedValues???        }         else        {             //import the file to the database           var transactionResults = importer.UploadToDatabase(parsedValues);           var failedDBTransactions= RetrieveFailedResults(transactionResults);           return failedDBTransactions.Any()             ? View(DatabaseImportErrorScreen, failedDBTransactions)             : View(DatabaseImportResults, transactionResults);        }    }    catch (Exception exception)    {        ViewBag.ExceptionMessage = exception.Message;        return View(DefaultErrorScreen);    }}However, you may have noticed I removed the utilization of a Session objectI could see some value to having a Database access mode in session. Even so, using a session to cache data can cause a multitude of problems if you don't have a session timeout page or ways to refill your session on session timeout. Also, using the session directly might introduce race issues. One attempt to still use the session while avoiding race issues might be the following:private DatabaseAccessMode _DataAccess;protected DatabaseAccessMode DatabaseAccess{     get{         //save the first non-null value retrieved and use that every time.          _DataAccess = _DataAccess               ?? (DatabaseAccessMode) HttpContext.Current.Session[DatabaseAccessMode]         return _DataAccess ;     }     set{         _DataAccess = value;         HttpContext.Current.Session[DatabaseAccessMode] = value;     }}but if you have a whole set of these values, and changing any one of them might invalidate all the others, it would probably be best to isolate that logic somewhere else.