Example #1
0
        public ActionResult Download(int id, string view)
        {
            PandaBase db = new PandaBase();

            //Calling the variables we need from the database tables.

            var subtitleLines = (from line in db.SubtitleLines
                                 where id == line.SubtitleID
                                 select line);

            var filename = (from title in db.Subtitles
                            where id == title.ID
                            select title.Title).SingleOrDefault();

            var language = (from lang in db.Subtitles
                            where id == lang.ID
                            select lang.Language).SingleOrDefault();


            //Building string in the right srt format.
            StringBuilder output = new StringBuilder();

            foreach (SubtitleLine line in subtitleLines)
            {
                int    indexInt = line.Index;
                string index    = indexInt.ToString();
                output.Append(index);
                output.Append("\r\n");
                string tcIn = line.TimeFrom.ToString();
                output.Append(tcIn);
                output.Append(" --> ");
                string tcOut = line.TimeTo.ToString();
                output.Append(tcOut);
                output.Append("\r\n");
                string onScreen = line.Text;
                output.Append(onScreen);
            }

            //Makes a string from the stringbuilder. Closing the string
            var finalOutput = output.ToString();

            //making the string that contains the filename and language.
            var finalname = filename + "_" + language + ".srt";

            //creating the file from the string.
            var byteArray = Encoding.UTF8.GetBytes(finalOutput);
            var stream    = new MemoryStream(byteArray);

            //return file to user.
            return(File(stream, "text/plain", finalname));
        }
Example #2
0
 public void UpdateSubtitleLine(int id, string text, string timeStart, string timeStop)
 {
     using (var context = new PandaBase())
     {
         // Locates a SubtitleLine in the database with
         // a given id
         SubtitleLine line = (context.SubtitleLines.Where(l => l.ID == id)
                              .FirstOrDefault <SubtitleLine>());
         // This adds two line breaks at the end of the text,
         // this is necessary for the .srt standard
         line.Text     = text + "\r\n" + "\r\n";
         line.TimeFrom = timeStart;
         line.TimeTo   = timeStop;
         // Marks the entry 'line' in the database as modified,
         // this way code-first knows it should update this entry in the database
         context.Entry(line).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #3
0
        public void Upvote(int id)
        {
            PandaBase panda = new PandaBase();

            //Tékkað á því hvort það sé til Upvote með þessari ákveðnu beiðni og notanda.
            //Ef 'true' þá er það ekki til og haldið er áfram.
            if (db.GetReqUpBool(id, db.GetUserByName(User.Identity.Name).ID))
            {
                // Find request with 'id' and raises upvote with 1
                Request req = panda.Requests.Single(re => re.ID == id);
                req.Upvotes++;

                // Adds a line to Upvoters table with the users ID and request ID
                Upvoter upvoter = new Upvoter()
                {
                    RequestID = id, UserID = db.GetUserByName(User.Identity.Name).ID
                };
                panda.Upvoters.Add(upvoter);

                panda.SaveChanges();
            }
        }