Esempio n. 1
0
        public string CreateTeacher(string teacherName, string teacherID, int courseID)
        {
            var teacher = new Teacher()
            {
                name     = teacherName,
                AUID     = teacherID,
                CourseID = courseID
            };

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    context.Add(teacher);
                    context.SaveChanges();
                    transaction.Commit();
                    return("Teacher have been added");
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return("Teacher could not be added. Teacher with this AUID already exists.");
                }
            }
        }
        public string CreateExercise(string lecture, int number, string where, bool open, string teacherID, string studentID, int courseID)
        {
            var exercise = new Exercise()
            {
                Lecture     = lecture,
                Number      = number,
                Help_Where  = where,
                Open        = open,
                TeacherAUID = teacherID,
                StudentAUID = studentID,
                CourseID    = courseID
            };

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    context.Add(exercise);
                    context.SaveChanges();
                    transaction.Commit();
                    return("Exercise have been added");
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return("Exercise could not be added.");
                }
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("SessionTimeId,SessionTime1,SessionTime2")] SessionTime sessionTime)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sessionTime);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(sessionTime));
        }
Esempio n. 4
0
      public async Task <IActionResult> Create([Bind("MountainId,MountainName,Elevation,Difficulty")] Mountain mountain)
      {
          if (ModelState.IsValid)
          {
              _context.Add(mountain);
              await _context.SaveChangesAsync();

              return(RedirectToAction(nameof(Index)));
          }
          return(View(mountain));
      }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("CompanyId,CompanyName,CompanyCeo,CompanyAge")] Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(company));
        }
        public async Task <IActionResult> Create([Bind("MovieId,ImageUrl,LongDescription,Price,ShortDescription,Title")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(movie));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("Title,CompanyId,AgeRestriction,Price,CustomerName")] Games games)
        {
            if (ModelState.IsValid)
            {
                _context.Add(games);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(games));
        }
Esempio n. 8
0
        public async Task <IActionResult> Create([Bind("CineplexId,ImageUrl,Location,LongDescription,ShortDescription")] Cineplex cineplex)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cineplex);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(cineplex));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create([Bind("HikeId,MountainName,MountainId,DateHiked,TimeToSummit")] HikeLog hikeLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hikeLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MountainId"]   = new SelectList(_context.Mountain, "MountainId", "MountainName", hikeLog.MountainId);
            ViewData["MountainName"] = new SelectList(_context.Mountain, "MountainName", "MountainName", hikeLog.MountainName);
            return(View(hikeLog));
        }
Esempio n. 10
0
        public async Task <IActionResult> Create([Bind("CustomerName,Title,CompanyId")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompanyId"] = new SelectList(_context.Company, "CompanyId", "CompanyId", customer.CompanyId);
            ViewData["Title"]     = new SelectList(_context.Games, "Title", "Title", customer.Title);
            return(View(customer));
        }
Esempio n. 11
0
        public string CreateCourse(string courseName)
        {
            var course = new Course()
            {
                Name = courseName
            };

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    context.Add(course);
                    context.SaveChanges();
                    transaction.Commit();
                    return("Course have been added");
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return("Course could not be added. This combination of name and ID already exists");
                }
            }
        }
Esempio n. 12
0
        public async Task <IActionResult> Create([Bind("CineplexId,MovieId,SessionId")] CineplexMovie cineplexMovie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cineplexMovie);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["CineplexId"] = new SelectList(_context.Cineplex, "CineplexId", "Location", cineplexMovie.CineplexId);
            ViewData["MovieId"]    = new SelectList(_context.Movie, "MovieId", "LongDescription", cineplexMovie.MovieId);
            ViewData["SessionId"]  = new SelectList(_context.SessionTime, "SessionTimeId", "SessionTimeId", cineplexMovie.SessionId);
            return(View(cineplexMovie));
        }
Esempio n. 13
0
        public string CreateAssignment(int courseID, string teacherID)
        {
            var assignment = new Assignment()
            {
                TeacherAUID = teacherID,
                CourseID    = courseID
            };

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    context.Add(assignment);
                    context.SaveChanges();
                    transaction.Commit();
                    return("Assignment have been added");
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return("Assignment could not be added.");
                }
            }
        }
Esempio n. 14
0
        public string CreateStudent(string studentName, string studentID)
        {
            var student = new Student()
            {
                Name = studentName,
                AUID = studentID
            };

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    context.Add(student);
                    context.SaveChanges();
                    transaction.Commit();
                    return("Student have been added");
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return("Student could not be added. Student with this AUID already exists.");
                }
            }
        }
