Esempio n. 1
0
 public async Task <DtoCourse> GetCourse(int courseId)
 {
     try
     {
         using (var data = Context)
             return(CourseConverter.DataAccsessToDto(await(from item in data.Courses where item.id == courseId select item).FirstOrDefaultAsync()));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 2
0
        public async Task <ObservableCollection <DtoCourse> > GetCourses(string filter = null)
        {
            var ret = new ObservableCollection <DtoCourse>();

            using (var data = Context)
            {
                if (!string.IsNullOrWhiteSpace(filter))
                {
                    foreach (var item in await(from item in data.Courses where item.name.Contains(filter) select item).ToListAsync())
                    {
                        ret.Add(CourseConverter.DataAccsessToDto(item));
                    }
                }
                else
                {
                    foreach (var item in await(from item in data.Courses select item).ToListAsync())
                    {
                        ret.Add(CourseConverter.DataAccsessToDto(item));
                    }
                }
                return(ret);
            }
        }