public ActionResult MSAccessEdit(int id) { StudentCourse course = new StudentCourse(); course = MSAccessMethods.getCourse(id); return(View(course)); }
public void DeleteStudent(int id) { StudentCourse student = unitOfWork.StudentCourseRepository.GetById(id); unitOfWork.StudentCourseRepository.Delete(student); unitOfWork.Save(); }
public ActionResult MSSQLEdit(int id) { StudentCourse studentCourse = new StudentCourse(); studentCourse = MSSQLMethods.getCourse(id); return(View(studentCourse)); }
public async Task <IActionResult> Edit(int id, [Bind("StudentCourseId,StdId,CrsId,Semester")] StudentCourse studentCourse) { if (id != studentCourse.StudentCourseId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(studentCourse); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentCourseExists(studentCourse.StudentCourseId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CrsId"] = new SelectList(_context.Course, "CrsId", "CourseId", studentCourse.CrsId); ViewData["StdId"] = new SelectList(_context.StudentInfo, "StdId", "StudentId", studentCourse.StdId); return(View(studentCourse)); }
public async Task <IActionResult> AddStudentCourse([FromBody] CreateStudentCourseDto createStudentCourse) { if (createStudentCourse == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var stu = await _studentService.GetStudentDetailByStuName(createStudentCourse.StudentName); var course = await _courseService.GetCourseByCourseNameDetail(createStudentCourse.CourseName); if (stu.Count == 0 || course.Count == 0) { return(BadRequest("学生或者课程不存在")); } if (stu.Count > 1 || course.Count > 1) { return(BadRequest("学生姓名或者课程名存在多条记录")); } StudentCourse studentCourse = new StudentCourse() { Student = stu.FirstOrDefault(), Course = course.FirstOrDefault() }; _studentCourseService.AddT(studentCourse); if (!await _studentCourseService.Save()) { return(StatusCode(500, "添加记录时出错")); } return(Created("", createStudentCourse)); }
public static StudentCourseModel Transform(StudentCourse input) { var output = new StudentCourseModel(); Transformers.ForEach(i => i(input, output)); return(output); }
public IActionResult Create(StudentViewModel obj) { if (ModelState.IsValid) { Student student = new Student() { StudentName = obj.StudentName, StudentAddress = obj.StudentAddress, StudentContactNo = obj.StudentContactNo, StudentEmail = obj.StudentEmail, DateOfBirth = obj.DateOfBirth, }; _db.Students.Add(student); _db.SaveChanges(); var courses = _db.Courses.Where(i => obj.StudentCourses.Contains(i.CourseId)).ToList(); foreach (var course in courses) { var newStudentCourse = new StudentCourse() { StudentId = student.StudentId, CourseId = course.CourseId, }; student.StudentCourses.Add(newStudentCourse); } _db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.listOfCourses = _db.Courses.ToList(); return(View(obj)); } }
public IActionResult Create(StudentCreateViewModel model) { if (ModelState.IsValid) { Student newStudent = new Student { StudentName = model.StudentName, }; DbContext.Students.Add(newStudent); DbContext.SaveChanges(); foreach (var selectedCourse in model.SelectedCourse.Where(s => s.isSelect)) { var courseStudent = new StudentCourse() { CourseId = selectedCourse.CourseId, StudentId = newStudent.StudentId }; DbContext.studentCourses.Add(courseStudent); DbContext.SaveChanges(); } return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult LearnCourse(int?id) { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); string currentUserId = User.Identity.GetUserId(); var user = UserManager.FindById(currentUserId); if (id == null) { return(RedirectToAction("NotFound")); } Course course = db.Courses.Find(id); //Kiem tra khoa hoc da duoc mua boi user da dang nhap hoac user da mua member: StudentCourse studentCourse = db.StudentCourses.Find(id, currentUserId); if (studentCourse == null && memberService.CheckExpiredMember(user) == true && course.Price > 0) { return(RedirectToAction("NotFound")); } if (course == null || course.DeletedAt != null || course.Status != (int)Course.CourseStatus.Actived) { return(RedirectToAction("NotFound")); } //Danh sach id khoa hoc member da mua: ViewBag.MyPaidCourse = myPaidCourses(); return(View(course)); }
public async Task <IActionResult> Add([FromBody] StudentCourseViewModel studentCourseViewModel) { try { bool isParticipatedByStudentIdAndCourseId = await studentCourseRepository.IsParticipatedByStudentIdAndCourseId(studentCourseViewModel.StudentId, studentCourseViewModel.CourseId); if (isParticipatedByStudentIdAndCourseId == true) { return(BadRequest(new { Errors = new { Code = "ParticipatedCourse", Description = "The student has already participated the course!" } })); } StudentCourse studentCourseMapped = mapper.Map <StudentCourse>(studentCourseViewModel); studentCourseMapped.DateTime = DateTime.Now; await studentCourseRepository.Add(studentCourseMapped); return(Ok(new { Results = studentCourseMapped })); } catch (Exception e) { Console.WriteLine($"ErrorMesages: {e}"); return(BadRequest(new { Errors = new { Code = "InvalidInputParameters", Description = "Invalid Input Parameters!" } })); } }
public List <StudentCourse> GetCoursesTakenByStudentById(int id) { Query = @"SELECT DISTINCT c.Id,c.Code,c.Name,c.Credit,c.Description,c.DepartmentId,c.SemesterId FROM Courses c INNER JOIN EnrollCourses r ON (c.Id=r.CourseId) WHERE r.StudentId ='" + id + "' AND r.AssignFlag = 1"; Command = new SqlCommand(Query, Connection); Connection.Open(); Reader = Command.ExecuteReader(); List <StudentCourse> studentCourses = new List <StudentCourse>(); while (Reader.Read()) { StudentCourse studentCourse = new StudentCourse(); studentCourse.Id = (int)Reader["Id"]; studentCourse.Code = Reader["Code"].ToString(); studentCourse.Name = Reader["Name"].ToString(); studentCourse.Credit = Convert.ToDecimal(Reader["Credit"]); studentCourse.Description = Reader["Description"].ToString(); studentCourse.DepartmentId = (int)Reader["DepartmentId"]; studentCourse.SemesterId = (int)Reader["SemesterId"]; //studentCourse.AssignFlag = (int)Reader["AssignFlag"]; studentCourses.Add(studentCourse); } Reader.Close(); Connection.Close(); return(studentCourses); }
public void TC05_GetHashKey(string courseId, string StudentId, string term) { StudentCourse studentCourse = new StudentCourse(courseId, StudentId, term); string expected = String.Format("{0}_{1}_{2}", courseId.ToLower(), StudentId.ToLower(), term.ToLower()); Assert.AreEqual(expected, studentCourse.GetHashKey()); }
public async Task AjouterInscriptionEtudiantAuCours_Variante2Async(long studentId, long courseId) { /* Dans cette variante, les instances des étudiants et des cours * sont explicitement recherchées. Rappel : pour rechercher une entité, il existe plusieurs méthodes. Les méthodes à utiliser varient selon les scenarii. Identifiez au moins deux scenarii de recherche et la méthode de recherche préférable dans chacun de ces scenarii. */ Student student = await context.Student.FindAsync(studentId); if (student == null) { throw new StudentNotFoundException(studentId); } Course course = await context.Course.FindAsync(courseId); if (course == null) { throw new CourseNotFoundException(courseId); } var inscription = new StudentCourse() { Course = course, Student = student }; context.StudentCourse.Add(inscription); await context.SaveChangesAsync(); }
public ActionResult Add(int id) { string curentuserid = User.Identity.GetUserId(); StudentCourse studentCourse = new StudentCourse(); studentCourse.CourseId = id; studentCourse.StudentId = curentuserid; studentCourse.Status = 2; var sc = db.StudentCourses.Where(r => r.CourseId == id && r.StudentId == curentuserid).ToList(); var Cs = db.Courses.Find(id); var idSm = Cs.SemesterId; var idSmUser = db.Users.Find(curentuserid).SemesterId; if (sc.Count == 0 && idSm.Equals(idSmUser)) { db.StudentCourses.Add(studentCourse); db.SaveChanges(); TempData["succers"] = "Save Course Success!!!"; } else { TempData["err"] = "You have already signed up for the course or Your course is incorrect!!!"; } //return RedirectToAction("Index", "Home"); return(RedirectToAction("Student", "Home")); }
public async Task <IActionResult> Edit(int id, [Bind("StudentCourseID,UserNameStudent,SelfEvaluationID,AnswerID,GroupGradeOK,SelfEvaluationGrade,ProfessorGuessGrade,Grade")] StudentCourse studentCourse) { if (id != studentCourse.StudentCourseID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(studentCourse); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentCourseExists(studentCourse.StudentCourseID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(studentCourse)); }
public StudentCourse GetStudent(int id) { StudentCourse student = unitOfWork.StudentCourseRepository.GetById(id); /*Student student = db.Students.Find(id);*/ return(student); }
public ActionResult DeleteConfirmed(int id) { using (DbContextTransaction dbTran = db.Database.BeginTransaction()) { try { string a = User.IsInRole("Franchisee") ? help.Franchisee() : help.Receptionist(); StudentCourse student_Course = db.StudentCourses.Find(id); Fees_Master feemaster = db.Fees_Master.FirstOrDefault(x => x.RollNo == student_Course.RollNo && x.franchid == a && x.CourseId == student_Course.CourseId); db.Fees_Master.Remove(feemaster); db.SaveChanges(); db.StudentCourses.Remove(student_Course); db.SaveChanges(); dbTran.Commit(); TempData["Success"] = "Deleted Successfully"; return(RedirectToAction("Index", new { roll = rollno })); } catch (Exception) { dbTran.Rollback(); return(RedirectToAction("Index", new { roll = rollno })); throw; } } }
public void ThrowArgumentNullException_WhenMapperMapToMethodReturnsNull() { //Arrange var studentCoursesMock = new Mock <IRepository <StudentCourse> >(); var mapperMock = new Mock <IMappingProvider>(); var saverMock = new Mock <ISaver>(); var studentCourseDto = new StudentCourseDto() { CourseId = Guid.NewGuid(), StudentId = "uniqueId" }; var studentCourse = new StudentCourse() { CourseId = studentCourseDto.CourseId, StudentId = studentCourseDto.StudentId }; mapperMock .Setup(x => x.MapTo <StudentCourse>(studentCourseDto)) .Returns((StudentCourse)null); var studentCourseService = new StudentCourseService( studentCoursesMock.Object, mapperMock.Object, saverMock.Object); //Act && Assert Assert.ThrowsException <ArgumentNullException>(() => studentCourseService.AddCourseToStudent(studentCourseDto.CourseId, studentCourseDto.StudentId)); }
public ActionResult Edit([Bind(Include = "Id,CourseId,Admitdate,enddate,Fees,RoomId,Status,Days,Token")] StudentCourse student_Course) { if (ModelState.IsValid) { string a = help.Permission(); Course cc = db.Courses.First(x => x.CourseId == student_Course.CourseId && x.franchid == a); student_Course.RollNo = rollno; student_Course.Uid = a; student_Course.enddate = Convert.ToDateTime(student_Course.Admitdate).AddDays(student_Course.Days); student_Course.Fees = (Convert.ToInt32(cc.Fees) * Convert.ToInt32(student_Course.Days)).ToString(); db.Entry(student_Course).State = EntityState.Modified; db.SaveChanges(); Fees_Master feemaster = db.Fees_Master.FirstOrDefault(x => x.RollNo == rollno && x.franchid == a && x.Token == student_Course.Token && x.Status == true); //feemaster.RollNo = student_Course.RollNo; feemaster.Date = System.DateTime.Now; feemaster.CourseId = student_Course.CourseId; feemaster.AlertDate = System.DateTime.Now.AddDays(2); feemaster.Status = true; feemaster.TotalFees = (Convert.ToInt32(cc.Fees) * Convert.ToInt32(student_Course.Days)); // feemaster.TotalFees += Convert.ToInt32(student_Course.Fees); db.Entry(feemaster).State = EntityState.Modified; db.SaveChanges(); TempData["Success"] = "Updated Successfully"; ViewBag.CourseId = new SelectList(db.Courses.Where(x => x.franchid == a), "CourseId", "CourseName"); return(RedirectToAction("Index", new { roll = rollno })); } return(View(student_Course)); }
public async Task <ActionResult> AddStudents(List <CompetitionApplicationDTO> applications) { List <StudentCourse> students = new List <StudentCourse>(); int competitionId = 0; foreach (var item in applications) { StudentCourse student = new StudentCourse() { CourseId = item.CourseId, StudentId = item.StudentId, Mark = 0, }; competitionId = item.CompetitionId; students.Add(student); } var succes = await _courseRepository.AddStudents(students); if (succes == 1) { Competition competition = await _competitionRepository.GetById(competitionId); if (competition != null) { competition.Active = false; } _competitionRepository.UpdateCompetition(competition); return(Ok()); } return(BadRequest()); }
/// <summary>check out of course as an asynchronous operation.</summary> /// <param name="student">The student.</param> /// <param name="course">The course.</param> /// <returns>Task.</returns> public async Task CheckOutOfCourseAsync(OmdleUser student, Data.Models.Course course) { StudentCourse studentCourse = _dataService.GetSet <Data.Models.StudentCourse>().FirstOrDefault(x => x.Course == course && x.Student == student); _dataService.GetSet <Data.Models.StudentCourse>().Remove(studentCourse); await _dataService.SaveDbAsync(); }
internal static void InitialStudentCoursesSeed(SchoolDbContext db, int count) { var allStudentsIds = db.Students.Select(s => s.Id).ToArray(); var allCoursesIds = db.Courses.Select(c => c.Id).ToArray(); var studentCourses = new List <StudentCourse>(); for (int i = 0; i < count; i++) { var studentId = allStudentsIds[rnd.Next(0, allStudentsIds.Length)]; var courseId = allCoursesIds[rnd.Next(0, allCoursesIds.Length)]; var studentCourse = new StudentCourse() { StudentId = studentId, CourseId = courseId }; var currentPairToSeed = studentId.ToString() + courseId.ToString(); // Ensures that there is no another Student with same Course if (sownPairs.Contains(currentPairToSeed)) { i--; continue; } sownPairs.Add(currentPairToSeed); studentCourses.Add(studentCourse); db.Students.Find(studentId).CourseParticipateIn.Add(studentCourse); db.Courses.Find(courseId).Participants.Add(studentCourse); } db.StudentsCourseses.AddRange(studentCourses); db.SaveChanges(); }
public ActionResult Cart() { Uri myUri = new Uri(Request.Url.ToString()); string code = HttpUtility.ParseQueryString(myUri.Query).Get("vnp_ResponseCode"); string BankCode = HttpUtility.ParseQueryString(myUri.Query).Get("vnp_BankCode"); Debug.WriteLine("OrderId = " + TempData["OrderId"]); if (code == "00") { ViewBag.ThanhToan = "Success!"; string orderID = (string)TempData["OrderId"]; var order = db.OrderInfos.Find(orderID); List <OrderDetail> listCourse = db.OrderDetails.Where(od => od.OrderId == orderID).ToList(); if (order == null) { return(RedirectToAction("NotFound")); } order.Status = (int)OrderInfo.OrderStatus.Paid; order.BankCode = BankCode; foreach (var item in listCourse) { //Debug.WriteLine("courseID= "+item.CourseId); var studentCourse = new StudentCourse(); studentCourse.MemberId = order.MemberId; studentCourse.CourseId = item.CourseId; db.StudentCourses.Add(studentCourse); db.SaveChanges(); } db.OrderInfos.AddOrUpdate(order); db.SaveChanges(); } return(View()); }
private static StudentCourse NewStudentCourse() { using (var db = new StudentSystemContext()) { var allStudentsIds = db.Students.Select(s => s.StudentId).ToArray(); var allCoursesIds = db.Courses.Select(c => c.CourseId).ToArray(); var studentCourse = new StudentCourse() { StudentId = allStudentsIds[rnd.Next(0, allStudentsIds.Length)], CourseId = allCoursesIds[rnd.Next(0, allCoursesIds.Length)] }; var currentPairToSeed = studentCourse.StudentId.ToString() + studentCourse.CourseId.ToString(); // Ensures that there is no another Student with same Course if (sownPairs.Contains(currentPairToSeed)) { return(NewStudentCourse()); } sownPairs.Add(currentPairToSeed); return(studentCourse); } }
public ActionResult AddStudent(string studentName, int CourseID) { StudentCourse newPair = new StudentCourse(Student.FindByName(studentName).GetId(), CourseID); newPair.Save(); return(RedirectToAction("Detail", new { ID = CourseID })); }
public async Task <IActionResult> PutStudentCourse(int id, StudentCourse studentCourse) { if (id != studentCourse.CourseId) { return(BadRequest()); } _context.Entry(studentCourse).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentCourseExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private static void AddStudentCourses(StudentSystemContext context) { var JavaCourse = context.Courses.FirstOrDefault(x => x.Name == "Java"); var JSCore = context.Courses.FirstOrDefault(x => x.Name == "JS Core"); var CSharpOOP = context.Courses.FirstOrDefault(x => x.Name == "CSharpOOP"); var student1 = context.Students.FirstOrDefault(x => x.Name == "Ivan Petrov"); var student2 = context.Students.FirstOrDefault(x => x.Name == "Pesho Peshov"); var student3 = context.Students.FirstOrDefault(x => x.Name == "Simona Simeonova"); var student4 = context.Students.FirstOrDefault(x => x.Name == "Stavri Dinozavri"); var student5 = context.Students.FirstOrDefault(x => x.Name == "Spiridon Kanchev"); var studentCourses = new StudentCourse[] { new StudentCourse(student1, JavaCourse), new StudentCourse(student2, JavaCourse), new StudentCourse(student3, CSharpOOP), new StudentCourse(student4, CSharpOOP), new StudentCourse(student5, JSCore), new StudentCourse(student1, CSharpOOP), new StudentCourse(student2, JSCore), new StudentCourse(student2, CSharpOOP) }; context.StudentCourses.AddRange(studentCourses); }
public void UpdateStudent(int id, StudentDTO studentDTO) { Student student = Context.Students.Find(id); student.FirstName = studentDTO.FirstName; student.LastName = studentDTO.LastName; student.Year = studentDTO.Year; student.StudentIdCard = studentDTO.StudentIdCard; var statusId = Context.StudentStatus.Where(s => s.Name == studentDTO.StudentStatus).FirstOrDefault().Id; student.StudentStatusId = statusId; var coursesOfStudent = Context.CoursesOfStudents.Where(s => s.StudentId == student.Id).ToList(); foreach (var course in coursesOfStudent) { Context.CoursesOfStudents.Remove(course); } foreach (var course in studentDTO.CoursesList) { var courseId = Context.Courses.Where(c => c.Name == course).FirstOrDefault().Id; StudentCourse courseOfStudent = new StudentCourse(); courseOfStudent.CourseId = courseId; courseOfStudent.StudentId = student.Id; Context.CoursesOfStudents.Add(courseOfStudent); Context.SaveChanges(); } }
private static List <StudentCourse> GenerateStudentsCourses(List <Student> students, List <Course> courses) { var random = new Random(); var randomKvp = new List <KeyValuePair <int, int> >(); var relations = new List <StudentCourse>(); for (int i = 0; i < 100; i++) { var studentId = random.Next(1, students.Count); var courseId = random.Next(1, courses.Count); randomKvp.Add(new KeyValuePair <int, int>(studentId, courseId)); } randomKvp = randomKvp.Distinct().ToList(); foreach (var kvp in randomKvp) { var relation = new StudentCourse { StudentId = kvp.Key, CourseId = kvp.Value }; relations.Add(relation); } return(relations); }
public StudentCourse GetStudentByStudentId(int studentId) { try { StudentCourse studentCourse = null; const string storeProcedure = "GetStudentByStudentId"; Connection.Open(); Command.CommandType = CommandType.StoredProcedure; Command.CommandText = storeProcedure; Command.Parameters.Clear(); Command.Parameters.AddWithValue("@Id", studentId); Reader = Command.ExecuteReader(); if (Reader.HasRows) { if (Reader.Read()) { studentCourse = new StudentCourse { StudentName = Reader["Name"].ToString(), StudentEmail = Reader["Email"].ToString(), StudentDepartment = Reader["Department"].ToString() }; } Reader.Close(); } return(studentCourse); } finally { Connection.Close(); } }
public void InsertOrUpdate(StudentCourse studentCourse) { if (studentCourse.StudentCourseId == default(int)) { // New entity context.StudentCourseRelations.Add(studentCourse); } else { // Existing entity context.Entry(studentCourse).State = EntityState.Modified; } }
// POST api/StudentCourse public HttpResponseMessage PostStudentCourse(StudentCourse studentcourse) { if (ModelState.IsValid) { db.StudentCourses.Add(studentcourse); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, studentcourse); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = studentcourse.Id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/StudentCourse/5 public HttpResponseMessage PutStudentCourse(int id, StudentCourse studentcourse) { if (ModelState.IsValid && id == studentcourse.Id) { db.Entry(studentcourse).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public EditStudentLessonCommand(StudentCourse studentLesson) { _studentLesson = studentLesson; }
public AddStudentCourseCommand(StudentCourse studentCourse) { _studentCourse = studentCourse; }
public void SaveStudentCourse(StudentCourse studentCourse) { if (studentCourse.ID == Guid.Empty) { studentCourse.StartDate = DateTime.Now; studentCourse.Mark = 0; _context.StudentCourses.Add(studentCourse); } else { StudentCourse dbEntry = _context.StudentCourses.Find(studentCourse.ID); dbEntry.EndDate = studentCourse.EndDate; dbEntry.Mark = studentCourse.Mark; } _context.SaveChanges(); }
public EditStudentLessonCommand(StudentCourse studentLesson, Student student) { Dispatcher.Push(new EditStudentCommand(student)); _studentLesson = studentLesson; }