Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            //_context.Attach(CurriculumUnit).State = EntityState.Modified;
            var curUnit = _context.CurriculumUnits.FirstOrDefault(m => m.Id == CurriculumUnit.Id);

            curUnit.SemesterNumber   = CurriculumUnit.SemesterNumber;
            curUnit.SpecializationId = CurriculumUnit.SpecializationId;

            _context.CurriculumUnits.Update(curUnit);

            await _context.SaveChangesAsync();

            CurriculumUnit = await _context.CurriculumUnits
                             .Include(c => c.CurriculumSubjects)
                             .FirstOrDefaultAsync(m => m.Id == CurriculumUnit.Id);

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            for (int i = 0; i < CurriculumUnit.CurriculumSubjects.Count; i++)
            {
                if (!Input.Any(m => m.SubjectId == CurriculumUnit.CurriculumSubjects[i].SubjectId))
                {
                    CurriculumUnit.CurriculumSubjects.Remove(CurriculumUnit.CurriculumSubjects[i]);
                }
            }
            foreach (var elem in Input)
            {
                if (CurriculumUnit.CurriculumSubjects.Any(m => m.SubjectId == elem.SubjectId && m.QuantityAll != elem.QuatityOfHours))
                {
                    CurriculumUnit.CurriculumSubjects.FirstOrDefault(m => m.CurriculumId == elem.SubjectId).QuantityAll = elem.QuatityOfHours;
                }
                else if (!CurriculumUnit.CurriculumSubjects.Any(m => m.SubjectId == elem.SubjectId))
                {
                    CurriculumUnit.CurriculumSubjects.Add(new CurriculumSubject {
                        SubjectId = elem.SubjectId, QuantityAll = elem.QuatityOfHours
                    });
                }
            }
            //_context.Attach(CurriculumUnit).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CurriculumUnitExists(CurriculumUnit.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        //public IList<TeacherSubject> TeacherSubjects { get; set; }

        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Teachers.Add(Teacher);
            await _context.SaveChangesAsync();

            //Teacher = await _context.Teachers.FirstOrDefaultAsync(t => t.FullName == Teacher.FullName );
            //foreach (var elem in Subjects)
            //{
            //    if(elem.ForTeacher)
            //        TeacherSubjects.Add(new TeacherSubject() { SubjectId = elem.Id, TeacherId = Teacher.Id });
            //}
            // TeacherSubjects.AddRange(Subjects.Where(s => s.ForTeacher).Select(s => new TeacherSubject() { SubjectId = s.Id, TeacherId = Teacher.Id }));
            _context.TeacherSubject.AddRange(Subjects.Where(s => s.ForTeacher).Select(s => new TeacherSubject()
            {
                SubjectId = s.Id, TeacherId = Teacher.Id
            }));
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.CurriculumUnits.Add(CurriculumUnit);
            await _context.SaveChangesAsync();

            List <CurriculumSubject> curSubjts = new List <CurriculumSubject>();

            foreach (var elem in Input)
            {
                if (elem.SubjectId?.Id != 0 && elem.QuatityOfHours != 0)
                {
                    curSubjts.Add(new CurriculumSubject {
                        CurriculumId = CurriculumUnit.Id, SubjectId = elem.SubjectId.Id, QuantityAll = elem.QuatityOfHours
                    });
                }
            }
            _context.CurriculumSubjects.AddRange(curSubjts);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Group).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupExists(Group.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 5
0
        public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

            _context.Subjects.Add(Subject);
            await _context.SaveChangesAsync();

            return RedirectToPage("./Index");
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Groups.Add(Group);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            TeacherSubjects = await _context.TeacherSubject
                              .Where(ts => ts.TeacherId == Teacher.Id).ToListAsync();

            _context.Attach(Teacher).State = EntityState.Modified;

            _context.TeacherSubject.AddRange(Subjects.Where(s => s.ForTeacher && !TeacherSubjects.Any(t => t.SubjectId == s.Id))
                                             .Select(q => new TeacherSubject {
                SubjectId = q.Id, TeacherId = Teacher.Id
            }));
            List <TeacherSubject> lst = new List <TeacherSubject>();

            for (int i = 0; i < Subjects.Count; i++)
            {
                if (!Subjects[i].ForTeacher && TeacherSubjects.Any(t => t.SubjectId == Subjects[i].Id))
                {
                    lst.Add(TeacherSubjects.FirstOrDefault(t => t.TeacherId == Teacher.Id && t.SubjectId == Subjects[i].Id));
                }
            }
            _context.TeacherSubject.RemoveRange(lst);
            //_context.TeacherSubject.RemoveRange(Subjects.Where(s => !s.ForTeacher && TeacherSubjects.Any(t => t.SubjectId == s.Id))
            //    .Select(s => TeacherSubjects.Where(t => t.SubjectId == s.Id && t.TeacherId == Teacher.Id)));
            //var lst = (IEnumerable<TeacherSubject>)TeacherSubjects
            //    .Select(t => Subjects.Where(s => s.Id != t.SubjectId && s.ForTeacher));
            //_context.TeacherSubject.RemoveRange(lst);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeacherExists(Teacher.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Subject = await _context.Subjects.FindAsync(id);

            if (Subject != null)
            {
                _context.Subjects.Remove(Subject);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Specialization = await _context.Specializations.FindAsync(id);

            if (Specialization != null)
            {
                _context.Specializations.Remove(Specialization);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Teacher = await _context.Teachers.FindAsync(id);

            if (Teacher != null)
            {
                _context.Teachers.Remove(Teacher);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CurriculumUnit = await _context.CurriculumUnits.FindAsync(id);

            if (CurriculumUnit != null)
            {
                _context.CurriculumUnits.Remove(CurriculumUnit);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (_context.Rooms.ToList().Any(r => r.Number == Room.Number))
            {
                ModelState.AddModelError("Room.Number", "Аудитория с таким номером уже существует");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Rooms.Add(Room);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Room = await _context.Rooms.FindAsync(id);

            if (Room != null)
            {
                _context.Rooms.Remove(Room);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            //var parentSpec = await _context.Specializations.FirstOrDefaultAsync(x => x.Id == Specialization.ParentSpec.Id);
            //Specialization.ParentSpec = parentSpec;

            var local = _context.Set <Specialization>()
                        .Local
                        .FirstOrDefault(entry => entry.Id.Equals(Specialization.Id));

            // check if local is not null
            if (local != null) // I'm using a extension method
            {
                // detach
                _context.Entry(local).State = EntityState.Detached;
            }
            // set Modified flag in your entry
            _context.Entry(Specialization).State = EntityState.Modified;

            // save
            _context.SaveChanges();

            //_context.Attach(Specialization).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpecializationExists(Specialization.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }