public ActionResult Edit(EditPledgeVM EditVM) { if (ModelState.IsValid) { var pledge = db.OpenPledges.Include("Activity_Types").FirstOrDefault(p => p.PledgeID.ToString() == EditVM.PledgeID); PledgesLogic.EditPledge(EditVM, pledge, CurrentUser(), db); db.SaveChanges(); return(RedirectToAction("Details", new { id = pledge.PledgeID })); } return(View(EditVM)); }
public IActionResult EditPledge([FromRoute] int?projectId, [FromRoute] int?pledgeId) { var editpledge = new EditPledgeVM() { Pledge = _pledgesservices.FindPledgeById((int)projectId.Value, (int)pledgeId.Value), Project = _projectservices.FindMyProjectById((int)projectId.Value) }; if (editpledge != null) { return(View(editpledge)); } return(NotFound()); }
public static void EditPledge(EditPledgeVM VM, Pledge pledge, ApplicationUser user, ApplicationDbContext db) { if (VM.Activities != null) { foreach (var newA in VM.Activities) { var thisNewType = (PledgeActivity.ActivityTypes)Enum.Parse(typeof(PledgeActivity.ActivityTypes), newA); if (!pledge.Activity_Types.Exists(at => at.Activity == thisNewType)) { pledge.Activity_Types.Add(new PledgeActivity { Activity = thisNewType }); } } } if (VM.GalleryIDs != null) { //new images foreach (var newG in VM.GalleryIDs) { var newGInt = GenericLogic.GetInt(newG); if (!pledge.Gallery.Exists(g => g.CalorieImageID == newGInt)) { pledge.Gallery.Add(db.Images.FirstOrDefault(t => t.CalorieImageID == newGInt)); } } //deleted images foreach (var old in pledge.Gallery.ToList()) { if (!VM.GalleryIDs.Exists(g => GenericLogic.GetInt(g) == old.CalorieImageID)) { pledge.Gallery.Remove(old); } } } pledge.ExpiryDate = VM.ExpiryDate; pledge.Story = VM.Story; Messaging.Add(Message.LevelEnum.alert_success, "Your Pledge has been updated.", Message.TypeEnum.StickyAlert, user); }