Esempio n. 1
0
        public CrashCourseDomain Save(CrashCourseDomain crashCourse)
        {
            var model = CrashCourseModel.From(crashCourse);

            using (var connection = new SqliteConnection(_configuration.GetConnectionString("cnx")))
            {
                connection.Open();

                var row = connection.Execute($"UPDATE {_tableName} SET description = @Description, title = @Title, solution = @Solution, closedAt = @ClosedAt WHERE id = @Id;", model);
            }

            return(model.To());
        }
Esempio n. 2
0
        public CrashCourseDomain Save(CrashCourseDomain crashCourse)
        {
            var model = CrashCourseModel.From(crashCourse);

            using (var dbContext = new CrashCourseDBContext(_configuration.GetConnectionString("cnx")))
            {
                dbContext.Database.EnsureCreated();

                dbContext.Entry(model).State = EntityState.Modified;

                dbContext.Update(model);

                dbContext.SaveChanges();
            }

            return(model.To());
        }
Esempio n. 3
0
        public CrashCourseDomain Add(string title, string description)
        {
            var model = new CrashCourseModel
            {
                Title       = title,
                Description = description,
                CreatedAt   = _clockService.Now
            };

            using (var connection = new SqliteConnection(_configuration.GetConnectionString("cnx")))
            {
                connection.Open();

                var row = connection.Execute($"INSERT INTO {_tableName} (title, description, createdAt) Values (@Title, @Description, @CreatedAt);", model);
            }

            return(model.To());
        }
Esempio n. 4
0
        public CrashCourseDomain Add(string title, string description)
        {
            var model = new CrashCourseModel
            {
                Title       = title,
                Description = description,
                CreatedAt   = _clockService.Now
            };

            // At the end of the bracket DOTNET will
            // dispose the connection automaticly
            using (var dbContext = new CrashCourseDBContext(_configuration.GetConnectionString("cnx")))
            {
                dbContext.Database.EnsureCreated();

                dbContext.Add(model);

                dbContext.SaveChanges();
            }

            return(model.To());
        }