public void Delete(T item)
 {
     using (var db = new FirebirdDb())
     {
         db.Delete(item);
     }
 }
 public void Create(T item)
 {
     using (var db = new FirebirdDb())
     {
         db.Insert(item);
     }
 }
 public void Update(T item)
 {
     using (var db = new FirebirdDb())
     {
         db.Update(item);
     }
 }
        public override List <LabProgress> GetAll(Func <ITable <LabProgress>, IEnumerable <LabProgress> > filter = null)
        {
            if (filter != null)
            {
                throw new NotImplementedException();
            }

            using (var db = new FirebirdDb())
            {
                var table = db.GetTable <Student>()
                            .InnerJoin(db.GetTable <Lab>(),
                                       (student, lab) => student.Subgroup.Group.SpecialityId == lab.Discipline.SpecialityId,
                                       (student, lab) => new LabProgress
                {
                    Student      = student,
                    Lab          = lab,
                    Discipline   = lab.Discipline,
                    LabId        = lab.Id,
                    StudentId    = student.Id,
                    DisciplineId = lab.DisciplineId
                }).LeftJoin(db.GetTable <Work>(),
                            (progress, work) => work.SubGroupId == progress.Student.SubGroupId &&
                            progress.DisciplineId == work.DisciplineId,
                            (progress, work) => new LabProgress
                {
                    Student      = progress.Student,
                    Lab          = progress.Lab,
                    Discipline   = progress.Discipline,
                    Teacher      = work.Teacher,
                    LabId        = progress.LabId,
                    StudentId    = progress.StudentId,
                    DisciplineId = progress.DisciplineId,
                    TeacherId    = work.TeacherId
                }).LeftJoin(db.GetTable <LabProgress>(), (localProgress, labProgress) =>
                            localProgress.DisciplineId == labProgress.DisciplineId &&
                            localProgress.StudentId == labProgress.StudentId &&
                            localProgress.TeacherId == labProgress.TeacherId &&
                            localProgress.LabId == labProgress.LabId,
                            (localProgress, labProgress) => new LabProgress
                {
                    Id           = labProgress.Id,
                    Student      = localProgress.Student,
                    Lab          = localProgress.Lab,
                    Discipline   = localProgress.Discipline,
                    Teacher      = localProgress.Teacher,
                    LabId        = localProgress.LabId,
                    StudentId    = localProgress.StudentId,
                    DisciplineId = localProgress.DisciplineId,
                    TeacherId    = localProgress.TeacherId,
                    LabStatus    = labProgress.LabStatus ?? LabStatus.NotComplete.ToString()
                })
                            .ToList();
                LastQuery = db.LastQuery;
                return(table);
            }
        }
Beispiel #5
0
        public StatusCodeResult Post(User user)
        {
            using (var db = new FirebirdDb())
            {
                if (db.GetTable <User>().FirstOrDefault(u => u.Username == user.Username) != null)
                {
                    return(new StatusCodeResult(StatusCodes.Status200OK));
                }
            }

            return(new StatusCodeResult(StatusCodes.Status205ResetContent));
        }
        public virtual T Get(int id, Func <ITable <T>, IEnumerable <T> > predicate = null)
        {
            using (var db = new FirebirdDb())
            {
                var table  = db.GetTable <T>();
                var result = predicate != null
                    ? predicate.Invoke(table).FirstOrDefault(faculty => faculty.Id == id)
                    : db.GetTable <T>().FirstOrDefault(faculty => faculty.Id == id);

                LastQuery = db.LastQuery;
                return(result);
            }
        }
        public virtual List <T> GetAll(Func <ITable <T>, IEnumerable <T> > filter = null)
        {
            using (var db = new FirebirdDb())
            {
                var table  = db.GetTable <T>();
                var result = filter != null
                    ? filter.Invoke(table).ToList()
                    : table.ToList();

                LastQuery = db.LastQuery;
                return(result);
            }
        }
