public IActionResult AddBusinessAccessibility(int id) { Business business = context.Businesses.Single(b => b.ID == id); AddBusinessAccessibilityViewModel addBusinessAccessibilityViewModel = new AddBusinessAccessibilityViewModel(business, context.AFeatures.ToList()); return(View(addBusinessAccessibilityViewModel)); }
public IActionResult AddBusinessAccessibility(AddBusinessAccessibilityViewModel addBusinessAccessibilityViewModel) { if (ModelState.IsValid) { IList <BusinessAF> existingFeatures = context.BusinessAFs .Where(fb => fb.AFeatureID == addBusinessAccessibilityViewModel.AFeatureID) .Where(fb => fb.BusinessID == addBusinessAccessibilityViewModel.BusinessID).ToList(); if (existingFeatures.Count == 0) { BusinessAF business = new BusinessAF { AFeatureID = addBusinessAccessibilityViewModel.AFeatureID, BusinessID = addBusinessAccessibilityViewModel.BusinessID, }; context.BusinessAFs.Add(business); context.SaveChanges(); return(Redirect("/Business/ViewBusiness/" + business.BusinessID)); } return(Redirect("/Business/ViewBusiness/" + addBusinessAccessibilityViewModel.BusinessID)); } return(View(addBusinessAccessibilityViewModel)); }