예제 #1
0
        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);
        }
예제 #2
0
        public static bool MergeVewModelToUser(EditViewModel EditVM, ApplicationUser User, ApplicationDbContext db)
        {
            var changed = false;

            User.UserName                = SetProperty(User.UserName, EditVM.User.UserName, ref changed);
            User.ProfilePictureID        = SetProperty(User.ProfilePictureID, EditVM.User.ProfilePictureID, ref changed);
            User.RecieveFirstPartyEmails = SetProperty(User.RecieveFirstPartyEmails, EditVM.User.RecieveFirstPartyEmails, ref changed);
            User.RecieveThirdPartyEmails = SetProperty(User.RecieveThirdPartyEmails, EditVM.User.RecieveThirdPartyEmails, ref changed);
            User.IsSponsor               = SetProperty(User.IsSponsor, EditVM.User.IsSponsor, ref changed);
            User.IsExercisor             = SetProperty(User.IsExercisor, EditVM.User.IsExercisor, ref changed);

            User.IsCompany          = SetProperty(User.IsCompany, EditVM.User.IsCompany, ref changed);
            User.CompanyDescription = SetProperty(User.CompanyDescription, EditVM.User.CompanyDescription, ref changed);
            User.CompanyURL         = SetProperty(User.CompanyURL, EditVM.User.CompanyURL, ref changed);

            User.Currency = SetProperty(User.Currency, EditVM.User.Currency, ref changed);
            if (checkAddUserToTeam(EditVM.User.TeamID, User, db))
            {
                changed = true;
            }



            if (EditVM.PreferredActivities?.Any() ?? false)
            {
                User.PreferredActivities?.Clear();
                changed = true;
                foreach (var pa in EditVM.PreferredActivities)
                {
                    User.PreferredActivities?.Add(new PreferredActivity
                    {
                        Activity = (PledgeActivity.ActivityTypes)Enum.Parse(typeof(PledgeActivity.ActivityTypes), pa)
                    });
                }
            }

            if (EditVM.PreferredjustGivingCharities?.Any() ?? false)
            {
                User.PreferredCharities?.Clear();
                changed = true;
                foreach (var pJustGivCharity in EditVM.PreferredjustGivingCharities)
                {
                    var c = JustGivingLogic.getOrCreateCharityRecordFromJustGivingCharityID(pJustGivCharity);
                    if (c != null)
                    {
                        User.PreferredCharities?.Add(new PreferredCharity {
                            CharityID = c.ID
                        });
                    }
                }
            }

            return(changed);
        }