public void UpdateFacultyWithUniversity(Faculty faculty, short universityId)
        {
            var universityFaculty = _context.UniversityFaculties.FirstOrDefault(uf => uf.FacultyId == faculty.Id);

            if (universityFaculty != null)
            {
                _context.Entry(faculty).State           = EntityState.Modified;
                _context.Entry(universityFaculty).State = EntityState.Deleted;

                var newUniversityFaculty = new UniversityFaculty
                {
                    FacultyId    = faculty.Id,
                    UniversityId = universityId
                };

                _context.UniversityFaculties.Add(newUniversityFaculty);
            }
            else
            {
                _context.Entry(faculty).State = EntityState.Modified;
                _context.Entry(new UniversityFaculty {
                    FacultyId = faculty.Id, UniversityId = universityId
                }).State = EntityState.Added;
            }

            _context.SaveChanges();
        }
        public void CreateFacultyWithUniversity(Faculty faculty, short universityId)
        {
            _context.Faculties.Add(faculty);

            var universityFaculty = new UniversityFaculty
            {
                FacultyId    = faculty.Id,
                UniversityId = universityId
            };

            _context.UniversityFaculties.Add(universityFaculty);

            _context.SaveChanges();
        }
예제 #3
0
        public static UniversityFaculty GetFaculty(int id)
        {
            UniversityFaculty f1 = ctx.Faculties.First(f => f.Id == id);

            return(f1);
        }