public bool AddSkill(int courseId, SetAvailableCoursesDto mentordetails) { try { var course = context.Courses.Where(c => c.Id == courseId).SingleOrDefault(); var ifExists = context.AvailableCourses.Where(ac => ac.MentorEmail == mentordetails.Email && ac.CourseDetails == course).SingleOrDefault(); if (ifExists == null) { var skill = new AvailableCourses { CourseDetails = course, MentorFname = mentordetails.FName, MentorLname = mentordetails.LName, MentorEmail = mentordetails.Email }; context.AvailableCourses.Add(skill); var result = context.SaveChanges(); if (result > 0) { return(true); } return(false); } return(false); } catch (Exception e) { throw; } }
public IActionResult Addskills(int courseId, [FromBody] SetAvailableCoursesDto mentordetails) { try { var result = repository.AddSkill(courseId, mentordetails); if (result) { return(Ok(new { Message = "Skill added successfully." })); } return(BadRequest(new { Message = "Internal Server error or Dublicate error." })); } catch (Exception e) { return(BadRequest(new { Message = "Internal Server error" })); } }