public ActionResult Create(ProjectOffering model) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.ProjectOffering)) { return(RedirectToPermissionDenied()); } if (ModelState.IsValid) { try { //Validate values of Project and UnitOffering db.GetProject(model.ProjectId); db.GetUnitOffering(model.UnitOfferingId); ProjectOfferingProcessor.InsertProjectOffering( model.ProjectId, model.UnitOfferingId); // If Insert successful return to index return(RedirectToAction("Index")); } catch (Exception e) { // Show DataLayer errors ModelState.AddModelError("", e.Message); } } else { // Show ModelState errors var errors = ModelState.Values.SelectMany(v => v.Errors); } var projectOffering = new ProjectOffering( ); // Generate drop down lists for each field. ViewBag.UnitofferingId = new SelectList(projectOffering.GetUnitOfferings( ), "UnitOfferingId", "UnitName", null); ViewBag.ProjectId = new SelectList(projectOffering.GetProjects( ), "ProjectId", "Name", null); // Navigate to View return(View( )); }
public ActionResult Create( ) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.ProjectOffering)) { return(RedirectToPermissionDenied()); } ViewBag.Message = "Create New Unit"; var projectOffering = new ProjectOffering( ); // Generate drop down lists for each field. ViewBag.UnitofferingId = new SelectList(projectOffering.GetUnitOfferings( ), "UnitOfferingId", "UnitName", null); ViewBag.ProjectId = new SelectList(projectOffering.GetProjects( ), "ProjectId", "Name", null); // Navigate to View return(View( )); }