コード例 #1
0
 public IActionResult Create(Session session, SessionViewModel svm, User user = null)
 {
     if (ModelState.IsValid)
     {
         IEnumerable <Formula> formulasOfDay = _formulaRepository.GetByTrainingDay(_trainingDayRepository.getById(svm.TrainingDayId));
         IList <Member>        members       = new List <Member>();
         foreach (var formula in formulasOfDay)
         {
             foreach (var member in _userRepository.GetByFormula(formula))
             {
                 members.Add(member);
             }
         }
         IEnumerable <Member> membersSession = new List <Member>(members);
         Teacher t = (Teacher)_userRepository.GetByEmail(user.Email);
         session.PutFormulas(formulasOfDay.ToList());
         session.Teacher     = t;
         session.Members     = membersSession;
         session.TrainingDay = _trainingDayRepository.getById(svm.TrainingDayId);
         if (session.SessionId == svm.SessionId)
         {
             _sessionRepository.Add(session);
             _sessionRepository.SaveChanges();
         }
         svm.Change(session);
         return(View("Register", svm));
     }
     return(RedirectToAction(nameof(Create)));
 }