public ActionResult Create(FormCollection collection) { ViewBag.storyId = storyId; ViewBag.collageId = collageId; Models.Story story = new Models.Story(); Models.StoryBlock block = new Models.StoryBlock(); if (!doc.Element("collages").Elements("collage").Elements("story").Elements("block").Any()) { block.id = 0; } else { block.id = (int)(from S in doc.Descendants("block") orderby (int)S.Element("id") descending select (int)S.Element("id")).FirstOrDefault() + 1; } blockId = block.id; ViewBag.blockId = blockId; block.blockCaption = collection["BlockCaption"]; block.blockContent = collection["BlockContent"]; block.imgPath = ""+block.id; block.bolckOrder = collection["bolckOrder"]; story.Create(storyId, block); return View("Upload"); }
public ActionResult Create(FormCollection collection) { ViewBag.storyId = storyId; ViewBag.collageId = collageId; Models.Story story = new Models.Story(); Models.StoryBlock block = new Models.StoryBlock(); if (!doc.Element("collages").Elements("collage").Elements("story").Elements("block").Any()) { block.id = 0; } else { block.id = (int)(from S in doc.Descendants("block") orderby(int) S.Element("id") descending select(int) S.Element("id")).FirstOrDefault() + 1; } blockId = block.id; ViewBag.blockId = blockId; block.blockCaption = collection["BlockCaption"]; block.blockContent = collection["BlockContent"]; block.imgPath = "" + block.id; block.bolckOrder = collection["bolckOrder"]; story.Create(storyId, block); return(View("Upload")); }
// GET: /Block/ public ActionResult Index(int id, int?clgId) { ViewBag.storyId = storyId = id; ViewBag.collageId = clgId; collageId = clgId ?? default(int); blockList = new List <Models.StoryBlock>(); var stys = from story in doc.Element("collages") .Elements("collage").Elements("story") select story; foreach (var sty in stys) { if (sty.Element("id").Value == id.ToString()) { ViewBag.story = sty.Element("storyCaption").Value; var blk = from block in sty.Elements("block") orderby(int) block.Element("bolckOrder") select block; foreach (var elem in blk) { Models.StoryBlock c = new Models.StoryBlock(); c.id = Int32.Parse(elem.Element("id").Value); c.blockCaption = elem.Element("blockCaption").Value; c.blockContent = elem.Element("blockContent").Value; c.bolckOrder = elem.Element("bolckOrder").Value; if (elem.Element("imgPath") != null) { c.imgPath = elem.Element("imgPath").Value; } blockList.Add(c); } return(View(blockList)); } } return(View()); }
public ActionResult showImgView(int id, int? clgId) { ViewBag.storyId = id; storyId = id; //????? ViewBag.collageId = clgId; collageId = clgId ?? default(int); List<Models.StoryBlock> blockList = new List<Models.StoryBlock>(); //get the list of stories in each collage string pathc = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Collages.xml"); XDocument doc = XDocument.Load(pathc); string paths = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\StoryCollection.xml"); XDocument collection = XDocument.Load(paths); Models.Collage c = new Models.Collage(); List<Models.Story> stories = new List<Models.Story>(); if (collageId == 0) //all stories in collage 0 { stories = c.storyList; } else { // choose stories in other collage and add to List List<Models.Story> storyList = new List<Models.Story>(); var clgs = from collage in collection.Element("collages") .Elements("collage") select collage; foreach (var clg in clgs) { if (clg.Element("id").Value == collageId.ToString()) { ViewBag.collageName = clg.Element("collageName").Value; var styids = from story in clg.Elements("storyId") select story; var s_in_c = from sty in doc.Element("collages").Elements("collage").Elements("story") select sty; foreach (var styid in styids) { foreach (var elem in s_in_c) { if (styid.Value == elem.Element("id").Value) { Models.Story st = new Models.Story(); st.id = Int32.Parse(elem.Element("id").Value); st.storyCaption = elem.Element("storyCaption").Value; st.storyTime = elem.Element("storyTime").Value; st.storyOrder = elem.Element("storyOrder").Value; storyList.Add(st); } } } stories = storyList; } } } //get the id of each story in collage int[] stor = new int[stories.Count()]; int i = 0; foreach (Models.Story story in stories) { stor[i] = story.id; i++; } if (id == stor[stor.Count() - 1]) { ViewBag.run = stor[0]; } else { for (int j = 0; j < stories.Count(); j++) { if (id == stor[j]) { ViewBag.run = stor[j + 1]; } } } //get information of each block in story var stys = from story in doc.Element("collages") .Elements("collage").Elements("story") orderby (int)story.Element("storyOrder") select story; foreach (var sty in stys) { if (sty.Element("id").Value == id.ToString()) { ViewBag.story = sty.Element("storyCaption").Value; ViewBag.storyTime = sty.Element("storyTime").Value + "000"; var blk = from block in sty.Elements("block") orderby (int)block.Element("bolckOrder") select block; foreach (var elem in blk) { Models.StoryBlock cs = new Models.StoryBlock(); cs.id = Int32.Parse(elem.Element("id").Value); cs.blockCaption = elem.Element("blockCaption").Value; cs.blockContent = elem.Element("blockContent").Value; cs.bolckOrder = elem.Element("bolckOrder").Value; if (elem.Element("imgPath") != null) { cs.imgPath = elem.Element("imgPath").Value; } blockList.Add(cs); } return View(blockList); } } return View(); }
// GET: /Block/ public ActionResult Index(int id, int? clgId) { ViewBag.storyId = storyId = id; ViewBag.collageId = clgId; collageId = clgId ?? default(int); blockList = new List<Models.StoryBlock>(); var stys = from story in doc.Element("collages") .Elements("collage").Elements("story") select story; foreach(var sty in stys) { if (sty.Element("id").Value == id.ToString()) { ViewBag.story = sty.Element("storyCaption").Value; var blk = from block in sty.Elements("block") orderby (int)block.Element("bolckOrder") select block; foreach(var elem in blk) { Models.StoryBlock c = new Models.StoryBlock(); c.id = Int32.Parse(elem.Element("id").Value); c.blockCaption = elem.Element("blockCaption").Value; c.blockContent = elem.Element("blockContent").Value; c.bolckOrder = elem.Element("bolckOrder").Value; if (elem.Element("imgPath") != null) { c.imgPath = elem.Element("imgPath").Value; } blockList.Add(c); } return View(blockList); } } return View(); }
public string htmlBuilder(Models.Story s) { string collages = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Collages.xml"); XDocument doc = XDocument.Load(collages); var stys = from story in doc.Element("collages") .Elements("collage").Elements("story") orderby(int) story.Element("storyOrder") select story; //get link for next story int[] a = new int[stories.Count()]; int link = 0; string href = ""; int i = 0; foreach (Models.Story story in stories) { a[i] = story.id; i++; } if (s.id == a[stories.Count - 1]) { link = a[0]; } else { for (int j = 0; j < stories.Count(); j++) { if (s.id == a[j]) { link = a[j + 1]; } } } foreach (Models.Story story in stories) { if (story.id == link) { href = story.storyCaption; } } //form html for each story foreach (var sty in stys) { if (sty.Element("id").Value == s.id.ToString()) { var blk = from block in sty.Elements("block") orderby(int) block.Element("bolckOrder") select block; StringBuilder sb = new StringBuilder(); sb.Append("<h2>"); sb.Append(sty.Element("storyCaption").Value); sb.Append("</h2>"); sb.Append("<a href='"); sb.Append(href); sb.Append(".html'>"); sb.Append("Next Story"); sb.Append("</a>"); sb.Append("<br/>"); foreach (var elem in blk) { Models.StoryBlock c = new Models.StoryBlock(); c.blockContent = elem.Element("blockContent").Value; if (elem.Element("imgPath") != null) { c.imgPath = elem.Element("imgPath").Value; } sb.Append("<img style='width:1024ps; height: 768px' src='"); sb.Append(c.imgPath); sb.Append("'/>"); sb.Append("<p>"); sb.Append(c.blockContent); sb.Append("</p>"); } return(sb.ToString()); } } return(""); }
//----< GET api/File?fileName=foobar.txt&open=true >--------------- //----< attempt to open or close FileStream >---------------------- public HttpResponseMessage Get(string fileName, string open) { string sessionId; var response = new HttpResponseMessage(); Models.Session session = new Models.Session(); CookieHeaderValue cookie = Request.Headers.GetCookies("session-id").FirstOrDefault(); if (cookie == null) { sessionId = session.incrSessionId(); cookie = new CookieHeaderValue("session-id", sessionId); cookie.Expires = DateTimeOffset.Now.AddDays(1); cookie.Domain = Request.RequestUri.Host; cookie.Path = "/"; } else { sessionId = cookie["session-id"].Value; } try { FileStream fs; string path = System.Web.HttpContext.Current.Server.MapPath("~\\Img\\"); if (open == "download") // attempt to open requested fileName { PrepDownloadController pd = new PrepDownloadController(); pd.Index(Int32.Parse(fileName), "api"); path = path + "collage"; string currentFileSpec = path + "\\" + fileName + ".zip" ; fs = new FileStream(currentFileSpec, FileMode.Open); session.saveStream(fs, sessionId); } else if(open == "upload") { string[] items = fileName.Split('?'); string storyId = items[0]; string blkTitle = items[1]; string blkContent = items[2]; string blkOrder = items[3]; string imgPath = items[4]; string XMLpath = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Collages.xml"); XDocument doc = XDocument.Load(XMLpath); Models.Story story = new Models.Story(); Models.StoryBlock block = new Models.StoryBlock(); if (!doc.Element("collages").Elements("collage").Elements("story").Elements("block").Any()) { block.id = 0; } else { block.id = (int)(from S in doc.Descendants("block") orderby (int)S.Element("id") descending select (int)S.Element("id")).FirstOrDefault() + 1; } block.blockCaption = blkTitle; block.blockContent = blkContent; block.imgPath = storyId + "_" + block.id + Path.GetExtension(imgPath); block.bolckOrder = blkOrder; story.Create(Int32.Parse(storyId), block); path = path + storyId; if (!Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } string currentFileSpec = path + "\\" + block.imgPath; fs = new FileStream(currentFileSpec, FileMode.OpenOrCreate); session.saveStream(fs, sessionId); } else // close FileStream { fs = session.getStream(sessionId); session.removeStream(sessionId); fs.Close(); } response.StatusCode = (HttpStatusCode)200; } catch { response.StatusCode = (HttpStatusCode)400; } finally // return cookie to save current sessionId { response.Headers.AddCookies(new CookieHeaderValue[] { cookie }); } return response; }
public string htmlBuilder(Models.Story s) { string collages = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Collages.xml"); XDocument doc = XDocument.Load(collages); var stys = from story in doc.Element("collages") .Elements("collage").Elements("story") orderby (int)story.Element("storyOrder") select story; //get link for next story int[] a = new int[stories.Count()]; int link = 0; string href = ""; int i = 0; foreach(Models.Story story in stories){ a[i] = story.id; i++; } if (s.id == a[stories.Count - 1]) { link = a[0]; } else { for (int j = 0; j < stories.Count(); j++) { if (s.id == a[j]) { link = a[j + 1]; } } } foreach (Models.Story story in stories) { if (story.id == link) { href = story.storyCaption; } } //form html for each story foreach (var sty in stys) { if (sty.Element("id").Value == s.id.ToString()) { var blk = from block in sty.Elements("block") orderby (int)block.Element("bolckOrder") select block; StringBuilder sb = new StringBuilder(); sb.Append("<h2>"); sb.Append(sty.Element("storyCaption").Value); sb.Append("</h2>"); sb.Append("<a href='"); sb.Append(href); sb.Append(".html'>"); sb.Append("Next Story"); sb.Append("</a>"); sb.Append("<br/>"); foreach (var elem in blk) { Models.StoryBlock c = new Models.StoryBlock(); c.blockContent = elem.Element("blockContent").Value; if (elem.Element("imgPath") != null) { c.imgPath = elem.Element("imgPath").Value; } sb.Append("<img style='width:1024ps; height: 768px' src='"); sb.Append(c.imgPath); sb.Append("'/>"); sb.Append("<p>"); sb.Append(c.blockContent); sb.Append("</p>"); } return sb.ToString(); } } return ""; }
public ActionResult showImgView(int id, int?clgId) { ViewBag.storyId = id; storyId = id; //????? ViewBag.collageId = clgId; collageId = clgId ?? default(int); List <Models.StoryBlock> blockList = new List <Models.StoryBlock>(); //get the list of stories in each collage string pathc = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Collages.xml"); XDocument doc = XDocument.Load(pathc); string paths = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\StoryCollection.xml"); XDocument collection = XDocument.Load(paths); Models.Collage c = new Models.Collage(); List <Models.Story> stories = new List <Models.Story>(); if (collageId == 0) //all stories in collage 0 { stories = c.storyList; } else { // choose stories in other collage and add to List List <Models.Story> storyList = new List <Models.Story>(); var clgs = from collage in collection.Element("collages") .Elements("collage") select collage; foreach (var clg in clgs) { if (clg.Element("id").Value == collageId.ToString()) { ViewBag.collageName = clg.Element("collageName").Value; var styids = from story in clg.Elements("storyId") select story; var s_in_c = from sty in doc.Element("collages").Elements("collage").Elements("story") select sty; foreach (var styid in styids) { foreach (var elem in s_in_c) { if (styid.Value == elem.Element("id").Value) { Models.Story st = new Models.Story(); st.id = Int32.Parse(elem.Element("id").Value); st.storyCaption = elem.Element("storyCaption").Value; st.storyTime = elem.Element("storyTime").Value; st.storyOrder = elem.Element("storyOrder").Value; storyList.Add(st); } } } stories = storyList; } } } //get the id of each story in collage int[] stor = new int[stories.Count()]; int i = 0; foreach (Models.Story story in stories) { stor[i] = story.id; i++; } if (id == stor[stor.Count() - 1]) { ViewBag.run = stor[0]; } else { for (int j = 0; j < stories.Count(); j++) { if (id == stor[j]) { ViewBag.run = stor[j + 1]; } } } //get information of each block in story var stys = from story in doc.Element("collages") .Elements("collage").Elements("story") orderby(int) story.Element("storyOrder") select story; foreach (var sty in stys) { if (sty.Element("id").Value == id.ToString()) { ViewBag.story = sty.Element("storyCaption").Value; ViewBag.storyTime = sty.Element("storyTime").Value + "000"; var blk = from block in sty.Elements("block") orderby(int) block.Element("bolckOrder") select block; foreach (var elem in blk) { Models.StoryBlock cs = new Models.StoryBlock(); cs.id = Int32.Parse(elem.Element("id").Value); cs.blockCaption = elem.Element("blockCaption").Value; cs.blockContent = elem.Element("blockContent").Value; cs.bolckOrder = elem.Element("bolckOrder").Value; if (elem.Element("imgPath") != null) { cs.imgPath = elem.Element("imgPath").Value; } blockList.Add(cs); } return(View(blockList)); } } return(View()); }
//----< GET api/File?fileName=foobar.txt&open=true >--------------- //----< attempt to open or close FileStream >---------------------- public HttpResponseMessage Get(string fileName, string open) { string sessionId; var response = new HttpResponseMessage(); Models.Session session = new Models.Session(); CookieHeaderValue cookie = Request.Headers.GetCookies("session-id").FirstOrDefault(); if (cookie == null) { sessionId = session.incrSessionId(); cookie = new CookieHeaderValue("session-id", sessionId); cookie.Expires = DateTimeOffset.Now.AddDays(1); cookie.Domain = Request.RequestUri.Host; cookie.Path = "/"; } else { sessionId = cookie["session-id"].Value; } try { FileStream fs; string path = System.Web.HttpContext.Current.Server.MapPath("~\\Img\\"); if (open == "download") // attempt to open requested fileName { PrepDownloadController pd = new PrepDownloadController(); pd.Index(Int32.Parse(fileName), "api"); path = path + "collage"; string currentFileSpec = path + "\\" + fileName + ".zip"; fs = new FileStream(currentFileSpec, FileMode.Open); session.saveStream(fs, sessionId); } else if (open == "upload") { string[] items = fileName.Split('?'); string storyId = items[0]; string blkTitle = items[1]; string blkContent = items[2]; string blkOrder = items[3]; string imgPath = items[4]; string XMLpath = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Collages.xml"); XDocument doc = XDocument.Load(XMLpath); Models.Story story = new Models.Story(); Models.StoryBlock block = new Models.StoryBlock(); if (!doc.Element("collages").Elements("collage").Elements("story").Elements("block").Any()) { block.id = 0; } else { block.id = (int)(from S in doc.Descendants("block") orderby(int) S.Element("id") descending select(int) S.Element("id")).FirstOrDefault() + 1; } block.blockCaption = blkTitle; block.blockContent = blkContent; block.imgPath = storyId + "_" + block.id + Path.GetExtension(imgPath); block.bolckOrder = blkOrder; story.Create(Int32.Parse(storyId), block); path = path + storyId; if (!Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } string currentFileSpec = path + "\\" + block.imgPath; fs = new FileStream(currentFileSpec, FileMode.OpenOrCreate); session.saveStream(fs, sessionId); } else // close FileStream { fs = session.getStream(sessionId); session.removeStream(sessionId); fs.Close(); } response.StatusCode = (HttpStatusCode)200; } catch { response.StatusCode = (HttpStatusCode)400; } finally // return cookie to save current sessionId { response.Headers.AddCookies(new CookieHeaderValue[] { cookie }); } return(response); }