Exemplo n.º 1
0
 public EditSundaySchoolViewModel(SundaySchool school,
                                  string pageTitle = "Editar Escola Dominical")
 {
     Id             = school.Id;
     Date           = school.Date;
     TeacherId      = school.TeacherId;
     Theme          = school.Theme;
     Verse          = school.Verse;
     NumberOfBibles = school.NumberOfBibles;
     PageTitle      = pageTitle;
 }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateSundaySchool(CreateSundaySchoolViewModel model)
        {
            if (ModelState.IsValid)
            {
                //if (model.SelectedMembers == null || model.SelectedMembers.Contains("0"))

                //if (model.TeacherId != null || model.TeacherId != "0")

                var sundaySchool = new SundaySchool(model);
                foreach (var id in model.SelectedMembers)
                {
                    var member = await memberRepository.GetMember(id);

                    if (member != null)
                    {
                        try
                        {
                            sundaySchool.AddMember(member);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Erro ao adicionar membros presentes.", ex);
                        }
                    }
                }

                var teacher = await memberRepository.GetMember(model.TeacherId);

                if (teacher != null)
                {
                    try
                    {
                        sundaySchool.Teacher = teacher;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Erro ao adicionar pregador.", ex);
                    }
                }

                try
                {
                    repository.Add(sundaySchool);
                }
                catch (Exception ex)
                {
                    throw new Exception("Erro ao salvar Escola Dominical", ex);
                }

                return(RedirectToAction("list", "event"));
            }

            return(await ReloadDataAndReturnView());
        }