protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            string status = string.Empty;
            try
            {

                Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance;
                aqufitEntities entities = new aqufitEntities();
                switch (hiddenAjaxAction.Value)
                {
                    case "saveRegistration":
                        CompetitionRegistration registration = null;
                        if (string.IsNullOrWhiteSpace(hiddenAjaxRegistrationId.Value))
                        {
                            registration = new CompetitionRegistration();
                        }
                        else
                        {
                            long rId = Convert.ToInt64(hiddenAjaxRegistrationId.Value);
                            registration = entities.CompetitionRegistrations.FirstOrDefault(r => r.Id == rId);
                        }
                        registration.Competition = entities.Competitions.FirstOrDefault( c => c.Id == 1 ); // ********** TMP
                        User test = entities.UserSettings.OfType<User>().FirstOrDefault(u => u.Id == UserSettings.Id);
                        registration.UserSetting = test;
                        // we have a chance to correct user "miss information"
                        int compType = Convert.ToInt32( ddlCompetitionType.SelectedValue );
                        registration.RegistrationType = compType;
                        registration.DateTime = DateTime.Now;
                        if (!string.IsNullOrWhiteSpace(hiddenAjaxValue.Value))
                        {
                            long affilId = Convert.ToInt64(hiddenAjaxValue.Value);
                            registration.GroupAffiliate = entities.UserSettings.OfType<Group>().FirstOrDefault(g => g.Id == affilId);
                        }
                        if (compType == 1)
                        {
                            if (atiSlimControl.Email != test.UserEmail) test.UserEmail = atiSlimControl.Email;
                            if (atiBodyComp.Gender != test.Sex) test.Sex = atiBodyComp.Gender;
                            if (!test.BirthDate.HasValue || atiBodyComp.BirthDate != test.BirthDate.Value) test.BirthDate = atiBodyComp.BirthDate;
                            registration.RegistrationType = 1;  // individual
                            registration.MailingAddress = txtAddress.Text;
                            registration.ContactPhone = txtPhone.Text;
                            registration.ContactEmail = test.UserEmail;
                            registration.EmergContactName = txtEmergName.Text;
                            registration.EmergContactPhone = txtEmergPhone.Text;
                            registration.EmergContactRelation = txtEmergRelation.Text;
                            registration.ExtraInfo = txtMedical.Text;
                            // save and load the new registration ID
                            entities.SaveChanges();
                            registration = entities.CompetitionRegistrations.OrderByDescending(r => r.Id).FirstOrDefault(r => r.UserSetting.Id == UserSettings.Id);
                            hiddenAjaxRegistrationId.Value = "" + registration.Id;

                            // now we need to add the users PR's to their profiles...
                            SaveCompWorkoutPR();
                        }
                        else
                        {   // team registration...
                            registration.MailingAddress = txtTeamAddress.Text;
                            registration.ContactPhone = txtTeamPhone.Text;
                            registration.TeamName = txtTeamName.Text;
                            registration.ContactEmail = txtTeamEmail.Text;
                            registration.RegistrationType = 2;  // team

                            // save and load the new registration ID
                            entities.SaveChanges();
                            registration = entities.CompetitionRegistrations.OrderByDescending(r => r.Id).FirstOrDefault(r => r.UserSetting.Id == UserSettings.Id);
                            hiddenAjaxRegistrationId.Value = "" + registration.Id;
                        }

                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(6); ");
                        break;
                    case "checkTeamLimit":
                        long gId = Convert.ToInt64(hiddenAjaxValue.Value);
                        int count = entities.CompetitionRegistrations.Where(r => r.GroupAffiliate.Id == gId && r.RegistrationType == 2 ).Count(); // more the 2 affiliate teams alreay ??
                        if (count >= 2)
                        {
                            Group check = entities.UserSettings.OfType<Group>().FirstOrDefault( g => g.Id == gId );
                            RadAjaxManager1.ResponseScripts.Add(" alert('Sorry the affiliate [ " + check.UserFirstName + " ] already has 2 teams signed up.' );" );
                        }
                        else
                        {
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(3);");
                        }
                        break;
                    case "connectCompAthlete":
                        long aid = Convert.ToInt64(hiddenAjaxValue.Value);
                        CompetitionAthlete athlete = entities.CompetitionAthletes.Include("CompetitionWODs").Include("CompetitionWODs.WOD").Include("CompetitionWODs.WOD.WODType").Include("CompetitionAffiliate").Include("CompetitionAffiliate.CFAffiliate").Include("CompetitionAffiliate.CFAffiliate.UserSetting").FirstOrDefault(a => a.Id == aid);
                        // first lets get any info we can off the profile (weight, height)
                        User thisUser = entities.UserSettings.OfType<User>().Include("BodyCompositions").FirstOrDefault( u => u.Id == UserSettings.Id );
                        BodyComposition bc = thisUser.BodyCompositions.FirstOrDefault();
                        if (bc == null)
                        {
                            bc = new BodyComposition();
                            bc.UserSetting = thisUser;
                            entities.AddToBodyComposition(bc);
                        }
                        bc.Height = athlete.Height;
                        bc.Weight = athlete.Weight;
                        entities.SaveChanges();
                        bool loadImg = true;
                        try
                        {
                            Utils.ImageUtil.MakeImageProfilePic(Utils.ImageUtil.ReadImageDataFromUrl(athlete.ImgUrl), UserSettings.Id);
                        }
                        catch (Exception)
                        {
                            loadImg = false;
                        }
                        // next see if we can add them to any groups (via the affiliate)
                        if (athlete.CompetitionAffiliate != null && athlete.CompetitionAffiliate.CFAffiliate != null && athlete.CompetitionAffiliate.CFAffiliate.UserSetting != null)
                        {
                            dataMan.JoinGroup(thisUser.Id, athlete.CompetitionAffiliate.CFAffiliate.UserSetting.Id, ConstsUtil.Relationships.GROUP_MEMBER);
                        }
                        // now add all the games workouts to the site.
                        foreach (CompetitionWOD cw in athlete.CompetitionWODs)
                        {
                            // so far we think they are all AMRAPS
                            dataMan.SaveWorkout(thisUser, (int)Utils.WorkoutUtil.WorkoutType.CROSSFIT, (int)Utils.WorkoutUtil.DataSrc.MANUAL_NO_MAP, DateTime.Now, null, "", true, cw.WOD.Id, cw.Score, null);
                        }
                        if (loadImg)
                        {
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(2); ");
                        }
                        else
                        {
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(1); ");
                        }
                        break;
                    case "friendRequest":
                        long fid = Convert.ToInt64(hiddenAjaxValue.Value);
                        dataMan.sendFriendRequest(UserSettings.Id, fid);
                        status = "Friend request has been sent.";
                        break;
                    case "joinGroup":
                        long gid = Convert.ToInt64(hiddenAjaxValue.Value);
                        bool isOwner = hiddenAjaxValue2.Value == "true" ? true : false;
                        bool sendRequestToAll = hiddenAjaxValue3.Value == "1" ? true : false;
                        dataMan.JoinGroup(UserSettings.Id, gid, ConstsUtil.Relationships.GROUP_MEMBER);
                        Group group = entities.UserSettings.OfType<Group>().FirstOrDefault(g => g.Id == gid);
                        if (sendRequestToAll)
                        {
                            long[] memberIdArray = entities.UserFriends.Where(g => (g.DestUserSettingKey == gid || g.SrcUserSettingKey == gid) && g.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER).Select(g => (g.DestUserSettingKey == gid ? g.SrcUserSettingKey : g.DestUserSettingKey)).ToArray();
                            int numMembers = memberIdArray.Length;
                            foreach (long mid in memberIdArray)
                            {
                                dataMan.sendFriendRequest(UserSettings.Id, mid);
                            }
                        }
                        if (isOwner)
                        {
                            dataMan.makeGroupOwnerRequest(UserSettings as User, group);
                        }
                        if (Request["step"] != null)
                        {   // todo: store this owne
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.JoinGroupDialog.close(); Aqufit.Page.Actions.LoadStep(4); ");
                        }
                        else
                        {
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.JoinGroupDialog.close(); Aqufit.Windows.SuccessDialog.open(\"{'html':'You have been added to the group.'}\");");
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                status = "ERROR: There was a problem with the action (" + ex.Message + ex.StackTrace.Replace("'","").Replace("\n","")+")";
                RadAjaxManager1.ResponseScripts.Add("alert('" + status + "'); ");
            }
        }
Example #2
0
        protected void bBodyComposition_Click(object sender, EventArgs e)
        {
            // TODO: check inputs for error
            UserSettings userSettings = new UserSettings();

            if (atiBodyComposition.BirthDate == null)
            {
                lErrorText.Text = "You must enter your Birthdate.";
                return;
            }
            if (string.IsNullOrEmpty(atiBodyComposition.Weight))
            {
                lErrorText.Text = "You must enter your weight.";
                return;
            }
            userSettings.BirthDate = Convert.ToDateTime(atiBodyComposition.BirthDate);
            //userSettings.DistanceUnits = (short)atiBodyComposition.DistanceUnits;
            userSettings.HeightUnits = (short)atiBodyComposition.HeightUnits;
            userSettings.WeightUnits = (short)atiBodyComposition.WeightUnits;
            userSettings.UserKey     = UserId;
            userSettings.PortalKey   = PortalId;
            userSettings.Sex         = atiBodyComposition.Gender;

            aqufitEntities aqufitEntities = new aqufitEntities();

            aqufitEntities.AddToUserSettings(userSettings);


            BodyComposition bc = new BodyComposition()
            {
                UserKey      = UserId,
                PortalKey    = PortalId,
                FitnessLevel = atiBodyComposition.FitnessLevel
            };

            // need height and weight conversions
            bc.Modified       = DateTime.Now;
            bc.BodyFatPercent = 0.0;
            bc.Weight         = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyComposition.Weight), atiBodyComposition.WeightUnits);

            // bc.Height = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyComposition.Height), atiBodyComposition.HeightUnits);
            aqufitEntities.AddToBodyComposition(bc);

            BodyMeasurments bm = new BodyMeasurments()
            {
                UserKey   = UserId,
                PortalKey = PortalId
            };

            Affine.Utils.UnitsUtil.MeasureUnit bmUnits = atiBodyComposition.HeightUnits == Affine.Utils.UnitsUtil.MeasureUnit.UNIT_INCHES ? Affine.Utils.UnitsUtil.MeasureUnit.UNIT_INCHES : Affine.Utils.UnitsUtil.MeasureUnit.UNIT_CM;
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Chest))
            {
                bm.Chest = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Chest), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Neck))
            {
                bm.Neck = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Neck), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Shoulders))
            {
                bm.Shoulders = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Shoulders), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Stomach))
            {
                bm.Stomach = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Stomach), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Waist))
            {
                bm.Waist = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Waist), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Hips))
            {
                bm.Hips = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Hips), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.BicepLeft))
            {
                bm.BicepLeft = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.BicepLeft), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.BicepRight))
            {
                bm.BicepRight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.BicepRight), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.ForearmLeft))
            {
                bm.ForearmLeft = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.ForearmLeft), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.ForearmRight))
            {
                bm.ForearmRight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.ForearmRight), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.ThighLeft))
            {
                bm.ThighLeft = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.ThighLeft), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.ThighRight))
            {
                bm.ThighRight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.ThighRight), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.CalfLeft))
            {
                bm.CalfLeft = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.CalfLeft), bmUnits);
            }
            if (!string.IsNullOrEmpty(atiBodyMeasurements.CalfLeft))
            {
                bm.CalfRight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.CalfRight), bmUnits);
            }
            bm.Modified = DateTime.Now;
            aqufitEntities.AddToBodyMeasurments(bm);

            aqufitEntities.SaveChanges();

            bBodyComposition.Visible = false;
            bProfile.Visible         = true;
            RadAjaxManager1.ResponseScripts.Add("AjaxResponseSuccess();");
        }
