Esempio n. 1
0
        public bool CreateInstructor(Instructor instructor, string userId)
        {
            try
            {
                if (!Instructors.Items.Any(x => x.Firstname == instructor.Firstname.Trim() && x.Surname == instructor.Surname.Trim()))
                {
                    instructor.Firstname   = instructor.Firstname.Trim();
                    instructor.Surname     = instructor.Surname.Trim();
                    instructor.UserCreated = userId;
                    instructor.Order       = Instructors.Items.Select(x => x.Order).DefaultIfEmpty(0).Max() + 1;

                    foreach (var l in instructor.Languages)
                    {
                        l.LanguageLevel = LanguageLevels.FindById(l.LanguageLevelId);
                    }

                    var languages = new List <InstructorLanguage>(instructor.Languages);
                    foreach (var l in languages)
                    {
                        if (instructor.Languages.Any(x => x.LanguageId == l.LanguageId && x.LanguageLevel.Level > l.LanguageLevel.Level))
                        {
                            instructor.Languages.Remove(l);
                        }
                    }

                    foreach (var e in instructor.Expertises)
                    {
                        e.ExpertiseLevel = ExpertiseLevels.FindById(e.ExpertiseLevelId);
                    }

                    var expertises = new List <InstructorExpertise>(instructor.Expertises);
                    foreach (var e in expertises)
                    {
                        if (instructor.Expertises.Any(x => x.ExpertiseId == e.ExpertiseId && x.ExpertiseLevel.Level > e.ExpertiseLevel.Level))
                        {
                            instructor.Expertises.Remove(e);
                        }
                    }

                    foreach (var ticket in instructor.Tickets)
                    {
                        ticket.From = ticket.From.Date;
                        ticket.To   = ticket.To.Date;
                    }

                    Instructors.Add(instructor);
                    return(true);
                }
            }
            catch (Exception e)
            {
            }
            return(false);
        }
Esempio n. 2
0
        public bool CreateCourse(Course course, string userId)
        {
            try
            {
                if (course.From >= course.To)
                {
                    return(false);
                }

                course.Name        = course.Name.Trim();
                course.UserCreated = userId;
                foreach (var i in course.Instructors)
                {
                    var instructor = Instructors.FindById(i.InstructorId);
                    if (!instructor.IsAvailable(course.From, course.To))
                    {
                        return(false);
                    }

                    if (!instructor.Rentals.Any(x => x.RentalId == course.RentalId))
                    {
                        return(false);
                    }

                    if (!instructor.HasExpertise(Expertises.FindById(course.ExpertiseId), ExpertiseLevels.FindById(course.ExpertiseLevelId)))
                    {
                        return(false);
                    }


                    if (course.LanguageId.HasValue && !instructor.HasLanguage(Languages.FindById(course.LanguageId.Value),
                                                                              course.LanguageLevelId.HasValue? LanguageLevels.FindById(course.LanguageLevelId.Value) : null))
                    {
                        return(false);
                    }
                }

                Courses.Add(course);
                return(true);
            }
            catch (Exception e)
            {
            }
            return(false);
        }