Esempio n. 1
0
        public IEnumerable <CrashCourseDomain> GetAll()
        {
            using (var dbContext = new CrashCourseDBContext(_configuration.GetConnectionString("cnx")))
            {
                dbContext.Database.EnsureCreated();

                return(dbContext.CrashCourses.ToList().Select(x => x.To()));
            }
        }
Esempio n. 2
0
        public CrashCourseDomain GetById(long id)
        {
            using (var dbContext = new CrashCourseDBContext(_configuration.GetConnectionString("cnx")))
            {
                dbContext.Database.EnsureCreated();

                return(dbContext.CrashCourses.Find(id).To());
            }
        }
Esempio n. 3
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. 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());
        }