Example #3
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            string status = string.Empty;

            try
            {
                Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance;
                aqufitEntities entities = new aqufitEntities();
                switch (hiddenAjaxAction.Value)
                {
                case "saveRegistration":
                    CompetitionRegistration registration = null;
                    if (string.IsNullOrWhiteSpace(hiddenAjaxRegistrationId.Value))
                    {
                        registration = new CompetitionRegistration();
                    }
                    else
                    {
                        long rId = Convert.ToInt64(hiddenAjaxRegistrationId.Value);
                        registration = entities.CompetitionRegistrations.FirstOrDefault(r => r.Id == rId);
                    }
                    registration.Competition = entities.Competitions.FirstOrDefault(c => c.Id == 1);       // ********** TMP
                    User test = entities.UserSettings.OfType <User>().FirstOrDefault(u => u.Id == UserSettings.Id);
                    registration.UserSetting = test;
                    // we have a chance to correct user "miss information"
                    int compType = Convert.ToInt32(ddlCompetitionType.SelectedValue);
                    registration.RegistrationType = compType;
                    registration.DateTime         = DateTime.Now;
                    if (!string.IsNullOrWhiteSpace(hiddenAjaxValue.Value))
                    {
                        long affilId = Convert.ToInt64(hiddenAjaxValue.Value);
                        registration.GroupAffiliate = entities.UserSettings.OfType <Group>().FirstOrDefault(g => g.Id == affilId);
                    }
                    if (compType == 1)
                    {
                        if (atiSlimControl.Email != test.UserEmail)
                        {
                            test.UserEmail = atiSlimControl.Email;
                        }
                        if (atiBodyComp.Gender != test.Sex)
                        {
                            test.Sex = atiBodyComp.Gender;
                        }
                        if (!test.BirthDate.HasValue || atiBodyComp.BirthDate != test.BirthDate.Value)
                        {
                            test.BirthDate = atiBodyComp.BirthDate;
                        }
                        registration.RegistrationType     = 1;  // individual
                        registration.MailingAddress       = txtAddress.Text;
                        registration.ContactPhone         = txtPhone.Text;
                        registration.ContactEmail         = test.UserEmail;
                        registration.EmergContactName     = txtEmergName.Text;
                        registration.EmergContactPhone    = txtEmergPhone.Text;
                        registration.EmergContactRelation = txtEmergRelation.Text;
                        registration.ExtraInfo            = txtMedical.Text;
                        // save and load the new registration ID
                        entities.SaveChanges();
                        registration = entities.CompetitionRegistrations.OrderByDescending(r => r.Id).FirstOrDefault(r => r.UserSetting.Id == UserSettings.Id);
                        hiddenAjaxRegistrationId.Value = "" + registration.Id;

                        // now we need to add the users PR's to their profiles...
                        SaveCompWorkoutPR();
                    }
                    else
                    {       // team registration...
                        registration.MailingAddress   = txtTeamAddress.Text;
                        registration.ContactPhone     = txtTeamPhone.Text;
                        registration.TeamName         = txtTeamName.Text;
                        registration.ContactEmail     = txtTeamEmail.Text;
                        registration.RegistrationType = 2;      // team

                        // save and load the new registration ID
                        entities.SaveChanges();
                        registration = entities.CompetitionRegistrations.OrderByDescending(r => r.Id).FirstOrDefault(r => r.UserSetting.Id == UserSettings.Id);
                        hiddenAjaxRegistrationId.Value = "" + registration.Id;
                    }

                    RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(6); ");
                    break;

                case "checkTeamLimit":
                    long gId   = Convert.ToInt64(hiddenAjaxValue.Value);
                    int  count = entities.CompetitionRegistrations.Where(r => r.GroupAffiliate.Id == gId && r.RegistrationType == 2).Count();     // more the 2 affiliate teams alreay ??
                    if (count >= 2)
                    {
                        Group check = entities.UserSettings.OfType <Group>().FirstOrDefault(g => g.Id == gId);
                        RadAjaxManager1.ResponseScripts.Add(" alert('Sorry the affiliate [ " + check.UserFirstName + " ] already has 2 teams signed up.' );");
                    }
                    else
                    {
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(3);");
                    }
                    break;

                case "connectCompAthlete":
                    long aid = Convert.ToInt64(hiddenAjaxValue.Value);
                    CompetitionAthlete athlete = entities.CompetitionAthletes.Include("CompetitionWODs").Include("CompetitionWODs.WOD").Include("CompetitionWODs.WOD.WODType").Include("CompetitionAffiliate").Include("CompetitionAffiliate.CFAffiliate").Include("CompetitionAffiliate.CFAffiliate.UserSetting").FirstOrDefault(a => a.Id == aid);
                    // first lets get any info we can off the profile (weight, height)
                    User            thisUser = entities.UserSettings.OfType <User>().Include("BodyCompositions").FirstOrDefault(u => u.Id == UserSettings.Id);
                    BodyComposition bc       = thisUser.BodyCompositions.FirstOrDefault();
                    if (bc == null)
                    {
                        bc             = new BodyComposition();
                        bc.UserSetting = thisUser;
                        entities.AddToBodyComposition(bc);
                    }
                    bc.Height = athlete.Height;
                    bc.Weight = athlete.Weight;
                    entities.SaveChanges();
                    bool loadImg = true;
                    try
                    {
                        Utils.ImageUtil.MakeImageProfilePic(Utils.ImageUtil.ReadImageDataFromUrl(athlete.ImgUrl), UserSettings.Id);
                    }
                    catch (Exception)
                    {
                        loadImg = false;
                    }
                    // next see if we can add them to any groups (via the affiliate)
                    if (athlete.CompetitionAffiliate != null && athlete.CompetitionAffiliate.CFAffiliate != null && athlete.CompetitionAffiliate.CFAffiliate.UserSetting != null)
                    {
                        dataMan.JoinGroup(thisUser.Id, athlete.CompetitionAffiliate.CFAffiliate.UserSetting.Id, ConstsUtil.Relationships.GROUP_MEMBER);
                    }
                    // now add all the games workouts to the site.
                    foreach (CompetitionWOD cw in athlete.CompetitionWODs)
                    {
                        // so far we think they are all AMRAPS
                        dataMan.SaveWorkout(thisUser, (int)Utils.WorkoutUtil.WorkoutType.CROSSFIT, (int)Utils.WorkoutUtil.DataSrc.MANUAL_NO_MAP, DateTime.Now, null, "", true, cw.WOD.Id, cw.Score, null);
                    }
                    if (loadImg)
                    {
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(2); ");
                    }
                    else
                    {
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(1); ");
                    }
                    break;

                case "friendRequest":
                    long fid = Convert.ToInt64(hiddenAjaxValue.Value);
                    dataMan.sendFriendRequest(UserSettings.Id, fid);
                    status = "Friend request has been sent.";
                    break;

                case "joinGroup":
                    long gid              = Convert.ToInt64(hiddenAjaxValue.Value);
                    bool isOwner          = hiddenAjaxValue2.Value == "true" ? true : false;
                    bool sendRequestToAll = hiddenAjaxValue3.Value == "1" ? true : false;
                    dataMan.JoinGroup(UserSettings.Id, gid, ConstsUtil.Relationships.GROUP_MEMBER);
                    Group group = entities.UserSettings.OfType <Group>().FirstOrDefault(g => g.Id == gid);
                    if (sendRequestToAll)
                    {
                        long[] memberIdArray = entities.UserFriends.Where(g => (g.DestUserSettingKey == gid || g.SrcUserSettingKey == gid) && g.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER).Select(g => (g.DestUserSettingKey == gid ? g.SrcUserSettingKey : g.DestUserSettingKey)).ToArray();
                        int    numMembers    = memberIdArray.Length;
                        foreach (long mid in memberIdArray)
                        {
                            dataMan.sendFriendRequest(UserSettings.Id, mid);
                        }
                    }
                    if (isOwner)
                    {
                        dataMan.makeGroupOwnerRequest(UserSettings as User, group);
                    }
                    if (Request["step"] != null)
                    {       // todo: store this owne
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.JoinGroupDialog.close(); Aqufit.Page.Actions.LoadStep(4); ");
                    }
                    else
                    {
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.JoinGroupDialog.close(); Aqufit.Windows.SuccessDialog.open(\"{'html':'You have been added to the group.'}\");");
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                status = "ERROR: There was a problem with the action (" + ex.Message + ex.StackTrace.Replace("'", "").Replace("\n", "") + ")";
                RadAjaxManager1.ResponseScripts.Add("alert('" + status + "'); ");
            }
        }
Example #4
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            string status = string.Empty;

            try
            {
                Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance;
                aqufitEntities entities = new aqufitEntities();
                switch (hiddenAjaxAction.Value)
                {
                case "connectCompAthlete":
                    long aid = Convert.ToInt64(hiddenAjaxValue.Value);
                    CompetitionAthlete athlete = entities.CompetitionAthletes.Include("CompetitionWODs").Include("CompetitionWODs.WOD").Include("CompetitionWODs.WOD.WODType").Include("CompetitionAffiliate").Include("CompetitionAffiliate.CFAffiliate").Include("CompetitionAffiliate.CFAffiliate.UserSetting").FirstOrDefault(a => a.Id == aid);
                    // first lets get any info we can off the profile (weight, height)
                    User            thisUser = entities.UserSettings.OfType <User>().Include("BodyCompositions").FirstOrDefault(u => u.Id == UserSettings.Id);
                    BodyComposition bc       = thisUser.BodyCompositions.FirstOrDefault();
                    if (bc == null)
                    {
                        bc             = new BodyComposition();
                        bc.UserSetting = thisUser;
                        entities.AddToBodyComposition(bc);
                    }
                    bc.Height = athlete.Height;
                    bc.Weight = athlete.Weight;
                    entities.SaveChanges();
                    bool loadImg = true;
                    try
                    {
                        Utils.ImageUtil.MakeImageProfilePic(Utils.ImageUtil.ReadImageDataFromUrl(athlete.ImgUrl), UserSettings.Id);
                    }
                    catch (Exception)
                    {
                        loadImg = false;
                    }
                    // next see if we can add them to any groups (via the affiliate)
                    if (athlete.CompetitionAffiliate != null && athlete.CompetitionAffiliate.CFAffiliate != null && athlete.CompetitionAffiliate.CFAffiliate.UserSetting != null)
                    {
                        dataMan.JoinGroup(thisUser.Id, athlete.CompetitionAffiliate.CFAffiliate.UserSetting.Id, ConstsUtil.Relationships.GROUP_MEMBER);
                    }
                    // now add all the games workouts to the site.
                    foreach (CompetitionWOD cw in athlete.CompetitionWODs)
                    {
                        // so far we think they are all AMRAPS
                        dataMan.SaveWorkout(thisUser, (int)Utils.WorkoutUtil.WorkoutType.CROSSFIT, (int)Utils.WorkoutUtil.DataSrc.MANUAL_NO_MAP, DateTime.Now, null, "", true, cw.WOD.Id, cw.Score, null);
                    }
                    if (loadImg)
                    {
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(2); ");
                    }
                    else
                    {
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(1); ");
                    }
                    break;

                case "friendRequest":
                    long fid = Convert.ToInt64(hiddenAjaxValue.Value);
                    dataMan.sendFriendRequest(UserSettings.Id, fid);
                    status = "Friend request has been sent.";
                    break;

                case "joinGroup":
                    long gid              = Convert.ToInt64(hiddenAjaxValue.Value);
                    bool isOwner          = hiddenAjaxValue2.Value == "true" ? true : false;
                    bool sendRequestToAll = hiddenAjaxValue3.Value == "1" ? true : false;
                    dataMan.JoinGroup(UserSettings.Id, gid, ConstsUtil.Relationships.GROUP_MEMBER);
                    Group group = entities.UserSettings.OfType <Group>().FirstOrDefault(g => g.Id == gid);
                    if (sendRequestToAll)
                    {
                        long[] memberIdArray = entities.UserFriends.Where(g => (g.DestUserSettingKey == gid || g.SrcUserSettingKey == gid) && g.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER).Select(g => (g.DestUserSettingKey == gid ? g.SrcUserSettingKey : g.DestUserSettingKey)).ToArray();
                        int    numMembers    = memberIdArray.Length;
                        foreach (long mid in memberIdArray)
                        {
                            dataMan.sendFriendRequest(UserSettings.Id, mid);
                        }
                    }
                    if (isOwner)
                    {
                        dataMan.makeGroupOwnerRequest(UserSettings as User, group);
                    }
                    if (Request["step"] != null)
                    {       // todo: store this owne
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.JoinGroupDialog.close(); Aqufit.Page.Actions.LoadStep(4); ");
                    }
                    else
                    {
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.JoinGroupDialog.close(); Aqufit.Windows.SuccessDialog.open(\"{'html':'You have been added to the group.'}\");");
                    }

                    break;

                case "toggleDotCom":
                    int join = Convert.ToInt32(hiddenAjaxValue.Value);

                    if (join == 1)
                    {
                        dataMan.JoinGroup(UserSettings.Id, CROSSFIT_COM_ID, ConstsUtil.Relationships.GROUP_MEMBER);
                    }
                    else if (join == 0)
                    {
                        dataMan.LeaveGroup(UserSettings.Id, CROSSFIT_COM_ID);
                    }
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.atiLoading.remove(); ");
                    break;
                }
            }
            catch (Exception ex)
            {
                status = "ERROR: There was a problem with the action (" + ex.Message + ")";
            }
            RadAjaxManager1.ResponseScripts.Add("UpdateStatus('" + status + "'); ");
        }
        private UserSettings populateUserSettings(UserSettings us, UserInfo ui)
        {
            aqufitEntities entities = new aqufitEntities();

            long usId = us.Id;
            us.UserKey = ui.UserID;
            us.PortalKey = ui.PortalID;
            us.UserEmail = ui.Email;
            us.UserName = ui.Username;
            us.UserFirstName = ui.FirstName;
            us.UserLastName = ui.LastName;
            //us.TimeZone = ui.Profile.TimeZone;
            if (atiBodyComp.Visible)
            {
                if (atiBodyComp.GenderVisible)
                {
                    us.Sex = atiBodyComp.Gender;
                }
                if (atiBodyComp.BirthDateVisible && atiBodyComp.BirthDate.HasValue)
                {
                    us.BirthDate = Convert.ToDateTime(atiBodyComp.BirthDate);
                }
                if (atiBodyComp.WeightVisible)
                {
                    us.WeightUnits = Convert.ToInt16(atiBodyComp.WeightUnits);
                }
                if (atiBodyComp.HeightVisible)
                {
                    us.HeightUnits = Convert.ToInt16(atiBodyComp.HeightUnits);
                }
            }
            if (ddlHomeGroup.Items.Count > 0 )
            {
                us.MainGroupKey = Convert.ToInt64( ddlHomeGroup.SelectedValue );
            }
            if (atiHeightWeight.Visible)
            {
                BodyComposition bc = entities.BodyComposition.FirstOrDefault(b => b.UserSetting.Id == us.Id);
                if( bc == null ){
                    bc = new BodyComposition(){
                        UserSetting = entities.UserSettings.FirstOrDefault( u => u.Id == us.Id ),
                    };
                    entities.AddToBodyComposition(bc);
                }
                if (atiHeightWeight.WeightVisible)
                {
                    bc.Weight = atiHeightWeight.UserWeightInSystemDefault;
                }
                if (atiHeightWeight.HeightVisible)
                {
                    bc.Height = atiHeightWeight.UserHeightInSystemDefault;
                }
                bc.Bio = txtBio.Text;
                bc.Description = txtTraining.Text;
                entities.SaveChanges();
            }
            ASP.desktopmodules_ati_base_controls_ati_slimcontrol_ascx slim = atiSlimControl.Visible ? atiSlimControl : (atiSlimFBSetup.Visible ? atiSlimFBSetup : null);
            if (slim != null)
            {
                if (!string.IsNullOrEmpty(slim.LocLat))
                {
                    us.DefaultMapLat = Convert.ToDouble(slim.LocLat);
                    us.LatHome = us.DefaultMapLat;
                }
                if (!string.IsNullOrEmpty(slim.LocLng))
                {
                    us.DefaultMapLng = Convert.ToDouble(slim.LocLng);
                    us.LngHome = us.DefaultMapLng;
                }
                us.RemoteAddress = slim.Address;
            }
            UserSettingsExtended[] webLinks = entities.UserSettingsExtendeds.Where(s => s.UserSetting.Id == usId && s.Class == 1).ToArray();
            if (atiWebLinks.Visible)
            {
                // Facebook
                UserSettingsExtended facebook = webLinks.FirstOrDefault(s => s.Name == "Facebook");
                if (!string.IsNullOrEmpty(atiWebLinks.Facebook))
                {
                    if (facebook == null)
                    {
                        facebook = new UserSettingsExtended()
                        {
                            Class = 1,
                            Name = "Facebook",
                            Value = atiWebLinks.Facebook
                        };
                        us.UserSettingsExtendeds.Add(facebook);
                    }
                    else
                    {
                        facebook.Value = atiWebLinks.Facebook;
                    }
                }
                else if (facebook != null)
                {
                    entities.DeleteObject(facebook);
                }

                // Twitter
                UserSettingsExtended twitter = webLinks.FirstOrDefault(s => s.Name == "Twitter");
                if (!string.IsNullOrEmpty(atiWebLinks.Twitter))
                {
                    if (twitter == null)
                    {
                        twitter = new UserSettingsExtended()
                        {
                            Class = 1,
                            Name = "Twitter",
                            Value = atiWebLinks.Twitter
                        };
                        us.UserSettingsExtendeds.Add(twitter);
                    }
                    else
                    {
                        twitter.Value = atiWebLinks.Twitter;
                    }
                }
                else if (twitter != null)
                {
                    entities.DeleteObject(twitter);
                }

                // YouTube
                UserSettingsExtended youtube = webLinks.FirstOrDefault(s => s.Name == "YouTube");
                if (!string.IsNullOrEmpty(atiWebLinks.YouTube))
                {

                    if (youtube == null)
                    {
                        youtube = new UserSettingsExtended()
                        {
                            Class = 1,
                            Name = "YouTube",
                            Value = atiWebLinks.YouTube
                        };
                        us.UserSettingsExtendeds.Add(youtube);
                    }
                    else
                    {
                        youtube.Value = atiWebLinks.YouTube;
                    }
                }
                else if (youtube != null)
                {
                    entities.DeleteObject(youtube);
                }

                // LinkedIn
                UserSettingsExtended linkedin = webLinks.FirstOrDefault(s => s.Name == "LinkedIn");
                if (!string.IsNullOrEmpty(atiWebLinks.LinkedIn))
                {
                    if (linkedin == null)
                    {
                        linkedin = new UserSettingsExtended()
                        {
                            Class = 1,
                            Name = "LinkedIn",
                            Value = atiWebLinks.LinkedIn
                        };
                        us.UserSettingsExtendeds.Add(linkedin);
                    }
                    else
                    {
                        linkedin.Value = atiWebLinks.LinkedIn;
                    }
                }
                else if (linkedin != null)
                {
                    entities.DeleteObject(linkedin);
                }

                // Flickr
                UserSettingsExtended flickr = webLinks.FirstOrDefault(s => s.Name == "Flickr");
                if (!string.IsNullOrEmpty(atiWebLinks.Flickr))
                {
                    if (flickr == null)
                    {
                        flickr = new UserSettingsExtended()
                        {
                            Class = 1,
                            Name = "Flickr",
                            Value = atiWebLinks.Flickr
                        };
                        us.UserSettingsExtendeds.Add(flickr);
                    }
                    else
                    {
                        flickr.Value = atiWebLinks.Flickr;
                    }
                }
                else if (flickr != null)
                {
                    entities.DeleteObject(flickr);
                }

                // Personal
                UserSettingsExtended personal = webLinks.FirstOrDefault(s => s.Name == "Personal");
                if (!string.IsNullOrEmpty(atiWebLinks.Peronsal))
                {
                    if (personal == null)
                    {
                        personal = new UserSettingsExtended()
                        {
                            Class = 1,
                            Name = "Personal",
                            Value = atiWebLinks.Peronsal
                        };
                        us.UserSettingsExtendeds.Add(personal);
                    }
                    else
                    {
                        personal.Value = atiWebLinks.Peronsal;
                    }
                }
                else if (personal != null)
                {
                    entities.DeleteObject(personal);
                }

                entities.SaveChanges();
            }
            return us;
        }
