public async Task <IActionResult> Create(MemberViewModel memberViewModel) { if (!ModelState.IsValid) { return(View(memberViewModel)); } Member member = new Member { Name = memberViewModel.Name, Document = memberViewModel.Document, DateBirth = memberViewModel.DateBirth, Address = memberViewModel.Address, Neighborhood = memberViewModel.Neighborhood, City = memberViewModel.City, State = memberViewModel.State, Mailbox = memberViewModel.Mailbox, Email = memberViewModel.Email, PhoneNumber = memberViewModel.PhoneNumber, Baptized = memberViewModel.Baptized, Status = memberViewModel.Status, RegistrationDate = memberViewModel.RegistrationDate }; foreach (var item in memberViewModel.GroupsIds ?? Enumerable.Empty <Guid>()) { member.AddGroup(await _groupRepository.GetEntityById(item)); } foreach (var item in memberViewModel.RolesIds ?? Enumerable.Empty <Guid>()) { member.AddRole(await _roleRepository.GetEntityById(item)); } try { await _memberRepository.CreateEntity(member); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); InitializeMember(); return(View(MemberVM)); } }