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/Details/5
 public ActionResult Details(int id, int?styId)
 {
     try
     {
         ViewBag.collageId = collageId;
         if (styId == null)
         {
             ViewBag.storyId = storyId;
         }
         else
         {
             ViewBag.storyId = styId;
         }
         ViewBag.blockId = id;
         Models.Story story = new Models.Story();
         foreach (Models.StoryBlock block in story.blockList)
         {
             if (block.id == id)
             {
                 return(View(block));
             }
         }
         return(RedirectToAction("Index", new { id = storyId, clgId = collageId }));
     }
     catch
     {
         return(RedirectToAction("Index", new { id = storyId, clgId = collageId }));
     }
 }
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         ViewBag.blockId   = id;
         ViewBag.collageId = collageId;
         ViewBag.storyId   = storyId;
         Models.Story story = new Models.Story();
         foreach (Models.StoryBlock block in story.blockList)
         {
             if (block.id == id)
             {
                 block.blockCaption = collection["BlockCaption"];
                 block.blockContent = collection["BlockContent"];
                 block.bolckOrder   = collection["bolckOrder"];
                 story.Edit(storyId, block);
                 break;
             }
         }
         return(RedirectToAction("Index", new { id = storyId, clgId = collageId }));
     }
     catch
     {
         return(View());
     }
 }
        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 async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Story = await _context.Stories
                    .Include(s => s.Collection).FirstOrDefaultAsync(m => m.ID == id);

            if (Story == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Story = await _context.Stories.FindAsync(id);

            if (Story != null)
            {
                _context.Stories.Remove(Story);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public ActionResult CreateStory([Bind(Include = "storyID,userName,title, body,postDate")] Models.Story story)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("SignIn", "Account"));
            }
            if (ModelState.IsValid)
            {
                story.postDate = DateTime.Now;
                story.userName = Session["username"].ToString();
                string tags = Request["tagsinput"].ToString();
                smokeFreeDB.Story.Add(story);
                smokeFreeDB.SaveChanges();
                smokeFreeDB.Entry(story).Reload();
                tagAccess.saveTags(tags, story.storyID);
                return(RedirectToAction("Stories"));
            }

            return(RedirectToAction("Stories"));
        }
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         Models.Story story = new Models.Story();
         foreach (Models.StoryBlock block in story.blockList)
         {
             if (block.id == id)
             {
                 story.blockList.Remove(block);
                 story.Delete(block, storyId);
                 break;
             }
         }
         return(RedirectToAction("Index", new { id = storyId, clgId = collageId }));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult Create(FormCollection collection)
        {
            Models.Collage collage = new Models.Collage();
            Models.Story   story   = new Models.Story();
            if (!doc.Element("collages").Elements("collage").Elements("story").Any())
            {
                story.id = 0;
            }
            else
            {
                story.id = (int)(from S in doc.Descendants("story")
                                 orderby(int) S.Element("id")
                                 descending
                                 select(int) S.Element("id")).FirstOrDefault() + 1;
            }
            story.storyCaption = collection["StoryCaption"];
            story.storyTime    = collection["StoryTime"];
            story.storyOrder   = collection["StoryOrder"];

            collage.Create(collageId, story);

            return(RedirectToAction("Index" + "/" + collageId));
        }
        public ActionResult Create(FormCollection collection)
        {
            Models.Collage collage = new Models.Collage();
            Models.Story story = new Models.Story();
            if (!doc.Element("collages").Elements("collage").Elements("story").Any())
            {
                story.id = 0;
            }
            else
            {
                story.id = (int)(from S in doc.Descendants("story")
                                   orderby (int)S.Element("id")
                                   descending
                                   select (int)S.Element("id")).FirstOrDefault() + 1;
            }
            story.storyCaption = collection["StoryCaption"];
            story.storyTime = collection["StoryTime"];
            story.storyOrder = collection["StoryOrder"];

            collage.Create(collageId, story);

            return RedirectToAction("Index"+"/"+collageId);
        }
        //----< 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 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());
        }
        public ActionResult Index(int id)
        {
            collageId = id;
            ViewBag.id = id;
            Models.Collage all = new Models.Collage();
            List<Models.Story> storyList = new List<Models.Story>();
            if (id == 0)
            {
                return View(all.storyList);
            }
            else
            {
                Models.Archive archive = new Models.Archive();

                List<int> styId = new List<int>();
                foreach (int a in archive.archiveList)
                {
                    string collection = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\StoryCollection.xml");
                    XDocument docu = XDocument.Load(collection);

                    var cos = from s in doc.Elements("collages").Elements("collage") select s;
                    foreach (var co in cos)
                    {
                        if (co.Element("id").Value == a.ToString())
                        {
                            var ids = from s in co.Elements("storyId") select s;
                            foreach (var sid in ids)
                            {
                                styId.Add(Int32.Parse(sid.Value));
                            }
                        }
                    }
                }
                var clgs = from collage in collection1.Element("collages")
                                .Elements("collage")
                           select collage;
                foreach (var clg in clgs)
                {

                    if (clg.Element("id").Value == id.ToString())
                    {
                        ViewBag.collageName = clg.Element("collageName").Value;
                        var styids = from story in clg.Elements("storyId")
                                  select story;
                        ViewBag.storyId = styids.First().Value;
                        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 c = new Models.Story();
                                        c.id = Int32.Parse(elem.Element("id").Value);
                                        c.storyCaption = elem.Element("storyCaption").Value;
                                        c.storyTime = elem.Element("storyTime").Value;
                                        c.storyOrder = elem.Element("storyOrder").Value;

                                        storyList.Add(c);
                                        foreach (int i in styId)
                                        {
                                            if (i == c.id)
                                            {
                                                storyList.Remove(c);
                                            }
                                        }
                                }
                            }
                        }

                        return View(storyList);
                    }
                }
            }
            return View();
        }
        public ActionResult Index(int id)
        {
            collageId  = id;
            ViewBag.id = id;
            Models.Collage      all       = new Models.Collage();
            List <Models.Story> storyList = new List <Models.Story>();

            if (id == 0)
            {
                return(View(all.storyList));
            }
            else
            {
                Models.Archive archive = new Models.Archive();

                List <int> styId = new List <int>();
                foreach (int a in archive.archiveList)
                {
                    string    collection = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\StoryCollection.xml");
                    XDocument docu       = XDocument.Load(collection);

                    var cos = from s in doc.Elements("collages").Elements("collage") select s;
                    foreach (var co in cos)
                    {
                        if (co.Element("id").Value == a.ToString())
                        {
                            var ids = from s in co.Elements("storyId") select s;
                            foreach (var sid in ids)
                            {
                                styId.Add(Int32.Parse(sid.Value));
                            }
                        }
                    }
                }
                var clgs = from collage in collection1.Element("collages")
                           .Elements("collage")
                           select collage;
                foreach (var clg in clgs)
                {
                    if (clg.Element("id").Value == id.ToString())
                    {
                        ViewBag.collageName = clg.Element("collageName").Value;
                        var styids = from story in clg.Elements("storyId")
                                     select story;
                        ViewBag.storyId = styids.First().Value;
                        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 c = new Models.Story();
                                    c.id           = Int32.Parse(elem.Element("id").Value);
                                    c.storyCaption = elem.Element("storyCaption").Value;
                                    c.storyTime    = elem.Element("storyTime").Value;
                                    c.storyOrder   = elem.Element("storyOrder").Value;

                                    storyList.Add(c);
                                    foreach (int i in styId)
                                    {
                                        if (i == c.id)
                                        {
                                            storyList.Remove(c);
                                        }
                                    }
                                }
                            }
                        }


                        return(View(storyList));
                    }
                }
            }
            return(View());
        }
 public ActionResult Delete(int id)
 {
     try
     {
         ViewBag.collageId = collageId;
         ViewBag.blockId = id;
         ViewBag.storyId = storyId;
         Models.Story story = new Models.Story();
         foreach (Models.StoryBlock block in story.blockList)
         {
             if (block.id == id)
             {
                 return View(block);
             }
         }
         return RedirectToAction("Index", new { id = storyId, clgId = collageId });
     }
     catch
     {
         return RedirectToAction("Index", new { id = storyId, clgId = collageId });
     }
 }
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         ViewBag.blockId = id;
         ViewBag.collageId = collageId;
         ViewBag.storyId = storyId;
         Models.Story story = new Models.Story();
         foreach (Models.StoryBlock block in story.blockList)
         {
             if (block.id == id)
             {
                 block.blockCaption = collection["BlockCaption"];
                 block.blockContent = collection["BlockContent"];
                 block.bolckOrder = collection["bolckOrder"];
                 story.Edit(storyId, block);
                 break;
             }
         }
         return RedirectToAction("Index", new { id = storyId, clgId = collageId });
     }
     catch
     {
         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();
        }
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         Models.Story story = new Models.Story();
         foreach (Models.StoryBlock block in story.blockList)
         {
             if (block.id == id)
             {
                 story.blockList.Remove(block);
                 story.Delete(block, storyId);
                 break;
             }
         }
         return RedirectToAction("Index", new { id = storyId, clgId = collageId });
     }
     catch
     {
         return View();
     }
 }
        //
        // GET: /PrepDownload/
        public FilePathResult Index(int collageId, string api = "")
        {
            string path = System.Web.HttpContext.Current.Server.MapPath("~\\Img\\");

            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();
            stories = new List <Models.Story>();
            if (collageId == 0) //all stories
            {
                stories = c.storyList;
            }
            else
            {
                List <Models.Story> storyList = new List <Models.Story>();
                // choose stories in collage and add to List
                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;
                    }
                }
            }

            List <string> zipFiles = new List <string>();

            foreach (Models.Story story in stories)
            {
                string htmlcontent = htmlBuilder(story);

                using (FileStream fs = new FileStream(path + story.id + "\\" + story.storyCaption + ".html", FileMode.Create))
                {
                    using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
                    {
                        w.WriteLine(htmlcontent);
                    }
                }

                string        storyFolder = path + story.id;
                DirectoryInfo dir         = new DirectoryInfo(storyFolder);
                foreach (FileInfo f in dir.GetFiles())
                {
                    zipFiles.Add(f.FullName);
                }
            }
            if (api == "api")
            {
                FileZipper.ZipFiles(zipFiles.ToArray(), path + "collage\\" + collageId + ".zip");
                return(null);
            }
            else if (api == "archive")
            {
                FileZipper.ZipFiles(zipFiles.ToArray(), path + "archive\\" + collageId + ".zip");
                return(Archive(collageId));
            }
            else
            {
                FileZipper.ZipFiles(zipFiles.ToArray(), path + "collage\\" + collageId + ".zip");
                return(Download(collageId));
            }
        }
        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: /PrepDownload/
        public FilePathResult Index(int collageId, string api="")
        {
            string path = System.Web.HttpContext.Current.Server.MapPath("~\\Img\\");

            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();
            stories = new List<Models.Story>();
            if (collageId == 0) //all stories
            {
                stories = c.storyList;
            }
            else
            {
                List<Models.Story> storyList = new List<Models.Story>();
                // choose stories in collage and add to List
                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;
                    }
                }
            }

            List<string> zipFiles = new List<string>();
            foreach (Models.Story story in stories)
            {
                string htmlcontent = htmlBuilder(story);

                using (FileStream fs = new FileStream(path+story.id+"\\"+story.storyCaption+".html", FileMode.Create))
                {
                    using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
                    {
                        w.WriteLine(htmlcontent);
                    }
                }

                string storyFolder = path + story.id;
                DirectoryInfo dir = new DirectoryInfo(storyFolder);
                foreach (FileInfo f in dir.GetFiles())
                {
                    zipFiles.Add(f.FullName);
                }

            }
            if (api == "api")
            {
                FileZipper.ZipFiles(zipFiles.ToArray(), path + "collage\\" + collageId + ".zip");
                return null;
            }
            else if (api == "archive")
            {
                FileZipper.ZipFiles(zipFiles.ToArray(), path + "archive\\" + collageId + ".zip");
                return Archive(collageId);
            }
            else {
                FileZipper.ZipFiles(zipFiles.ToArray(), path + "collage\\" + collageId + ".zip");
                return Download(collageId);
            }
        }
        //----< 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;
        }