public async Task <IActionResult> AddStudentSkill([FromBody] StudentSkill newStudentSkill) { //Get Request's User var claimsIdentity = (ClaimsIdentity)this.User.Identity; if (!claimsIdentity.IsAuthenticated) { return(Unauthorized()); } //Get Student Profile var claim = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier); var userEmail = claim.Value; var User = await _userManager.FindByEmailAsync(userEmail); newStudentSkill.StudentId = User.Id; var skill = _profileSrv.AddStudentSkill(newStudentSkill); if (skill != null) { return(Ok(new { Status = "Success", Id = skill.Id, SkillName = skill.SkillName })); } else { return(Ok(new { Status = "Failed", Msg = "Skill Exist" })); } }
public IActionResult AddPoints(int id, [FromForm(Name = "selectedSkill")] List <int> selectedSkills) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var student = _context.Students.FirstOrDefault(x => x.Id == id); foreach (var skillId in selectedSkills) { var skill = _context.Skill.FirstOrDefault(s => s.Id == skillId); if (skill != null) { StudentSkill studentSkill = new StudentSkill(); studentSkill.ClassId = student.ClassId; studentSkill.Date = DateTime.Now.Date; studentSkill.Description = skill.Description; studentSkill.Point = skill.Point; studentSkill.SkillId = skill.Id; studentSkill.StudentId = student.Id; student.Point += skill.Point; _context.StudentSkill.Add(studentSkill); _context.Students.Update(student); } } _context.SaveChanges(); return(RedirectToAction(nameof(SelectedStudent), new { id })); }
public async Task SaveSkillsAsync(int currentStudentId, string[] skills) { //Delete all student skills, if they are exist var studentSkills = _db.StudentSkills.Where(s => s.StudentId == currentStudentId).ToList(); if (studentSkills.Count() != 0) { foreach (var stud in studentSkills) { _db.StudentSkills.Remove(stud); } } //Add skill for current student foreach (var skill in skills) { var existingSkill = _db.Skills.FirstOrDefault(s => s.Name == skill); if (existingSkill != null) { // If the added skill has been removed above in this method, // we change EntityState from "Deleted" to "Modified" for this skill var existingStudentSkill = studentSkills.FirstOrDefault(s => s.SkillId == existingSkill.Id && s.StudentId == currentStudentId); if (existingStudentSkill != null) { _db.Entry(existingStudentSkill).State = EntityState.Modified; } else { //If Skills are exist, add new record about Student and its skills StudentSkill studentSkill = new StudentSkill { SkillId = existingSkill.Id, StudentId = currentStudentId, }; _db.StudentSkills.Add(studentSkill); } } //If skill is added by user, add new skill to table Skill and add new record about Student and its skills else { var Skill = new Skill { Name = skill }; _db.Skills.Add(Skill); StudentSkill studentSkill = new StudentSkill { SkillId = Skill.Id, StudentId = currentStudentId, }; _db.StudentSkills.Add(studentSkill); } } }
public bool AddStudentSkill(StudentSkill newStudentSkill) { var getStudentSkill = _studentSkillRepo.GetAll().Where(ss => ss.StudentId == newStudentSkill.StudentId && ss.SkillId == newStudentSkill.SkillId).Any(); if (getStudentSkill) { return(false); } else { _studentSkillRepo.Insert(newStudentSkill); } return(true); }
public async Task <ActionResult> addStudentSkills([FromForm] StudentSkill studentSkill) { if (ModelState.IsValid) { if (studentSkill != null) { await _studentSkillsRepository.AddStudentSkill(studentSkill); return(Created("Student Skills Table", studentSkill)); } else { return(NotFound()); } } return(BadRequest()); }
public StudentSkillVM AddStudentSkill(StudentSkill newStudentSkill) { var getStudentSkill = _studentSkillRepo.GetAll().Where(ss => ss.StudentId == newStudentSkill.StudentId && ss.SkillId == newStudentSkill.SkillId).Any(); if (getStudentSkill) { return(null); } else { var result = _studentSkillRepo.Insert(newStudentSkill); var skill = _skillRepo.GetAll().Include(s => s.StudentSkills).SingleOrDefault(s => s.Id == result.SkillId); return(new StudentSkillVM() { Id = result.Id, SkillName = skill.Name }); } }
public IActionResult DeleteStudentSkill([FromBody] StudentSkill studentSkill) { _profileSrv.DeleteStudentSkill(studentSkill.Id); return(Ok(new { Status = "Success" })); }
/// <summary> /// Seeds the given database with Student/StudentSkill/CompletedCourses if needed. /// </summary> /// <param name="context">The context (database) to be used.</param> public static void Initialize(URC_Context context, UserManager <URCUser> userManager) { // Look for any student aplications. if (context.Students.Any()) { return; // DB has been seeded } var sid1 = userManager.FindByEmailAsync("*****@*****.**").Result.Id.ToString(); var sid2 = userManager.FindByEmailAsync("*****@*****.**").Result.Id.ToString(); var studentApplications = new Student[] { new Student { Sid = sid2, StudentName = "Ashley Eaton", ExpectedGraduationDate = DateTime.Parse("2022-05-10"), DegreePlan = "CE", GPA = (float)3.9, Uid = "u0000002", AvailableHoursPerWeek = 10, PersonalStatement = "Hi, I would like to be considered for a research position. I believe that I will be a great addition to any team. I am a really good student.", ProfileCreationDate = DateTime.Parse("2020-10-11"), Active = true }, new Student { Sid = sid1, StudentName = "Oliver Allphin", ExpectedGraduationDate = DateTime.Parse("2021-05-10"), DegreePlan = "CS", GPA = (float)3.7, Uid = "u0000001", AvailableHoursPerWeek = 20, PersonalStatement = "This is my personal statement. I am a great student and am very interested in research. Please consider me! This is my personal statement. I am a great student and am very interested in research. Please consider me! This is my personal statement. I am a great student and am very interested in research. Please consider me!", ProfileCreationDate = DateTime.Parse("2020-10-10"), Active = true } }; context.Students.AddRange(studentApplications); context.SaveChanges(); var studentSkills = new StudentSkill[] { new StudentSkill { SkillName = "C#", StudentID = 1 }, new StudentSkill { SkillName = "ASP.NET Core", StudentID = 1 }, new StudentSkill { SkillName = "Entity Framework", StudentID = 1 }, new StudentSkill { SkillName = "Javascript", StudentID = 1 }, new StudentSkill { SkillName = "HTML", StudentID = 1 }, new StudentSkill { SkillName = "Java", StudentID = 2 }, new StudentSkill { SkillName = "Bootstrap", StudentID = 2 }, new StudentSkill { SkillName = "MongoDB", StudentID = 2 }, new StudentSkill { SkillName = "ElasticSearch", StudentID = 2 } }; context.StudentSkills.AddRange(studentSkills); context.SaveChanges(); // Seed Popular Student Skills foreach (var s in studentSkills) { context.PopularStudentSkills.Add(new PopularStudentSkill { name = s.SkillName.ToUpper(), count = 1 }); } context.SaveChanges(); var interests = new Interest[] { new Interest { InterestName = "Basketball", StudentID = 1 }, new Interest { InterestName = "Snowboarding", StudentID = 1 }, new Interest { InterestName = "Web Software Architecture", StudentID = 1 }, new Interest { InterestName = "Wake Boarding", StudentID = 1 }, new Interest { InterestName = "Art", StudentID = 2 }, new Interest { InterestName = "Piano", StudentID = 2 }, new Interest { InterestName = "Rock Climbing", StudentID = 2 }, new Interest { InterestName = "Chess", StudentID = 2 } }; context.Interests.AddRange(interests); context.SaveChanges(); var completedCourses = new CompletedCourse[] { new CompletedCourse { CompletedCourseName = "CS-3100", StudentID = 1 }, new CompletedCourse { CompletedCourseName = "CS-2420", StudentID = 1 }, new CompletedCourse { CompletedCourseName = "CS-4480", StudentID = 1 }, new CompletedCourse { CompletedCourseName = "CS-3505", StudentID = 1 }, new CompletedCourse { CompletedCourseName = "CS-2420", StudentID = 2 }, new CompletedCourse { CompletedCourseName = "CS-1030", StudentID = 2 }, new CompletedCourse { CompletedCourseName = "CS-1410", StudentID = 2 }, new CompletedCourse { CompletedCourseName = "MATH-2270", StudentID = 2 } }; context.CompletedCourses.AddRange(completedCourses); context.SaveChanges(); }
public async Task AddStudentSkill(StudentSkill studentSkill) { await _context.StudentSkills.AddAsync(studentSkill); await _context.SaveChangesAsync(); }