Пример #1
0
        public ActionResult SelectTee(int?id, string gender, string teeName, DateTime playStartDateTime)
        {
            // here, build up Round so it can have
            // Round.UserName, Round.PlayStartDate, Round.Course.CourseName, Round.Course.Rating/Slope
            // Round.ScoreCards... That's it!!!

            Course course = db.Courses.Find(id);

            // create top 3 rows for scorecard
            TeeCommonInfo tciPar =
                (from a in course.TCInfos where a.Gender == gender where a.Theme == "Par" select a).FirstOrDefault();

            TeeCommonInfo tciHandicap =
                (from a in course.TCInfos where a.Gender == gender where a.Theme == "Handicap" select a).FirstOrDefault();

            TeeCommonInfo tciDistance =
                (from a in course.TCInfos where a.Gender == gender where a.Theme == "Distance" where a.Name == teeName select a).FirstOrDefault();

            // create a new empty round so that we can have a roundID
            Round round = new Round()
            {
                RecordDate = DateTime.Now, PlayDate = playStartDateTime, PlayStartTime = playStartDateTime, PlayEndTime = playStartDateTime.AddHours(4.5), CourseID = course.GCID, TeeID = tciDistance.TCID
            };

            round.Course = course;

            string aaa = User.Identity.GetUserId();

            round.UserGUID = Guid.Parse(User.Identity.GetUserId());
            round.UserName = User.Identity.Name;

            // to get a roundID
            // save partial info to round, later once a user completed entering score, then fully save it
            db.Rounds.Add(round);
            db.SaveChanges();

            // ??? here ???
            // do I have to do this?
            course.Rounds.Add(round);

            // create all the score card rows
            ScoreCard sc0 = new ScoreCard()
            {
                CreateDate = DateTime.Today,
                UpdateDate = DateTime.Today,
                //FRID = round.RID,
                FTCID     = tciPar.TCID,
                RowNumber = 0,
                Theme     = "Par"
            };
            ScoreCard sc1 = new ScoreCard()
            {
                CreateDate = DateTime.Today,
                UpdateDate = DateTime.Today,
                //FRID = round.RID,
                FTCID     = tciHandicap.TCID,
                RowNumber = 1,
                Theme     = "Handicap"
            };
            ScoreCard sc2 = new ScoreCard()
            {
                CreateDate = DateTime.Today,
                UpdateDate = DateTime.Today,
                //FRID = round.RID,
                FTCID     = tciDistance.TCID,
                RowNumber = 2,
                Theme     = "Distance"
            };

            CopyPropertiesH(tciPar, sc0);
            CopyPropertiesH(tciHandicap, sc1);
            CopyPropertiesH(tciDistance, sc2);

            // here I'm going to add or delete something for changes
            //
            // now I can finish my edit

            sc0.HOut   = tciPar.HOut;
            sc0.HIn    = tciPar.HIn;
            sc0.HTotal = tciPar.HTotal;
            sc1.HOut   = tciHandicap.HOut;
            sc1.HIn    = tciHandicap.HIn;
            sc1.HTotal = tciHandicap.HTotal;
            sc2.HOut   = tciDistance.HOut;
            sc2.HIn    = tciDistance.HIn;
            sc2.HTotal = tciDistance.HTotal;

            List <ScoreCard> scoreCards = new List <ScoreCard>();

            scoreCards.Add(sc0);
            scoreCards.Add(sc1);
            scoreCards.Add(sc2);

            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 3, Theme = "Score"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 4, Theme = "AltScore"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 5, Theme = "Putt"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 6, Theme = "Fairway"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 7, Theme = "GIR"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 8, Theme = "Pitch"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 9, Theme = "Chip"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 10, Theme = "GSBunker"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 11, Theme = "Penalty"
            });

            // now add scoreCards to round.ScoreCards
            round.ScoreCards = scoreCards;

            TempData["Round"] = round;

            // pass only round

            if (ModelState.IsValid)
            {
                return(RedirectToAction("EnterScoreCard", "Score"));
            }

            return(View());
        }
