public void AddProposalItem(int proposalId, ProposalItem proposalItem) { // get the proposal that we're going to add the item to var proposal = this.Proposals.FirstOrDefault(p => p.Id == proposalId); // IGNORE this next line. It's just manually attaching the actual image object // because I'm using a fake repository. EF would do this for you based on // the ImageId. proposalItem.Image = _images.FirstOrDefault(i => i.Id == proposalItem.ImageId); // Add the new item to the proposal. Possibly SaveChanges() here, if using EF. proposal.ProposalItems.Add(proposalItem); }
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)); }
private void UpdateProposalItems(ScrumFactoryEntities context, Proposal proposal, Proposal oldProposal) { // get new items added at the proposal and the removed ones ProposalItem[] newItems = new ProposalItem[0]; if (proposal.Items != null) newItems = proposal.Items.Where(i => !oldProposal.Items.Any(oi => oi.BacklogItemUId == i.BacklogItemUId)).ToArray(); ProposalItem[] deletedItems = new ProposalItem[0]; if (oldProposal.Items != null) deletedItems = oldProposal.Items.Where(oi => !proposal.Items.Any(i => i.BacklogItemUId == oi.BacklogItemUId)).ToArray(); // add and delete proposal items foreach (ProposalItem item in newItems) context.ProposalItems.AddObject(item); foreach (ProposalItem item in deletedItems) context.ProposalItems.DeleteObject(item); }
public Task AddProposalItemAsync(int proposalId, ProposalItem proposalItem) { _flowerAppContext.ProposalItems.Add(proposalItem); return(_flowerAppContext.SaveChangesAsync()); }
public async Task <IActionResult> DeleteConfirmed(int id, ProposalItem proposalItem) { await _repository.DeleteProposalItemAsync(id); return(RedirectToAction("Edit", "Proposals", new { id = proposalItem.ProposalId })); }