Example #6
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            string status = string.Empty;
            try
            {
                Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance;
                aqufitEntities entities = new aqufitEntities();
                switch (hiddenAjaxAction.Value)
                {
                    case "connectCompAthlete":
                        long aid = Convert.ToInt64(hiddenAjaxValue.Value);
                        CompetitionAthlete athlete = entities.CompetitionAthletes.Include("CompetitionWODs").Include("CompetitionWODs.WOD").Include("CompetitionWODs.WOD.WODType").Include("CompetitionAffiliate").Include("CompetitionAffiliate.CFAffiliate").Include("CompetitionAffiliate.CFAffiliate.UserSetting").FirstOrDefault(a => a.Id == aid);
                        // first lets get any info we can off the profile (weight, height)
                        User thisUser = entities.UserSettings.OfType<User>().Include("BodyCompositions").FirstOrDefault( u => u.Id == UserSettings.Id );
                        BodyComposition bc = thisUser.BodyCompositions.FirstOrDefault();
                        if (bc == null)
                        {
                            bc = new BodyComposition();
                            bc.UserSetting = thisUser;
                            entities.AddToBodyComposition(bc);
                        }
                        bc.Height = athlete.Height;
                        bc.Weight = athlete.Weight;
                        entities.SaveChanges();
                        bool loadImg = true;
                        try
                        {
                            Utils.ImageUtil.MakeImageProfilePic(Utils.ImageUtil.ReadImageDataFromUrl(athlete.ImgUrl), UserSettings.Id);
                        }
                        catch (Exception)
                        {
                            loadImg = false;
                        }
                        // next see if we can add them to any groups (via the affiliate)
                        if (athlete.CompetitionAffiliate != null && athlete.CompetitionAffiliate.CFAffiliate != null && athlete.CompetitionAffiliate.CFAffiliate.UserSetting != null)
                        {
                            dataMan.JoinGroup(thisUser.Id, athlete.CompetitionAffiliate.CFAffiliate.UserSetting.Id, ConstsUtil.Relationships.GROUP_MEMBER);
                        }
                        // now add all the games workouts to the site.
                        foreach (CompetitionWOD cw in athlete.CompetitionWODs)
                        {
                            // so far we think they are all AMRAPS
                            dataMan.SaveWorkout(thisUser, (int)Utils.WorkoutUtil.WorkoutType.CROSSFIT, (int)Utils.WorkoutUtil.DataSrc.MANUAL_NO_MAP, DateTime.Now, null, "", true, cw.WOD.Id, cw.Score, null);
                        }
                        if (loadImg)
                        {
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(2); ");
                        }
                        else
                        {
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.LoadStep(1); ");
                        }
                        break;
                    case "friendRequest":
                        long fid = Convert.ToInt64(hiddenAjaxValue.Value);
                        dataMan.sendFriendRequest(UserSettings.Id, fid);
                        status = "Friend request has been sent.";
                        break;
                    case "joinGroup":
                        long gid = Convert.ToInt64(hiddenAjaxValue.Value);
                        bool isOwner = hiddenAjaxValue2.Value == "true" ? true : false;
                        bool sendRequestToAll = hiddenAjaxValue3.Value == "1" ? true : false;
                        dataMan.JoinGroup(UserSettings.Id, gid, ConstsUtil.Relationships.GROUP_MEMBER);
                        Group group = entities.UserSettings.OfType<Group>().FirstOrDefault(g => g.Id == gid);
                        if (sendRequestToAll)
                        {
                            long[] memberIdArray = entities.UserFriends.Where(g => (g.DestUserSettingKey == gid || g.SrcUserSettingKey == gid) && g.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER).Select(g => (g.DestUserSettingKey == gid ? g.SrcUserSettingKey : g.DestUserSettingKey)).ToArray();
                            int numMembers = memberIdArray.Length;
                            foreach (long mid in memberIdArray)
                            {
                                dataMan.sendFriendRequest(UserSettings.Id, mid);
                            }
                        }
                        if (isOwner)
                        {
                            dataMan.makeGroupOwnerRequest(UserSettings as User, group);
                        }
                        if (Request["step"] != null)
                        {   // todo: store this owne
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.JoinGroupDialog.close(); Aqufit.Page.Actions.LoadStep(4); ");
                        }
                        else
                        {
                            RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.JoinGroupDialog.close(); Aqufit.Windows.SuccessDialog.open(\"{'html':'You have been added to the group.'}\");");
                        }

                        break;
                    case "toggleDotCom":
                        int join = Convert.ToInt32(hiddenAjaxValue.Value);

                        if (join == 1)
                        {
                            dataMan.JoinGroup(UserSettings.Id, CROSSFIT_COM_ID, ConstsUtil.Relationships.GROUP_MEMBER);
                        }
                        else if (join == 0)
                        {
                            dataMan.LeaveGroup(UserSettings.Id, CROSSFIT_COM_ID);
                        }
                        RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.atiLoading.remove(); ");
                        break;
                }
            }
            catch (Exception ex)
            {
                status = "ERROR: There was a problem with the action (" + ex.Message + ")";
            }
            RadAjaxManager1.ResponseScripts.Add("UpdateStatus('" + status + "'); ");
        }
