예제 #1
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", "") + ")');");
            }
        }
        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","") + ")');");
            }
        }