public static bool getCompletePledgeFromCreatePledgeVM(CreatePledgeVM pledgeVM, ApplicationDbContext db, ApplicationUser user) { pledgeVM.Pledge.Contributors[0].IsOriginator = true; pledgeVM.Pledge.Contributors[0].Currency = user.Currency; if (pledgeVM.Pledge.Teams == null) { pledgeVM.Pledge.Teams = new List <Team>(); } if (pledgeVM.TeamIDs != null) { foreach (var tId in pledgeVM.TeamIDs) { int tIdInt = 0; int.TryParse(tId, out tIdInt); pledgeVM.Pledge.Teams.Add(db.Teams.FirstOrDefault(t => t.ID == tIdInt)); } } if (pledgeVM.GalleryIDs != null) { foreach (var gIdStr in pledgeVM.GalleryIDs) { var gID = GenericLogic.GetInt(gIdStr); pledgeVM.Pledge.Gallery.Add(db.Images.FirstOrDefault(t => t.CalorieImageID == gID)); } } if (pledgeVM.ActivityIDs != null) { if (pledgeVM.Pledge.Activity_Types == null) { pledgeVM.Pledge.Activity_Types = new List <PledgeActivity>(); } foreach (var ActivityID in pledgeVM.ActivityIDs) { pledgeVM.Pledge.Activity_Types.Add(new PledgeActivity { Activity = (PledgeActivity.ActivityTypes)Enum.Parse(typeof(PledgeActivity.ActivityTypes), ActivityID) }); } } if (!string.IsNullOrEmpty(pledgeVM.JustGivingCharityID)) { var SelectedCharity = JustGivingLogic.getOrCreateCharityRecordFromJustGivingCharityID(pledgeVM.JustGivingCharityID); if (SelectedCharity == null) { return(false); } pledgeVM.Pledge.CharityID = SelectedCharity.ID; } return(true); }
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); }