Exemple #1
0
 public bool Create(Course course)
 {
     try
     {
         DbContext.Course.Add(course);
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #2
0
 public bool Create(Question newQuestion)
 {
     try
     {
         DbContext.Question.Add(newQuestion);
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #3
0
        public void Delete(actor ator)
        {
            using (var db = new SakilaContext())
            //Como não há concorrência nas modificações, não é necessário criar um contexto transacional.
            //using (var transacao = db.Database.BeginTransaction())
            {
                try
                {
                    db.films_actors.RemoveRange(ator.films_actors);
                    db.actors.Remove(ator);

                    db.SaveChanges();
                    //transacao.Commit();
                }
                catch
                {
                    //transacao.Rollback();
                    //tratar exceção e gravar no log além de fechar a transação
                    throw;
                }

/*                 finally
 *              {
 *                  transacao.Dispose();
 *              };
 */         }
        }
Exemple #4
0
 public void Update(actor ator)
 {
     using (var db = new SakilaContext())
     {
         db.actors.Update(ator);
         db.SaveChanges();
     }
 }
Exemple #5
0
 public void Insert(actor ator)
 {
     using (var db = new SakilaContext())
     {
         db.actors.Add(ator);
         db.SaveChanges();
     }
 }
Exemple #6
0
 public void Incluir(film filme)
 {
     using (var db = new SakilaContext())
     {
         db.films.Add(filme);
         db.SaveChanges();
     }
 }
Exemple #7
0
 public bool CreateCoursePermission(Guid userId, Guid courseId, bool writePermission, bool authorizePermission, bool join)
 {
     try
     {
         DbContext.CoursePermission.Add(new CoursePermission
         {
             UserId    = userId,
             CourseId  = courseId,
             Write     = writePermission,
             Authorize = authorizePermission,
             Join      = join
         });
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool CreateChapter(Chapter chapter)
 {
     try
     {
         DbContext.Chapter.Add(chapter);
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #9
0
    static void Main(string[] args)
    {
        SakilaContext sakila       = new SakilaContext();
        Film          war1917      = new Film("1917", "2019 War Drama By Director Sam Mendes", "2019", 3, 5.99m, 179, 19.99m, "R");
        Film          joker        = new Film("Joker", "Oscar-Nominated SuperHero Drama", "2019", 3, 6.99m, 182, 23.99m, "R");
        Film          jarjarAbrams = new Film("Star Wars: The Rise of SkyWalker", "Trash Disney Fanfic", "2019", 3, 4.99m, 202, 21.99m, "PG-13");

        sakila.Film.Add(war1917);
        sakila.Film.Add(joker);
        sakila.Film.Add(jarjarAbrams);
        sakila.SaveChanges();



        Film[] allfilms = sakila.Film.ToArray();

        var newfilms = allfilms.Where(x => x.release_year == "2019");

        StringBuilder html = new StringBuilder();

        html.Append("<html>\n");
        html.Append("  <head>");
        html.Append("    <title>Sakila New Films</title>\n");
        html.Append("  </head>\n");
        html.Append("  <body\n");
        html.Append("    <h1> New Films Coming Soon! </h1>\n");
        html.Append("      <ul>\n");
        foreach (var film in newfilms)
        {
            html.Append("<li>");
            html.Append(film.title + " " + film.description);
            html.Append("</li>");
        }


        html.Append("      </ul>\n");
        html.Append("  </body>\n");
        html.Append("</html>\n");

        string htmlFile = "D:\\output\\newfilms.html";

        File.WriteAllText(htmlFile, html.ToString());
    }
Exemple #10
0
 public User Create(string username, string password)
 {
     try
     {
         User user = new User
         {
             Id          = Guid.NewGuid(),
             Username    = username,
             Password    = password,
             DateCreated = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")
         };
         DbContext.User.Add(user);
         DbContext.SaveChanges();
         return(user);
     }
     catch (Exception)
     {
         return(null);
     }
 }