Esempio n. 1
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. 2
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());
        }