Esempio n. 1
0
        public Leaper AddLeaper(string name, decimal budget)
        {
            using (var db = new SqlConnection(ConnectionString))
            {
                var leaperRepo = new LeaperRepository();

                var insertQuery = @"
                    INSERT INTO [dbo].[Leapers]
                               ([Name]
                               ,[Budget])
                    OUTPUT inserted.*
                         VALUES
                               (@name
                               ,@budget)";

                var parameters = new
                {
                    Name   = name,
                    Budget = budget,
                };

                var newLeaper = db.QueryFirstOrDefault <Leaper>(insertQuery, parameters);

                if (newLeaper != null)
                {
                    return(newLeaper);
                }
            }
            throw new Exception("Leaper was not created");
        }
        public string GetLeapHistory()
        {
            string leapLog       = "";
            int    leapIteration = 1;
            var    eventRepo     = new EventRepository();
            var    leaperRepo    = new LeaperRepository();
            var    hostRepo      = new HostRepository();

            foreach (var leap in _leaps)
            {
                var eventToLog    = eventRepo.GetEventById(leap.EventId);
                var leaperToLog   = leaperRepo.GetLeaperById(leap.LeaperId);
                var hostToLog     = hostRepo.GetHostById(leap.HostId);
                var date          = $"{eventToLog.HistoricalDate.Month}/{eventToLog.HistoricalDate.Day}/{eventToLog.HistoricalDate.Year}";
                var leapOrderInfo = "";

                if (leapIteration == 1)
                {
                    leapOrderInfo = $"{leapIteration} <-- First leap";
                }
                else if (leapIteration == _leaps.Count)
                {
                    leapOrderInfo = $"{leapIteration} <-- Most recent leap";
                }
                else
                {
                    leapOrderInfo = leapIteration.ToString();
                }

                leapLog += $"{leapOrderInfo}\n";
                leapLog += $"Location: {eventToLog.Location}\n";
                leapLog += $"Date: {date}\n";
                leapLog += $"Leaper: {leaperToLog.Name}\n";
                leapLog += $"Host: {hostToLog.Name}\n";
                leapLog += leapIteration == _leaps.Count ? "" : "\n";
                leapIteration++;
            }
            ;
            return(leapLog == "" ? "You haven't made any leaps yet.\n" : $"{leapLog}");
        }