public BusinessLayerResult <AssignDto> AssignStudentToCourse(AssignDto assignDto) { BusinessLayerResult <AssignDto> businessLayerResult = new BusinessLayerResult <AssignDto>(); businessLayerResult.Result = assignDto; Course currentcourse = _courseDal.Get(x => x.CourseId == assignDto.CourseId); List <Student> students = new List <Student>(); foreach (int Id in assignDto.People) { Student student = _studentDal.Get(s => s.Id == Id); Course course = _courseDal.GetCourseWithChild(assignDto.CourseId); var isExist = course.Students.FirstOrDefault(x => x.Id == student.Id); if (isExist == null) { students.Add(student); } else { businessLayerResult.AddError(MessagesCodes.AlreadyExist, $"{student.Id} numaralı öğrenci zaten kursa kayıtlıdır."); } } if (businessLayerResult.Error.Select(x => x.Code == MessagesCodes.AlreadyExist).ToList().Count < assignDto.People.Length || businessLayerResult.Error.Count == 0) { _courseDal.AssignStudentToCourse(currentcourse, students); } else { businessLayerResult.AddError(MessagesCodes.AlreadyExist, "Kayıtlı öğrenciler için işlem yapılmamıştır."); } return(businessLayerResult); }
public BusinessLayerResult <AssignDto> AssignInstructorToCourse(AssignDto assignDto) { BusinessLayerResult <AssignDto> businessLayerResult = new BusinessLayerResult <AssignDto>(); businessLayerResult.Result = assignDto; Course currentcourse = _courseDal.Get(x => x.CourseId == assignDto.CourseId); List <Instructor> ınstructors = new List <Instructor>(); foreach (int Id in assignDto.People) { Instructor ınstructor = _userDal.Get(s => s.Id == Id); Course course = _courseDal.GetCourseWithChild(assignDto.CourseId); var isExist = course.Instructors.FirstOrDefault(x => x.Id == ınstructor.Id); if (isExist == null) { ınstructors.Add(ınstructor); } else { businessLayerResult.AddError(MessagesCodes.AlreadyExist, $"{ınstructor.Id} numaralı Eğitmen zaten kursa atanmış."); } } if (businessLayerResult.Error.Select(x => x.Code == MessagesCodes.AlreadyExist).ToList().Count < assignDto.People.Length || businessLayerResult.Error.Count == 0) { _courseDal.AssignInstructorToCourse(currentcourse, ınstructors); } else { businessLayerResult.AddError(MessagesCodes.AlreadyExist, "Atanmış eğitmenler için işlem yapılmamıştır."); } return(businessLayerResult); }
public async Task <IHttpActionResult> Assign([FromBody] AssignDto assignDto) { if (assignDto != null) { foreach (var bookId in assignDto.BooksId) { var assign = new Assigning { BookId = bookId, ClientId = assignDto.ClientId, OrderDate = assignDto.OrderDate, ReturnDate = assignDto.ReturnDate }; await _assignRepository.Assign(assign); } } else { return(BadRequest()); } return(Ok()); }
public IHttpActionResult AssignInstructorToCourse([FromBody] AssignDto assignDto) { BusinessLayerResult <AssignDto> result = _courseService.AssignInstructorToCourse(assignDto); return(Ok(result)); }