Esempio n. 15
0
        public async void addUserAssoc(int id_user_function,
                                       int id_association, string email, string password, string cnp, string name,
                                       string surname, string license, string insurance, string role)
        {
            var user = new User();

            //user.IdAssociation = id_association;
            user.Email     = email;
            user.Password  = password;
            user.Cnp       = cnp;
            user.Name      = name;
            user.Surname   = surname;
            user.License   = license;
            user.Insurance = insurance;
            // user.Role = role;
            _context.Add(user);
            await _context.SaveChangesAsync();
        }
Esempio n. 16
0
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Address,City,Province,PostalCode,Age,Password," +
                                                       "ConfirmPassword,Email,AlternativeEmail,Phone")] Member member, bool AnotherMember = false)
        // Above, we added AnotherMember as a Create's parameter (false is a default value)
        {
            if (ModelState.IsValid)
            {
                _context.Add(member);
                await _context.SaveChangesAsync();

                // If AnotherMember is true, which means we checked the checkbox...
                if (AnotherMember)
                {
                    // ...redirect to Create (after add a new member, stay in the same page to add another member)
                    return(RedirectToAction(nameof(Create)));
                }
                // Thanks Harry for share the following code to display a message after successfully add new member! \o/
                TempData["notice"] = "Thanks for registering with our website, your record was created successfully.";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(member));
        }
Esempio n. 17
0
        public static void Main(string[] args)
        {
            using (var db = new Assignment2Context())
            {
                db.Database.ExecuteSqlCommand("delete from HelpRequests");
                db.Database.ExecuteSqlCommand("delete from StudentCourses");
                db.Database.ExecuteSqlCommand("delete from HelpRequests");
                db.Database.ExecuteSqlCommand("delete from Exercises");
                db.Database.ExecuteSqlCommand("delete from Courses");
                db.Database.ExecuteSqlCommand("delete from Teachers");
                db.Database.ExecuteSqlCommand("delete from Students");


                var student = new Student()
                {
                    Name = "Jokum",
                    AUID = "AU785594"
                };
                db.Add(student);
                db.SaveChanges();

                var student3 = new Student()
                {
                    Name = "Jordkim",
                    AUID = "AU789456"
                };
                db.Add(student3);
                db.SaveChanges();


                var student2 = new Student()
                {
                    Name = "DJDudeMan",
                    AUID = "AU223684"
                };
                db.Add(student2);
                db.SaveChanges();


                var course = new Course()
                {
                    Name = "Avanceret Løgspark"
                };

                db.Add(course);

                var course2 = new Course()
                {
                    Name = "Matematik"
                };
                db.Add(course2);
                db.SaveChanges();

                db.Add(new StudentCourse() //Add a student to a course
                {
                    Active   = true,
                    Course   = course,
                    Semester = 2,
                    Student  = student
                });

                db.Add(new StudentCourse() //Add another student to the same course
                {
                    Active  = true,
                    Course  = course,
                    Student = student2
                });

                db.SaveChanges();

                Teacher teacher2 = new Teacher()
                {
                    name     = "Karl Jorgen",
                    AUID     = "AU555555",
                    CourseID = course2.CourseID
                };

                Teacher teacher1 = new Teacher()
                {
                    name     = "Dr. John",
                    AUID     = "AU000000",
                    CourseID = course.CourseID
                };

                db.SaveChanges();


                Exercise E1 = new Exercise()
                {
                    Number     = 0,
                    Lecture    = "English",
                    Help_Where = "Auditoriet",
                    Student    = student,
                    Teacher    = teacher1,
                    Course     = course,
                    Open       = true
                };
                db.Add(E1);

                Exercise E2 = new Exercise()
                {
                    Number     = 420,
                    Lecture    = "Danks",
                    Help_Where = "PBA",
                    Student    = student,
                    Teacher    = teacher1,
                    Course     = course,
                    Open       = true
                };
                db.Add(E2);

                Exercise E3 = new Exercise()
                {
                    Number     = 545,
                    Lecture    = "Danks",
                    Help_Where = "PBA",
                    Student    = student2,
                    Teacher    = teacher2,
                    Course     = course2
                };
                db.Add(E3);
                db.SaveChanges();

                var A1 = new Assignment()
                {
                    Course  = course,
                    Teacher = teacher1
                };

                db.Add(A1);
                db.SaveChanges();

                var A1Students = new HelpRequest()
                {
                    Open       = false,
                    Assignment = A1,
                    Student    = student
                };

                db.Add(A1Students);

                var A1Students2 = new HelpRequest()
                {
                    Open       = true,
                    Assignment = A1,
                    Student    = student2
                };

                db.Add(A1Students2);

                db.SaveChanges();
            }

            CreateHostBuilder(args).Build().Run();
        }