public async Task <IActionResult> Create([Bind("Name,IsMember,IsMemberDefault,IsNonMemberDefault,SecurityGroup,SendNewsletter,NewsletterGraceDays,StartSendingRenewalDays,StopSendingRenewalDays,MembershipFee,LeagueSplit,ChapterSplit")] PersonTypeCreateViewModel viewModel) { var isDuplicate = await _context.PersonTypes.AnyAsync(p => p.Name == viewModel.Name); if (isDuplicate) { ModelState.AddModelError("", "Person Type " + viewModel.Name + " already exists. It must be unique."); } if (ModelState.IsValid) { var personType = new PersonType { Name = viewModel.Name, IsMember = viewModel.IsMember, IsMemberDefault = viewModel.IsMemberDefault, IsNonMemberDefault = viewModel.IsNonMemberDefault, SecurityGroup = viewModel.SecurityGroup, SendNewsletter = viewModel.SendNewsletter, NewsletterGraceDays = viewModel.NewsletterGraceDays, StartSendingRenewalDays = viewModel.StartSendingRenewalDays, StopSendingRenewalDays = viewModel.StopSendingRenewalDays, MembershipFee = viewModel.MembershipFee, LeagueSplit = viewModel.LeagueSplit, ChapterSplit = viewModel.ChapterSplit }; _context.Add(personType); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(viewModel)); }
public async Task <IActionResult> Create() { ViewBag.User = await GetCurrentUser(); var viewModel = new PersonTypeCreateViewModel(); return(View(viewModel)); }