Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        aqufitEntities entities = new aqufitEntities();

        if (this.CompetitionAthleteId > 0)
        {
            CompetitionAthlete athlete = entities.CompetitionAthletes.FirstOrDefault(a => a.Id == CompetitionAthleteId);
            if (athlete != null)
            {
                litName.Text        = athlete.AthleteName + " " + athlete.OverallRank + "(" + athlete.OverallScore + ")";
                imgAthlete.ImageUrl = athlete.ImgUrl;
                string html = "<ul>";
                if (athlete.Height.HasValue)
                {
                    double inch = Affine.Utils.UnitsUtil.systemDefaultToUnits(athlete.Height.Value, Affine.Utils.UnitsUtil.MeasureUnit.UNIT_INCHES);
                    html += "<li>Height: <em>" + Math.Floor(inch / 12.0) + "' " + Math.Ceiling(inch % 12.0) + "\"</em></li>";
                }
                if (athlete.Weight.HasValue)
                {
                    double lbs = Affine.Utils.UnitsUtil.systemDefaultToUnits(athlete.Weight.Value, Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS);
                    html += "<li>Weight: <em>" + Math.Round(lbs, 2) + "</em></li>";
                }
                html           += "<li>&nbsp;</li>";
                html           += "<li>Affiliate: <em>" + athlete.AffiliateName + "</em></li>";
                html           += "<li>Region: <em>" + athlete.RegionName + "</em></li>";
                html           += "<li>Hometown: <em>" + athlete.Hometown + "</em></li>";
                html           += "<li>Country: <em>" + athlete.Country + "</em></li>";
                html           += "</ul>";
                litDetails.Text = html;
            }
        }
    }
Ejemplo n.º 2
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            try
            {
                Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance;
                aqufitEntities entities = new aqufitEntities();
                switch (hiddenAjaxAction.Value)
                {
                case "updateAthleteScore":
                    CompetitionWODResult res = null;
                    try
                    {
                        long compAthlete = Convert.ToInt64(hiddenAjaxValue.Value);

                        long compWodKey            = Convert.ToInt64(hiddenCompWodKey.Value);
                        CompetitionAthlete athlete = entities.CompetitionAthletes.FirstOrDefault(a => a.Id == compAthlete && a.Competition.Id == CompetitionKey);
                        CompetitionWOD     compWod = entities.CompetitionWODs.Include("WOD").Include("WOD.WODType").FirstOrDefault(w => w.Id == compWodKey && w.Competition.Id == CompetitionKey && w.CompetitionCategory.Id == _compType);
                        // check if we have a score yet..
                        if (athlete != null && compWod != null)
                        {
                            res = entities.CompetitionWODResults.FirstOrDefault(r => r.CompetitionAthlete.Id == compAthlete && r.CompetitionWOD.Id == compWodKey);
                            double score = 0;

                            if (compWod.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.TIMED)
                            {
                                string[] ts      = hiddenAjaxValue2.Value.Split(':');
                                double   seconds = 0.0;
                                if (ts.Length == 3)
                                {
                                    seconds = Convert.ToDouble(ts[0]) * 60 * 60 + Convert.ToDouble(ts[1]) * 60 + Convert.ToDouble(ts[2]);
                                }
                                else if (ts.Length == 2)
                                {
                                    seconds = Convert.ToDouble(ts[0]) * 60 + Convert.ToDouble(ts[1]);
                                }
                                else if (ts.Length == 1)
                                {
                                    seconds = Convert.ToDouble(ts[0]);
                                }
                                else
                                {
                                    seconds = Convert.ToDouble(hiddenAjaxValue2.Value);
                                }
                                score = Affine.Utils.UnitsUtil.unitsToSystemDefualt(seconds, UnitsUtil.MeasureUnit.UNIT_SEC);     // TODO: switch between units..
                            }
                            else if (compWod.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.MAX_WEIGHT)
                            {
                                score = Convert.ToDouble(hiddenAjaxValue2.Value);
                                score = Affine.Utils.UnitsUtil.unitsToSystemDefualt(score, UnitsUtil.MeasureUnit.UNIT_LBS);     // TODO: switch between units..
                            }
                            else
                            {
                                score = Convert.ToDouble(hiddenAjaxValue2.Value);
                            }
                            if (res == null)
                            {
                                res = new CompetitionWODResult()
                                {
                                    CompetitionWOD     = compWod,
                                    CompetitionAthlete = athlete,
                                    WOD = compWod.WOD
                                };
                            }
                            res.Score = score;
                            entities.SaveChanges();
                        }
                    }
                    catch (Exception) {
                        if (res != null)
                        {
                            entities.DeleteObject(res);
                            entities.SaveChanges();
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.Actions.ShowFail('ERROR: There was a problem with the action (" + ex.StackTrace.Replace("'", "").Replace("\r", "").Replace("\n", "") + ")');");
            }
        }
Ejemplo n.º 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 + "'); ");
            }
        }
Ejemplo n.º 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 + "'); ");
        }