Exemple #1
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();
     }
 }
        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();
            }
        }