Пример #2
0
        public ActionResult FieldSelectTee(int?id, string gender, string teeName, DateTime playStartDateTime, int nineHole)
        {
            Course course = db.Courses.Find(id);

            // create top 3 rows for scorecard
            TeeCommonInfo tciPar =
                (from a in course.TCInfos where a.Gender == gender where a.Theme == "Par" select a).FirstOrDefault();

            TeeCommonInfo tciHandicap =
                (from a in course.TCInfos where a.Gender == gender where a.Theme == "Handicap" select a).FirstOrDefault();

            TeeCommonInfo tciDistance =
                (from a in course.TCInfos where a.Gender == gender where a.Theme == "Distance" where a.Name == teeName select a).FirstOrDefault();

            // create a new empty round so that we can have a roundID
            Round round = new Round()
            {
                RecordDate = DateTime.Now, PlayDate = playStartDateTime, PlayStartTime = playStartDateTime, PlayEndTime = playStartDateTime.AddHours(4.5), CourseID = course.GCID, TeeID = tciDistance.TCID, NineHole = nineHole
            };

            round.Course = course;

            //string aaa = User.Identity.GetUserId();

            round.UserGUID = Guid.Parse(User.Identity.GetUserId());
            round.UserName = User.Identity.Name;

            // to get a roundID
            // save partial info to round, later once a user completed entering score, then fully save it
            // todo: do I have to save to get the RID? what if I save both round and scorecard at the end of enterScoreCard and save them at the same time?
            db.Rounds.Add(round);
            db.SaveChanges();

            // ??? here ???
            // do I have to do this?
            course.Rounds.Add(round);

            // create all the score card rows
            ScoreCard sc0 = new ScoreCard()
            {
                CreateDate = DateTime.Today,
                UpdateDate = DateTime.Today,
                FRID       = round.RID,
                FTCID      = tciPar.TCID,
                RowNumber  = 0,
                Theme      = "Par"
            };
            ScoreCard sc1 = new ScoreCard()
            {
                CreateDate = DateTime.Today,
                UpdateDate = DateTime.Today,
                FRID       = round.RID,
                FTCID      = tciHandicap.TCID,
                RowNumber  = 1,
                Theme      = "Handicap"
            };
            ScoreCard sc2 = new ScoreCard()
            {
                CreateDate = DateTime.Today,
                UpdateDate = DateTime.Today,
                FRID       = round.RID,
                FTCID      = tciDistance.TCID,
                RowNumber  = 2,
                Theme      = "Distance"
            };

            CopyPropertiesH(tciPar, sc0);
            CopyPropertiesH(tciHandicap, sc1);
            CopyPropertiesH(tciDistance, sc2);

            sc0.HOut   = tciPar.HOut;
            sc0.HIn    = tciPar.HIn;
            sc0.HTotal = tciPar.HTotal;
            sc1.HOut   = tciHandicap.HOut;
            sc1.HIn    = tciHandicap.HIn;
            sc1.HTotal = tciHandicap.HTotal;
            sc2.HOut   = tciDistance.HOut;
            sc2.HIn    = tciDistance.HIn;
            sc2.HTotal = tciDistance.HTotal;

            List <ScoreCard> scoreCards = new List <ScoreCard>();

            scoreCards.Add(sc0);
            scoreCards.Add(sc1);
            scoreCards.Add(sc2);

            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 3, Theme = "Score"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 4, Theme = "AltScore"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 5, Theme = "Putt"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 6, Theme = "Fairway"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 7, Theme = "GIR"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 8, Theme = "Pitch"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 9, Theme = "Chip"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 10, Theme = "GSBunker"
            });
            scoreCards.Add(new ScoreCard()
            {
                RowNumber = 11, Theme = "Penalty"
            });

            // now add scoreCards to round.ScoreCards
            round.ScoreCards = scoreCards;

            // kpkp: do I have to save round with empty score card here for the later use???
            foreach (ScoreCard score in round.ScoreCards)
            {
                score.FRID = round.RID;
                db.ScoreCards.Add(score);
            }

            db.SaveChanges();

            //TempData["Round"] = round;

            // pass only round
            ViewBag.Title = round.Course.Name + "," + teeName;

            if (ModelState.IsValid)
            {
                return(RedirectToAction("FieldEnterScoreHole", "Field", new { id = round.RID, ppage = 1, cpage = 1,
                                                                              hScore = 0, hAltScore = 0, hPutt = 0, hFairway = 0,
                                                                              hGir = 0, hPitch = 0, hChip = 0, hGsBunker = 0, hPenalty = 0 }));
            }

            return(View());
        }