/// <summary> /// Saves the after having been loaded within the same remote method. /// Reloads potentially modified members in the M object to make /// changes visible in WebSharper. /// </summary> /// <typeparam name="M"></typeparam> /// <param name="stored">The stored.</param> /// <returns>The VIewState string</returns> public static string Save <M>(ViewModel <M> stored) where M : class, IStored <M>, new() { stored.SaveMembers(); // Captures members directly mutable on the client side. stored.LoadMembers(); // Mirrors side effects of methods on M in the ViewModel. switch (stored.SessionStorage) // guaranteed here, whether overridden or not { case Storage.ViewState: var filter = StorageImplementation.EncryptViewState(Configuration); stored.SerializeMain(filter); // save locally into the object return(stored.ViewState); case Storage.Session: StorageImplementation.SaveSession(Configuration, HttpContext, stored.Main); return(null); case Storage.Database: StorageImplementation.SaveDatabase(Configuration, HttpContext, stored.Main); return(null); default: throw new NotImplementedException(String.Format( "Storage {0}", stored.SessionStorage)); } }
/// <summary> /// Store the serialized controller to the database. Reference to it is /// kept in a persistent cookie. /// </summary> public static void SaveDatabase(this IPersistentController inst) { inst.ViewBag.SessionStorage = ViewBagSessionStorage(inst, Storage.Database); StorageImplementation.SaveDatabase(inst.Configuration, inst.HttpContext, inst); }