コード例 #1
0
        public async Task <int> AddWorkshopAsync(WorkshopDto workshopDto)
        {
            if (workshopDto == null)
            {
                throw new ArgumentNullException($"Argument {nameof(workshopDto)} can't be null!");
            }

            int id = context.Set <Workshop>().Add(workshopDto.ToWorkshop()).Id;

            var students = await context.Set <User>().Where(u => u.GroupId == workshopDto.GroupId).ToListAsync();

            foreach (var student in students)
            {
                context.Set <Attendance>().Add(new Attendance()
                {
                    WorkshopId = workshopDto.Id,
                    StudentId  = student.Id,
                    IsAttended = false
                });
            }

            await context.SaveChangesAsync();

            return(id);
        }
コード例 #2
0
        public async Task AddWorkshopAsync(WorkshopDto workshopDto)
        {
            if (workshopDto == null)
            {
                throw new ArgumentException();
            }

            context.Workshops.Add(workshopDto.ToWorkshop());
            await context.SaveChangesAsync();
        }