예제 #1
0
 public bool AddStudentToSection(StudentSectionModel model, ref string errorMessage)
 {
     using (SZPNUWContext context = new SZPNUWContext())
     {
         Sections section = context.Sections.Where(x => x.Id == model.SectionId).FirstOrDefault();
         if (section != null)
         {
             bool result = (from ss in context.Studentssections
                            join s in context.Sections on ss.Sectionid equals s.Id
                            where s.Subcjetsemesterid == section.Subcjetsemesterid && ss.Studentid == model.StudentId
                            select ss).Any();
             if (!result)
             {
                 Studentssections studSec = new Studentssections()
                 {
                     Sectionid = model.SectionId,
                     Studentid = model.StudentId.Value
                 };
                 context.Studentssections.Add(studSec);
                 context.SaveChanges();
                 return(true);
             }
         }
         errorMessage = PortalMessages.CanNotAddStudentToSection;
         return(false);
     }
 }
예제 #2
0
 public bool UpdateStudentSection(StudentSectionModel model, ref string errorMessage)
 {
     using (SZPNUWContext context = new SZPNUWContext())
     {
         Studentssections studentSection = context.Studentssections.FirstOrDefault(x => x.Id == model.Id);
         if (studentSection != null)
         {
             studentSection.Rating      = model.Rate;
             studentSection.Dateofentry = model.Date;
             context.SaveChanges();
             return(true);
         }
         errorMessage = PortalMessages.NoSuchElement;
         return(false);
     }
 }
예제 #3
0
 public StudentSectionModel GetSectionStudent(int sectionId, int studentId)
 {
     using (SZPNUWContext context = new SZPNUWContext())
     {
         Studentssections studentSection = context.Studentssections
                                           .FirstOrDefault(x => x.Sectionid == sectionId && x.Studentid == studentId);
         if (studentSection != null)
         {
             return(new StudentSectionModel
             {
                 Id = studentSection.Id,
                 Date = studentSection.Dateofentry,
                 Rate = studentSection.Rating,
                 SectionId = studentSection.Sectionid,
                 StudentId = studentSection.Studentid
             });
         }
         return(null);
     }
 }
예제 #4
0
 public bool DeleteStudentFromSection(int studentId, int sectionId, ref string errorMessage)
 {
     using (SZPNUWContext context = new SZPNUWContext())
     {
         Studentssections section = context.Studentssections.FirstOrDefault(x => x.Sectionid == sectionId && x.Studentid == studentId);
         if (section != null)
         {
             try
             {
                 //context.Studentssections.Attach(section);
                 context.Studentssections.Remove(section);
                 context.SaveChanges();
                 return(true);
             }
             catch (Exception)
             {
                 errorMessage = PortalMessages.CanNotDeleteStudentFromSection;
                 return(false);
             }
         }
         errorMessage = PortalMessages.CanNotDeleteStudentFromSection;
         return(false);
     }
 }