public ViewResult Settings(string workspace, string collection)
 {
   string view = "AdminSettings";
   AdminModel m = null;
   if (Scope.IsEntireSite)
   {
     var esm = TempData["model"] as AdminSettingsEntireSiteModel;
     if (esm == null)
     {
       esm = new AdminSettingsEntireSiteModel();
       esm.SiteAddress = AppService.Base;
       esm.DefaultSubdomain = AppService.DefaultSubdomain;
       esm.ServiceType = AppService.ServiceType.ToString();
       esm.Secure = AppService.Secure;
     }
     view = "AdminSettingsEntireSite";
     m = esm;
   }
   else if (Scope.IsWorkspace)
   {
     var wm = TempData["model"] as AdminSettingsWorkspaceModel;
     if (wm == null)
     {
       wm = new AdminSettingsWorkspaceModel();
       //wm.Workspace = workspace;
       wm.Title = Workspace.Title.Text;
       wm.Subtitle = Workspace.Subtitle != null ? Workspace.Subtitle.Text : null;
       wm.Name = Workspace.Name;
     }
     view = "AdminSettingsWorkspace";
     m = wm;
   }
   else
   {
     var cm = TempData["model"] as AdminSettingsCollectionModel;
     if (cm == null)
     {
       cm = new AdminSettingsCollectionModel();
       cm.CollectionId = Collection.Id;
       cm.Title = Collection.Title.Text;
       cm.Subtitle = Collection.Subtitle != null ? Collection.Subtitle.Text : null;
       cm.Owner = Collection.Id.Owner;
       cm.Name = Collection.Id.Collection;
       cm.Dated = Collection.Dated;
       cm.Visible = Collection.Visible;
       cm.AnnotationsOn = Collection.AnnotationsOn;
       cm.SyndicationOn = Collection.SyndicationOn;
     }
     view = "AdminSettingsCollection";
     m = cm;
   }
   if (m == null) m = new AdminModel();
   if (TempData["new"] != null) m.Notifications.Add((string)TempData["new"], "was created successfully! Changes may take some time before they appear.");
   else if (TempData["saved"] != null) m.Notifications.Add("Saved", "settings successfully! Changes may take some time before they appear.");
   return View(view, "Admin", m);
 }
 public ActionResult UpdateCollection(string workspace, string collection, AdminSettingsCollectionModel m)
 {
   try
   {
     AppCollection c = AppService.GetCollection(workspace, collection);
     m.CollectionId = c.Id;
     if (string.IsNullOrEmpty(m.Title)) throw new Exception("Title is required.");
     c.Title = new AtomTitle() { Text = m.Title };
     c.Subtitle = string.IsNullOrEmpty(m.Subtitle) ? null : new AtomSubtitle() { Text = m.Subtitle };
     c.AnnotationsOn = m.AnnotationsOn ?? false;
     c.Visible = m.Visible ?? false;
     c.SyndicationOn = m.SyndicationOn ?? false;
     AtomPubService.UpdateService(AppService);
     ServerApp.Restart();
     TempData["saved"] = true;
     return RedirectToAction("Settings", new { workspace = workspace, collection = collection });
   }
   catch (Exception ex)
   {
     LogService.Error(ex);
     m.Errors.Add(ex.Message);
   }
   TempData["model"] = m;
   return RedirectToAction("Settings", new { workspace = workspace, collection = collection });
 }
    public ActionResult NewCollection(string workspace, AdminSettingsCollectionModel m)
    {
      try
      {
        if (string.IsNullOrEmpty(m.Owner)) throw new Exception("Owner is required.");
        if (!string.IsNullOrEmpty(workspace) && workspace != Atom.DefaultWorkspaceName)
        {
          if (!m.Owner.StartsWith(workspace)) throw new Exception("Owner must start with workspace name: workspace.example.com");
        }

        if (string.IsNullOrEmpty(m.Name)) throw new Exception("Name is required.");
        if (m.Name.ToLowerInvariant() != m.Name.CleanSlug().ToLowerInvariant()) throw new Exception("Name has invalid characters.");
        string collection = m.Name.ToLowerInvariant();

        if (Workspace.Collections.Where(coll => coll.Id.Collection == collection).Count() > 0) 
            throw new Exception("The collection already exists.  Please choose a different name.");
        
        AppWorkspace w = AppService.GetWorkspace(workspace);
        bool @default = w.Collections.Count() == 0;

        AppCollection c = new AppCollection() { Id = new Id(m.Owner, collection), Dated = m.Dated ?? false, Default = @default };

        if (string.IsNullOrEmpty(m.Title)) throw new Exception("Title is required.");
        c.Title = new AtomTitle() { Text = m.Title };
        c.Subtitle = string.IsNullOrEmpty(m.Subtitle) ? null : new AtomSubtitle() { Text = m.Subtitle };
        c.AnnotationsOn = m.AnnotationsOn ?? false;
        c.Visible = m.Visible ?? false;
        c.SyndicationOn = m.SyndicationOn ?? false;
        c.Href = new Uri(collection + ".atom", UriKind.Relative);

        w.AddCollection(c);
        AtomPubService.UpdateService(AppService);
        ServerApp.Restart();
        TempData["new"] = "New Collection";
        return RedirectToAction("Settings", new { workspace = workspace, collection = collection });
      }
      catch (Exception ex)
      {
        LogService.Error(ex);
        m.Errors.Add(ex.Message);
      }
      return View("AdminSettingsCollection", "Admin", m);
    }
 public ViewResult NewCollection()
 {
   AdminSettingsCollectionModel cm = new AdminSettingsCollectionModel();
   return View("AdminSettingsCollection", "Admin", cm);
 }