Ejemplo n.º 1
0
        public async Task <IEnumerable <ClassDto> > Get(int SemesterId)
        {
            var results = new List <ClassDto>();

            using (var db = new AbetContext())
            {
                try
                {
                    results = await db.Classes.Where(s => s.SemesterId == SemesterId)
                              .Select(s =>
                                      new ClassDto {
                        Id         = s.Id,
                        SemesterId = s.SemesterId,
                        CourseCode = s.CourseCode,
                        CourseName = s.CourseName,
                        Instructor = s.Instructor,
                    }).ToListAsync();
                }
                catch (Exception e)
                {
                }
            }

            return(results);
        }
Ejemplo n.º 2
0
        public async Task <ClassDto> AddOrUpdate(ClassDto classDto)
        {
            using (var db = new AbetContext())
            {
                var c = new Class
                {
                    Id         = classDto.Id,
                    SemesterId = classDto.SemesterId,
                    CourseCode = classDto.CourseCode,
                    CourseName = classDto.CourseName,
                    Instructor = classDto.Instructor,
                };
                db.Classes.AddOrUpdate(c);
                await db.SaveChangesAsync();

                return(new ClassDto
                {
                    Id = c.Id,
                    SemesterId = c.SemesterId,
                    CourseCode = c.CourseCode,
                    CourseName = c.CourseName,
                    Instructor = c.Instructor
                });
            }
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <ReviewDto> > Get(int id)
        {
            var results = new List <ReviewDto>();

            using (var db = new AbetContext())
            {
                try
                {
                    results = await db.Reviews.Where(c => c.Id == id)
                              .Select(s =>
                                      new ReviewDto
                    {
                        Id         = s.Id,
                        Rating     = s.Rating,
                        ClassId    = s.ClassId,
                        ReviewText = s.ReviewText
                    }).ToListAsync();
                }
                catch (Exception e)
                {
                }
            }

            return(results);
        }
Ejemplo n.º 4
0
 public async Task <SemesterDto> GetById(int id)
 {
     using (var db = new AbetContext())
     {
         return(await db.Semesters.Where(s => s.Id == id)?.Take(1).Select(s => new SemesterDto {
             Id = s.Id, Name = s.Name
         }).FirstOrDefaultAsync());
     }
 }
Ejemplo n.º 5
0
        public async Task <Review> RemoveById(int id)
        {
            using (var db = new AbetContext())
            {
                var toRemove = db.Reviews.FirstOrDefault(s => s.Id == id);
                db.Reviews.Remove(toRemove);
                await db.SaveChangesAsync();

                return(toRemove);
            }
        }
Ejemplo n.º 6
0
 public async Task <IEnumerable <SemesterDto> > Search(string query)
 {
     using (var db = new AbetContext())
     {
         return(await db.Semesters
                .Where(s => s.Name.ToUpper().Contains(query.ToUpper()))
                .Select(s => new SemesterDto {
             Id = s.Id, Name = s.Name
         })
                .ToListAsync());
     }
 }
Ejemplo n.º 7
0
 public SemesterDto Remove(SemesterDto semesterDto)
 {
     using (var db = new AbetContext())
     {
         var result = db.Semesters.Remove(new Semester {
             Id = semesterDto.Id, Name = semesterDto.Name
         });
         db.SaveChanges();
         return(new SemesterDto {
             Id = result.Id, Name = result.Name
         });
     }
 }
Ejemplo n.º 8
0
        public async Task <ClassDto> Remove(int id)
        {
            using (var db = new AbetContext())
            {
                var c = db.Classes.FirstOrDefault(cl => cl.Id == id);
                db.Classes.Remove(c);
                await db.SaveChangesAsync();

                return(new ClassDto
                {
                    Id = c.Id,
                    SemesterId = c.SemesterId,
                    CourseCode = c.CourseCode,
                    CourseName = c.CourseName,
                    Instructor = c.Instructor
                });;
            }
        }
Ejemplo n.º 9
0
        public async Task <ReviewDto> AddOrUpdate(ReviewDto reviewDto)
        {
            using (var db = new AbetContext())
            {
                db.Reviews.AddOrUpdate(
                    new Review
                {
                    Id         = reviewDto.Id,
                    Rating     = reviewDto.Rating,
                    ClassId    = reviewDto.ClassId,
                    ReviewText = reviewDto.ReviewText
                });
                await db.SaveChangesAsync();
            }


            return(reviewDto);
        }
Ejemplo n.º 10
0
        public async Task <IEnumerable <SemesterDto> > Get()
        {
            var results = new List <SemesterDto>();

            using (var db = new AbetContext())
            {
                try
                {
                    results = await db.Semesters.Select(s => new SemesterDto {
                        Id = s.Id, Name = s.Name
                    }).ToListAsync();
                } catch (Exception e)
                {
                }
            }

            return(results);
        }
Ejemplo n.º 11
0
 public ReviewDto Remove(ReviewDto reviewDto)
 {
     using (var db = new AbetContext())
     {
         var result = db.Reviews.Remove(new Review
         {
             Id         = reviewDto.Id,
             Rating     = reviewDto.Rating,
             ClassId    = reviewDto.ClassId,
             ReviewText = reviewDto.ReviewText
         });
         db.SaveChanges();
         return(new ReviewDto
         {
             Id = result.Id,
             Rating = reviewDto.Rating,
             ClassId = reviewDto.ClassId,
             ReviewText = reviewDto.ReviewText
         });
     }
 }
Ejemplo n.º 12
0
 public async Task <ClassDto> Remove(ClassDto classDto)
 {
     using (var db = new AbetContext())
     {
         var result = db.Classes.Remove(new Class
         {
             Id         = classDto.Id,
             SemesterId = classDto.SemesterId,
             CourseCode = classDto.CourseCode,
             CourseName = classDto.CourseName,
             Instructor = classDto.Instructor
         });
         db.SaveChanges();
         return(new ClassDto {
             Id = result.Id,
             SemesterId = result.SemesterId,
             CourseCode = result.CourseCode,
             CourseName = result.CourseName,
             Instructor = result.Instructor
         });
     }
 }
Ejemplo n.º 13
0
        public async Task <SemesterDto> AddOrUpdate(SemesterDto semesterDto)
        {
            var newSemester = new Semester {
                Id = semesterDto.Id, Name = semesterDto.Name, LastModified = DateTime.Now
            };

            using (var db = new AbetContext())
            {
                try
                {
                    db.Semesters.AddOrUpdate(newSemester);
                    await db.SaveChangesAsync();
                } catch (Exception e)
                {
                }
            }


            return(new SemesterDto {
                Id = newSemester.Id, Name = newSemester.Name
            });
        }