Beispiel #1
0
        public async Task <T[]> Where <T>(Func <T, bool> predicate) where T : class
        {
            using MainContext _db = new MainContext();
            IEnumerable <T> result = _db.DbSet <T>().Where(predicate);

            return(await Task.Run(() => result.ToArray()));
        }
Beispiel #2
0
        public async Task <T> First <T>() where T : class
        {
            using MainContext _db = new MainContext();
            T result = _db.DbSet <T>().FirstOrDefault();

            return(await Task.Run(() => result));
        }
Beispiel #3
0
        public async Task <bool> RemoveGroup(Group obj)
        {
            try
            {
                using MainContext _db = new MainContext();

                var students = _db.DbSet <Student>().Where(e => e.Id == obj.Id).ToList();
                foreach (var student in students)
                {
                    _db.DbSet <Student>().Remove(student);
                }
                _db.Remove(obj);
                await _db.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #4
0
        public async void Change(int Id, Group obj)
        {
            using MainContext _db = new MainContext();
            var oldObj = _db.DbSet <Group>().Find(Id);

            oldObj.Key          = obj.Key;
            oldObj.HeadManId    = obj.HeadManId;
            oldObj.CuratorId    = obj.CuratorId;
            oldObj.StudyForm    = obj.StudyForm;
            oldObj.Notes        = obj.Notes;
            oldObj.EduFrom      = obj.EduFrom;
            oldObj.Speciality   = obj.Speciality;
            oldObj.DepartmentId = obj.DepartmentId;
            oldObj.EduLevel     = obj.EduLevel;
            oldObj.StudyForm    = obj.StudyForm;
            await _db.SaveChangesAsync();
        }
Beispiel #5
0
        public async void Change(int Id, Teacher teacher)
        {
            using MainContext _db = new MainContext();
            var old = _db.DbSet <Teacher>().Find(Id);

            old.AcademicDegree = teacher.AcademicDegree;
            old.AcademicTitle  = teacher.AcademicTitle;
            old.BirthDay       = teacher.BirthDay;
            old.DepartmentId   = teacher.DepartmentId;
            old.Email          = teacher.Email;
            old.Login          = teacher.Login;
            old.Name           = teacher.Name;
            old.Password       = teacher.Password;
            old.Patronymic     = teacher.Patronymic;
            old.PhoneNumber    = teacher.PhoneNumber;
            old.Role           = teacher.Role;
            old.Surname        = teacher.Surname;
            await _db.SaveChangesAsync();
        }
Beispiel #6
0
        public async void Change(Student newObj)
        {
            using MainContext _db = new MainContext();
            Student oldObj = _db.DbSet <Student>().Find(newObj.Id);

            oldObj.Address          = newObj.Address;
            oldObj.BB               = newObj.BB;
            oldObj.Name             = newObj.Name;
            oldObj.Note             = newObj.Note;
            oldObj.Birthday         = newObj.Birthday;
            oldObj.Contract         = newObj.Contract;
            oldObj.Email            = newObj.Email;
            oldObj.GroupId          = newObj.GroupId;
            oldObj.Img              = newObj.Img;
            oldObj.Patronymic       = newObj.Patronymic;
            oldObj.PhoneNumber      = newObj.PhoneNumber;
            oldObj.RecordBookNumber = newObj.RecordBookNumber;
            oldObj.Surname          = newObj.Surname;
            await _db.SaveChangesAsync();
        }
Beispiel #7
0
        public void Change(int Id, Department obj)
        {
            using MainContext _db = new MainContext();
            Department oldObj = _db.DbSet <Department>().Find(Id);

            if (oldObj != null)
            {
                if (obj.Name != null)
                {
                    oldObj.Name = obj.Name;
                }
                else if (obj.headOfDepId != 0)
                {
                    oldObj.headOfDepId = obj.headOfDepId;
                }
                else if (obj.Note != null)
                {
                    oldObj.Name = obj.Note;
                }
            }
            _db.SaveChangesAsync();
        }
Beispiel #8
0
 public async Task <bool> isContein <T>(T obj) where T : class
 {
     using MainContext _db = new MainContext();
     return(await Task.Run(() => _db.DbSet <T>().Where(e => e == obj).Any()));
 }
Beispiel #9
0
 public async Task <T> GetById <T>(int Id) where T : class
 {
     using MainContext _db = new MainContext();
     return(await Task.Run(() => _db.DbSet <T>().Find(Id)));
 }
Beispiel #10
0
 public async Task <T[]> Get <T>() where T : class
 {
     using MainContext _db = new MainContext();
     return(await Task.Run(() => _db.DbSet <T>().ToArray()));
 }