public ActionResult Upload(string NetworkName, IEnumerable<HttpPostedFileBase> files) { var nvm = new NetworkListViewModel(); IEnumerable<HttpPostedFileBase> someFiles = files; var networkDoc = new XDocument(); if(NetworkName == "") { ViewBag.UploadAlert = "Enter a network name"; using (var c = new DataModelContext()) { nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); } return View("Index", nvm); } try { networkDoc = XDocument.Load(Request.Files["NetworkFile"].InputStream); } catch (XmlException e) { Console.WriteLine(e.Message); ViewBag.UploadAlert = "You must select a valid xml file"; using (var c = new DataModelContext()) { nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); } return View("Index", nvm); } using(var c = new DataModelContext()) { var xmlE = new XmlEngine(); var xmlnetwork = xmlE.XmlFileToNetwork(networkDoc); xmlnetwork.Name = NetworkName; xmlnetwork.Author = UserDataEngine.getInstance().GetCurrentUser(c, HttpContext); xmlnetwork.LastEdit = DateTime.Now; c.Networks.Add(xmlnetwork); try { c.SaveChanges(); } catch(DbEntityValidationException e) { foreach(var i in e.EntityValidationErrors) { Console.WriteLine(i.ValidationErrors); } throw e; } nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); ViewBag.NewNetworkID = xmlnetwork.ID; } ViewBag.Alert = "Network upload successful"; ViewBag.AlertClass = "alert-success"; return View("Index", nvm); }
public ActionResult NetworkHistory(long id) { var nvm = new NetworkListViewModel(); nvm.Networks = new List<Network>(); using(var c = new DataModelContext()) { var network = c.Networks .Include("Author") .Include("Parent") .SingleOrDefault(n => n.ID == id); while(true) { nvm.Networks.Add(network); if (network.Parent == null) break; network = c.Networks.Include("Author").Include("Parent") .SingleOrDefault(n => n.ID == network.Parent.ID); } } return View(nvm); }
public ActionResult CreateBlank(string NetworkName) { var nvm = new NetworkListViewModel(); if(NetworkName == "") { ViewBag.UploadAlert = "Enter a network name"; using (var c = new DataModelContext()) { nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); } return View("Index", nvm); } using(var c = new DataModelContext()) { var xmlnetwork = new Network(); xmlnetwork.Name = NetworkName; xmlnetwork.Author = UserDataEngine.getInstance().GetCurrentUser(c, HttpContext); xmlnetwork.LastEdit = DateTime.Now; c.Networks.Add(xmlnetwork); try { c.SaveChanges(); } catch(DbEntityValidationException e) { foreach(var i in e.EntityValidationErrors) { Console.WriteLine(i.ValidationErrors); } throw e; } nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); ViewBag.NewNetworkID = xmlnetwork.ID; } ViewBag.Alert = "Network upload successful"; ViewBag.AlertClass = "alert-success"; return View("Index", nvm); }
public ActionResult Index() { var nvm = new NetworkListViewModel(); using(var c = new DataModelContext()) { nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); } object alertObject; if(TempData.TryGetValue("Alert", out alertObject)) { ViewBag.Alert = alertObject; } return View(nvm); }
public ActionResult UploadUrl(string NetworkName, string NetworkUrl) { var nvm = new NetworkListViewModel(); Network net; if(NetworkName == "") { ViewBag.UrlUploadAlert = "Enter a network name"; using (var c = new DataModelContext()) { nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); } return View("Index", nvm); } try { net = new XmlEngine().UrlDownloadToNetwork(new Uri(NetworkUrl)); } catch (Exception e) { Console.WriteLine(e.Message); ViewBag.UrlUploadAlert = "Could not find valid XML file at specified URL"; using (var c = new DataModelContext()) { nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); } return View("Index", nvm); } using(var c = new DataModelContext()) { net.Name = NetworkName; net.Author = UserDataEngine.getInstance().GetCurrentUser(c, HttpContext); net.LastEdit = DateTime.Now; c.Networks.Add(net); try { c.SaveChanges(); } catch(DbEntityValidationException e) { foreach(var i in e.EntityValidationErrors) { Console.WriteLine(i.ValidationErrors); } throw e; } nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList(); ViewBag.NewNetworkID = net.ID; } ViewBag.Alert = "Network upload successful"; ViewBag.AlertClass = "alert-success"; return View("Index", nvm); }