Example #7
0
        protected void bBodyComposition_Click(object sender, EventArgs e)
        {
            // TODO: check inputs for error
            UserSettings userSettings = new UserSettings();
            if (atiBodyComposition.BirthDate == null)
            {
                lErrorText.Text = "You must enter your Birthdate.";
                return;
            }
            if (string.IsNullOrEmpty( atiBodyComposition.Weight ))
            {
                lErrorText.Text = "You must enter your weight.";
                return;
            }
            userSettings.BirthDate = Convert.ToDateTime(atiBodyComposition.BirthDate);
            //userSettings.DistanceUnits = (short)atiBodyComposition.DistanceUnits;
            userSettings.HeightUnits = (short)atiBodyComposition.HeightUnits;
            userSettings.WeightUnits = (short)atiBodyComposition.WeightUnits;
            userSettings.UserKey = UserId;
            userSettings.PortalKey = PortalId;
            userSettings.Sex = atiBodyComposition.Gender;

            aqufitEntities aqufitEntities = new aqufitEntities();
            aqufitEntities.AddToUserSettings(userSettings);

            BodyComposition bc = new BodyComposition()
            {
                UserKey = UserId,
                PortalKey = PortalId,
                FitnessLevel = atiBodyComposition.FitnessLevel
            };

            // need height and weight conversions
            bc.Modified = DateTime.Now;
            bc.BodyFatPercent = 0.0;
            bc.Weight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyComposition.Weight), atiBodyComposition.WeightUnits);

               // bc.Height = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyComposition.Height), atiBodyComposition.HeightUnits);
            aqufitEntities.AddToBodyComposition(bc);

            BodyMeasurments bm = new BodyMeasurments()
            {
                UserKey = UserId,
                PortalKey = PortalId
            };
            Affine.Utils.UnitsUtil.MeasureUnit bmUnits = atiBodyComposition.HeightUnits == Affine.Utils.UnitsUtil.MeasureUnit.UNIT_INCHES ? Affine.Utils.UnitsUtil.MeasureUnit.UNIT_INCHES : Affine.Utils.UnitsUtil.MeasureUnit.UNIT_CM;
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Chest)) bm.Chest = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Chest), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Neck)) bm.Neck = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Neck), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Shoulders)) bm.Shoulders = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Shoulders), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Stomach)) bm.Stomach = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Stomach), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Waist)) bm.Waist = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Waist), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.Hips)) bm.Hips = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.Hips), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.BicepLeft)) bm.BicepLeft = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.BicepLeft), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.BicepRight)) bm.BicepRight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.BicepRight), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.ForearmLeft)) bm.ForearmLeft = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.ForearmLeft), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.ForearmRight)) bm.ForearmRight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.ForearmRight), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.ThighLeft)) bm.ThighLeft = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.ThighLeft), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.ThighRight)) bm.ThighRight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.ThighRight), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.CalfLeft)) bm.CalfLeft = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.CalfLeft), bmUnits);
            if (!string.IsNullOrEmpty(atiBodyMeasurements.CalfLeft)) bm.CalfRight = Affine.Utils.UnitsUtil.unitsToSystemDefualt(Convert.ToDouble(atiBodyMeasurements.CalfRight), bmUnits);
            bm.Modified = DateTime.Now;
            aqufitEntities.AddToBodyMeasurments(bm);

            aqufitEntities.SaveChanges();

            bBodyComposition.Visible = false;
            bProfile.Visible = true;
            RadAjaxManager1.ResponseScripts.Add("AjaxResponseSuccess();");
        }