// GET: ProposalItems/Create public IActionResult Create(int imageId, int proposalId) { var vm = new AddProposalItem { ProposalId = proposalId, ImageId = imageId, Image = _repository.Images.FirstOrDefault(i => i.Id == imageId), Caption = "" }; return(View(vm)); }
public ActionResult AddProposalItem(int imageId, int proposalId) { // create an AddProposalItem view model to hold info for the view var vm = new AddProposalItem { ProposalId = proposalId, ImageId = imageId, // get the image object by id Image = _repository.Images.FirstOrDefault(i => i.Id == imageId), Caption = "" }; // pass the view model to the view return(View(vm)); }
public ActionResult AddProposalItem(int id, AddProposalItem vm) { // create a new proposalItem model and fill in the image id, caption, etc var newProposalItem = new ProposalItem { ImageId = vm.ImageId, ProposalId = vm.ProposalId, Caption = vm.Caption }; // add it to the proposal _repository.AddProposalItem(vm.ProposalId, newProposalItem); // redirect to the Proposal Edit page return(RedirectToAction("Edit", new { id = vm.ProposalId })); }
public async Task <IActionResult> Create([Bind("Id,Caption,ImageId,ProposalId")] AddProposalItem vm) { if (ModelState.IsValid) { // create a new proposalItem model and fill in the image id, caption, etc var newProposalItem = new ProposalItem { ImageId = vm.ImageId, ProposalId = vm.ProposalId, Caption = vm.Caption }; // add it to the proposal await _repository.AddProposalItemAsync(vm.ProposalId, newProposalItem); // redirect to the Proposal Edit page //return RedirectToAction("Edit", "Proposals", new { id = vm.ProposalId }); //redirect to Proposals Image Search page return(RedirectToAction("ImageSearch", "Proposals", new { proposalId = vm.ProposalId, searchString = "" })); } return(View(vm)); }