public ActionResult Create([Bind(Include = "Id,CourseId,StudentId,Durtation,StartDate,EndDate,HolidayStartDay,HolidayEndDate")] CourseList courseList)
        {
            var  dates   = db.CorsesList.Where(cl => cl.StudentId == courseList.StudentId).Select(x => new { x.StartDate, x.EndDate }).ToList();
            bool isValid = true;

            if (dates != null)
            {
                dates.ForEach(date => {
                    if (courseList.StartDate < date.EndDate && date.StartDate < courseList.EndDate)
                    {
                        isValid = false;
                    }
                });
            }


            if (isValid == false)
            {
                ViewBag.ErroMessage = "You have course on this dates. Choose another!";
                ViewBag.CourseId    = new SelectList(db.Corses, "Id", "CourseName", courseList.CourseId);
                ViewBag.StudentId   = new SelectList(db.Students, "Id", "FullName", courseList.StudentId);
                return(View(courseList));
            }

            if (ModelState.IsValid)
            {
                db.CorsesList.Add(courseList);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CourseId  = new SelectList(db.Corses, "Id", "CourseName", courseList.CourseId);
            ViewBag.StudentId = new SelectList(db.Students, "Id", "FullName", courseList.StudentId);
            return(View(courseList));
        }
        public IHttpActionResult PutStudent(int id, Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != student.Id)
            {
                return(BadRequest());
            }

            db.Entry(student).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public JsonResult Insert(Enrollment enrollment)
        {
            Student studentFound = db.Students.Where(x => x.ID == enrollment.StudentID).FirstOrDefault();

            if (studentFound != null)
            {
                enrollment.Student = studentFound;
            }
            Course CourseFound = db.Courses.Where(x => x.CourseID == enrollment.CoursesID).FirstOrDefault();

            if (CourseFound != null)
            {
                enrollment.Courses = CourseFound;
            }
            try
            {
                if (enrollment != null)
                {
                    db.Enrollment.Add(enrollment);
                    db.SaveChanges();
                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                return(Json(new { success = false }));
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var ctx = new StudentsContext("adress connect");

            var studs = ctx.Students.Where(x => x.Name.Length <= 7).ToList();

            foreach (var stud in studs)
            {
                Console.WriteLine($"Name : {stud.Name} {stud.ID}");

                foreach (var book in stud.Books)
                {
                    Console.WriteLine($"Book id {book.Id} name: {book.Name}");
                }
            }

            studs[0].Books.Add(new Book {
                Name = "Book1"
            });
            studs[0].Books.First().Name = "New Name";  ////good

            //  new Book { Name = "Name" }; //EntFrame ничего не знает о книгах в данній момент

            ctx.SaveChanges();


            var allStuds = GetAll();

            foreach (var stud in allStuds)
            {
                stud.Name = "Updated";
            }
            ctx.SaveChanges(); // ничего не происходит без него
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Student student = db.Students.Find(id);

            db.Students.Remove(student);
            db.SaveChanges();
            return(RedirectToAction("index"));
        }
        public IActionResult Post([FromBody]Student value)
        {
            if (value == null) return BadRequest();

            DB.Students.Add(value);
            DB.SaveChanges();

            return Ok(value);
        }
Beispiel #7
0
        public IActionResult CreateStudent(Student student)
        {
            student.IndexNumber = $"s{new Random().Next(1,10000)}";

            db.GetStudents.Add(student);
            db.SaveChanges();

            return(Ok(student));
        }
Beispiel #8
0
        public IActionResult AddRoom()
        {
            MeetingRoom meetingRoom = new MeetingRoom {
            };

            db.MeetingRooms.Add(meetingRoom);
            db.SaveChanges();

            return(Ok(meetingRoom));
        }
        public ActionResult Create([Bind(Include = "id,FirstName,LastName,UserName,Password,Email")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public ActionResult StudentsCreate([Bind(Include = "Id,Acid,Year")] Student student)
        {
            if (ModelState.IsValid)
            {
                db4.Students.Add(student);
                db4.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public void DeleteStudent(int id)
        {
            var student = context.students.FirstOrDefault(s => s.StudentId == id);

            if (student == null)
            {
                return;
            }
            context.students.Remove(student);
            context.SaveChanges();
        }
Beispiel #12
0
        public ActionResult Create([Bind(Include = "Id,Name,LastName,BirthDate,Email,City")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
 public ActionResult CreateStudent(Student student)
 {
     if (student == null)
     {
         return(BadRequest());
     }
     db.Student.Add(student);
     db.SaveChanges();
     // Add student to db
     return(Created("", student));
 }
        public IActionResult Post([FromBody] MeetingRoom meetingRoom)
        {
            if (meetingRoom == null)
            {
                return(BadRequest());
            }

            db.MeetingRooms.Add(meetingRoom);
            db.SaveChanges();

            return(Ok(meetingRoom));
        }
        public IActionResult PostStudents(string name, int id)
        {
            var Students = new Students()
            {
                Student_Name = name,
                Group_Id     = id
            };

            _context.Add(Students);
            _context.SaveChanges();
            return(Ok("Created"));
        }
Beispiel #16
0
        public IActionResult Post([FromBody] DayOfBusy dayOfBusy)
        {
            if (db.DaysOfBusy.FirstOrDefault(x => x == dayOfBusy) != null)
            {
                return(BadRequest());
            }

            db.DaysOfBusy.Add(dayOfBusy);
            db.SaveChanges();

            return(Ok(dayOfBusy));
        }
Beispiel #17
0
        public static void UpdateTracking()
        {
            List <Department> departments = context.Departments.ToList();
            Department        update      = departments[1];

            update.Name = "Katedra za softversko inzenjerstvo";
            context.SaveChanges();
        }
        public async Task <IActionResult> UploadFile(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return(Content("file not selected"));
            }

            var path = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot",
                file.FileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            var jsonString = await System.IO.File.ReadAllTextAsync(path);

            var imprtedData = JsonConvert.DeserializeObject <List <Student> >(jsonString);

            foreach (var item in imprtedData)
            {
                _context.Add(item);
            }

            _context.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
        public void AddGrade(Grade grade)
        {
            using var db = new StudentsContext();

            db.Grades.Add(grade);
            db.SaveChanges();
        }
        private static void AddGrades(StudentsContext db)
        {
            var students = db.Students.ToList();
            var courses  = db.Courses.ToList();

            var random = new Random();

            foreach (var student in students)
            {
                foreach (var course in courses)
                {
                    db.Grades.Add(new Grade()
                    {
                        Id = Guid.NewGuid(), Mark = random.Next(3, 11), StudentId = student.Id, CourseId = course.Id
                    });

                    db.Grades.Add(new Grade()
                    {
                        Id = Guid.NewGuid(), Mark = random.Next(3, 11), StudentId = student.Id, CourseId = course.Id
                    });

                    db.Grades.Add(new Grade()
                    {
                        Id = Guid.NewGuid(), Mark = random.Next(3, 11), StudentId = student.Id, CourseId = course.Id
                    });
                }
            }

            db.SaveChanges();
        }
Beispiel #21
0
        public IEnumerable <Students> Insert()
        {
            var context  = new StudentsContext();
            var students = new List <Students>()
            {
                new Students()
                {
                    ID        = 5,
                    FirstName = "Julia",
                    LastName  = "Koval",
                    Email     = "*****@*****.**",
                    Phone     = "762859"
                },
                new Students()
                {
                }
            };
            var university = new University()
            {
                Name = "Politeh", Id = 3
            };
            var graduateSupervisor = new GraduateSupervisor()
            {
                LName = "kOVALCHYK", FName = "Boris", Id = 5
            };

            context.Students.AddRange(students);
            context.GraduateSupervisor.Add(graduateSupervisor);
            context.University.Add(university);

            context.SaveChanges();

            return(context.Students.ToList());
        }
Beispiel #22
0
        private static void ClearDb()
        {
            StudentsContext studentContext = new StudentsContext();

            DbSet <Mark> marks       = studentContext.Set <Mark>();
            List <Mark>  marksAsList = marks.ToList();

            foreach (Mark mark in marksAsList)
            {
                marks.Remove(mark);
            }

            DbSet <Student> students       = studentContext.Set <Student>();
            List <Student>  studentsAsList = studentContext.Set <Student>().ToList();

            foreach (Student student in studentsAsList)
            {
                students.Remove(student);
            }

            DbSet <School> schools       = studentContext.Set <School>();
            List <School>  schoolsAsList = schools.ToList();


            foreach (School school in schoolsAsList)
            {
                schools.Remove(school);
            }

            studentContext.SaveChanges();
        }
Beispiel #23
0
        public ActionResult Edit(Student student, int[] selectedCourses)
        {
            Student newStudent = db.Students.Find(student.Id);

            newStudent.Name    = student.Name;
            newStudent.Surname = student.Surname;

            newStudent.Courses.Clear();
            if (selectedCourses != null)
            {
                //получаем выбранные курсы
                foreach (var c in db.Courses.Where(co => selectedCourses.Contains(co.Id)))
                {
                    newStudent.Courses.Add(c);
                }
            }

            db.Entry(newStudent).State = EntityState.Modified;
            db.SaveChanges();
            SearchHelper.AddToIndex(new List <Student>()
            {
                student
            });
            return(RedirectToAction("Index"));
        }
Beispiel #24
0
 public ActionResult Create(Student student)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Students.Add(student);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (RetryLimitExceededException /* dex */)
     {
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(student));
 }
Beispiel #25
0
        public ActionResult Add(List <Student> students)
        {
            Student curStudent;

            foreach (var student in students)
            {
                curStudent = db.Students.Find(student);

                if (curStudent == null)
                {
                    return(HttpNotFound("Не найдена книга по ID " + student.Id));
                }

                db.Entry(curStudent).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(View("Index"));
        }
Beispiel #26
0
        public IActionResult CreateStudent(StudentDto studentDto)
        {
            var student = _context.Students.Add(new Student()
            {
                IndexNumber  = studentDto.IndexNumber,
                BirthDate    = studentDto.BirthDate,
                IdEnrollment = _context
                               .Enrollments
                               .Where(e => e.Study.Name == studentDto.StudyName && e.Semester == studentDto.Semester)
                               .Select(e => e.IdEnrollment)
                               .Single(),
                FirstName = studentDto.FirstName,
                LastName  = studentDto.LastName
            });

            _context.SaveChanges();

            return(Ok(student.Entity));
        }
Beispiel #27
0
 public IEnumerable <Students> DeleteStudentsById(int id)
 {
     using (var context = new StudentsContext())
     {
         var students = context.Students.Where(o => o.ID == id).FirstOrDefault();
         context.Students.Remove(students);
         context.SaveChanges();
         return(context.Students.ToList());
     }
 }
 public void Post([FromBody] Student student)
 {
     //var groups = _context.Groups.ToList();
     //if (groups.Count() > 0)
     //{
     //    var studentGroups = groups.Select(x => new StudentGroup { Group = x });
     //    student.StudentGroups = studentGroups.ToList();
     //}
     _context.Students.Add(student);
     _context.SaveChanges();
 }
Beispiel #29
0
        public static void UpdateSubjectWithDepartmentNoTracking()
        {
            List <Subject> subjectsWithDepartment = context.Subjects.Include(s => s.Department).ToList();

            using StudentsContext newcontext = new StudentsContext();
            Subject s = subjectsWithDepartment[0];

            s.Department.Name = "Department Update No Tracking";
            newcontext.Update(s);
            newcontext.SaveChanges();
        }
Beispiel #30
0
        public StudentsController(StudentsContext context)
        {
            db = context;

            if (!db.GetStudents.Any())
            {
                db.GetStudents.Add(new Student {
                    Name = "A", Surname = "B", IndexNumber = "s1236"
                });
                db.SaveChanges();
            }
        }
        public static void CreateSampleHomeworks(StudentsContext db)
        {
            var homework1 = new Homework
            {
                Content = "Study this",
                Student = db.Students.FirstOrDefault(x => x.Name == "Harry Potter"),
                Course = db.Courses.FirstOrDefault(x => x.Name == "Alchemy")

            };

            var homework2 = new Homework
            {
                Content = "Very easy",
                Student = db.Students.FirstOrDefault(x => x.Name == "Hermione"),
                Course = db.Courses.FirstOrDefault(x => x.Name == "Dark arts")
            };

            db.Homeworks.Add(homework1);
            db.Homeworks.Add(homework2);
            db.SaveChanges();
        }