示例#1
0
        public IActionResult Add(AddPrefixViewModel addPrefixViewModel)
        {
            Provider selectedProvider =
                context.Providers.SingleOrDefault(p => p.ID == addPrefixViewModel.SelectedProvider);

            if (ModelState.IsValid)
            {
                // Add the new Prefix to my existing Prefixes
                Prefix newPrefix = new Prefix
                {
                    Name       = addPrefixViewModel.Prefix,
                    ProviderID = selectedProvider.ID
                };

                context.Prefixes.Add(newPrefix);
                context.SaveChanges();

                return(Redirect("ListAllPrefixes"));
            }

            return(View(addPrefixViewModel)); //if user inout does not pass validation send user back to the homepage with the form
        }
示例#2
0
        //routes to add prefix view

        public IActionResult Add()
        {
            AddPrefixViewModel addPrefixViewModel = new AddPrefixViewModel(context.Providers.ToList());

            return(View(addPrefixViewModel));
        }