Beispiel #8
0
        public StatusCodeResult Post(User user)
        {
            try
            {
                using (var db = new FirebirdDb())
                {
                    db.Insert(user);
                }

                return(new StatusCodeResult(StatusCodes.Status201Created));
            }
            catch
            {
                return(new StatusCodeResult(StatusCodes.Status205ResetContent));
            }
        }
        public async Task <IActionResult> Register(RegistrationTeacher user, string returnUrl)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                using (var db = new FirebirdDb())
                {
                    if (UnitOfWork.Teachers.GetAll().Any(u => u.Username.Equals(user.Username)))
                    {
                        ModelState.AddModelError(string.Empty,
                                                 $"Пользователь с именем {user.Username} уже зарегистрирован.");
                        return(View());
                    }

                    user.Role = user.Username == "Admin" ? Teacher.AdminRole : Teacher.UndefinedRole;
                    user.Id   = db.InsertWithInt32Identity(user);
                }

                await Authenticate(user);

                if (returnUrl.IsNullOrEmpty())
                {
                    return(RedirectToAction("Index", "Main"));
                }

                return(Redirect(returnUrl));
            }
            catch (Exception)
            {
                ModelState.AddModelError(string.Empty,
                                         $"Не удалось зарегистрироваться.");
                return(View());
            }
        }
Beispiel #10
0
        public List <DisciplineStudy> GetAll(int studentId)
        {
            using (var db = new FirebirdDb())
            {
                var table = db.GetTable <Student>()
                            .LoadWith(student => student.Subgroup.Group.Speciality)
                            .Where(student => student.Id == studentId)
                            .InnerJoin(db.GetTable <Lab>(),
                                       (student, lab) => student.Subgroup.Group.SpecialityId == lab.Discipline.SpecialityId,
                                       (student, lab) => new LabProgress
                {
                    Student      = student,
                    Lab          = lab,
                    Discipline   = lab.Discipline,
                    LabId        = lab.Id,
                    StudentId    = student.Id,
                    DisciplineId = lab.DisciplineId
                }).LeftJoin(db.GetTable <Work>(),
                            (progress, work) => work.SubGroupId == progress.Student.SubGroupId &&
                            progress.DisciplineId == work.DisciplineId,
                            (progress, work) => new LabProgress
                {
                    Student      = progress.Student,
                    Lab          = progress.Lab,
                    Discipline   = progress.Discipline,
                    Teacher      = work.Teacher,
                    LabId        = progress.LabId,
                    StudentId    = progress.StudentId,
                    DisciplineId = progress.DisciplineId,
                    TeacherId    = work.TeacherId
                }).LeftJoin(db.GetTable <LabProgress>(), (localProgress, labProgress) =>
                            localProgress.DisciplineId == labProgress.DisciplineId &&
                            localProgress.StudentId == labProgress.StudentId &&
                            localProgress.TeacherId == labProgress.TeacherId &&
                            localProgress.LabId == labProgress.LabId,
                            (localProgress, labProgress) => new LabProgress
                {
                    Id           = labProgress.Id,
                    Student      = localProgress.Student,
                    Lab          = localProgress.Lab,
                    Discipline   = localProgress.Discipline,
                    Teacher      = localProgress.Teacher,
                    LabId        = localProgress.LabId,
                    StudentId    = localProgress.StudentId,
                    DisciplineId = localProgress.DisciplineId,
                    TeacherId    = localProgress.TeacherId,
                    LabStatus    = labProgress.LabStatus ?? LabStatus.NotComplete.ToString()
                }).GroupBy(progress => progress.DisciplineId, progress => progress)
                            .Select(gr => new DisciplineStudy
                {
                    StudentId      = gr.Key,
                    StudentName    = gr.First().StudentName,
                    Coors          = gr.First().Student.Course,
                    SpecialityId   = gr.First().Student.Subgroup.Group.SpecialityId,
                    GroupNumber    = gr.First().Student.GroupNumber,
                    SubgroupNumber = gr.First().Student.SubgroupNumber,
                    SubgroupId     = gr.First().Student.SubGroupId,
                    Discipline     = gr.First().DisciplineName,
                    Completed      = gr.Count(labProgress => labProgress.LabStatus == LabStatus.Complete.ToString()),
                    AllLabs        = gr.Count(labProgress => labProgress.DisciplineId == gr.Key)
                })
                            .ToList();

                LastQuery = db.LastQuery;
                return(table);
            }
        }