コード例 #1
0
        private Event ConvertToEntity(EventDto dto)
        {
            Event entity;

            switch (dto.Type)
            {
            case EventType.Course:
                entity = new Course()
                {
                    Subject  = RepositoryHelper.GetAnotherEntity <Subject>(dto.Subject.Id),
                    Duration = dto.Duration,
                    Price    = dto.Price
                };
                break;

            case EventType.AcademicCompetition:
                entity = new AcademicCompetition()
                {
                    Subject = RepositoryHelper.GetAnotherEntity <Subject>(dto.Subject.Id)
                };
                break;

            default:
                entity = new SchoolWork()
                {
                    Program = dto.Program
                };
                break;
            }

            entity.Id          = dto.Id;
            entity.Name        = dto.Name;
            entity.Type        = dto.Type;
            entity.Info        = dto.Info;
            entity.Comment     = dto.Comment;
            entity.Departments = RepositoryHelper.GetAnotherEntity <Department>(dto.Departments.Select(x => x.Id)).ToSet();
            entity.Volunteers  = RepositoryHelper.GetAnotherEntity <Volunteer>(dto.Volunteers.Select(x => x.Id)).ToList();
            entity.Lecturers   = RepositoryHelper.GetAnotherEntity <Employee>(dto.Lecturers.Select(x => x.Id)).ToList();
            entity.Organizers  = RepositoryHelper.GetAnotherEntity <Employee>(dto.Organizers.Select(x => x.Id)).ToList();
            entity.Purchases   = dto.Purchases;

            entity.EventExecutions = dto.Executions.Select(x => new EventExecution()
            {
                Dates = x.Dates.Select(xx => new EventDate()
                {
                    Date      = xx.Date,
                    StartTime = GetTimeSpan(xx.StartTime),
                    EndTime   = GetTimeSpan(xx.EndTime)
                }).ToList(),
                Address = RepositoryHelper.GetAnotherEntity <Address>(x.Address.Id)
            }
                                                           ).ToSet();

            if (dto.Id != 0)
            {
                var lastVersion = RepositoryHelper.GetAnotherEntity <Event>(dto.Id);
                entity.AttendanceInfo = lastVersion.AttendanceInfo;
            }

            var dates = entity.EventExecutions.First().Dates;

            entity.Year = dates?.First()?.Date.Year ?? 0;

            return(entity);
        }