Esempio n. 1
0
        public void Test_AddPerformance_ShouldAddThePerformance()
        {
            theatreDatabase.AddTheatre("Theatre Sofia");
            theatreDatabase.AddPerformance(
                "Theatre Sofia",
                "Bella Donna",
                new DateTime(2015, 01, 20, 20, 30, 00),
                new TimeSpan(0, 1, 0, 0),
                12);
            string expectedOutput = "(Bella Donna, Theatre Sofia, 20.01.2015 20:30)";
            string actualOutput   = string.Join(", ", theatreDatabase.ListAllPerformances());

            Assert.AreEqual(expectedOutput, actualOutput);
        }
        public static string ExecutePrintAllPerformancesCommand(IPerformanceDatabase database)
        {
            var performances = database.ListAllPerformances().ToList();
            var performanceOutput = new StringBuilder();
            if (!performances.Any())
            {
                return "No performances";
            }

            for (int i = 0; i < performances.Count; i++)
            {
                //PERFORMANCE
                if (i > 0)
                {
                    performanceOutput.Append(", ");
                }

                string startDateTimeAsString = performances[i].StartDateTime.ToString("dd.MM.yyyy HH:mm");
                performanceOutput.AppendFormat(
                    "({0}, {1}, {2})",
                    performances[i].PerformanceTitle,
                    performances[i].TheatreName,
                    startDateTimeAsString);
            }

            return performanceOutput.ToString();
        }
Esempio n. 3
0
        private static string ExecutePrintAllPerformancesCommand()
        {
            var performances    = performanceDatabase.ListAllPerformances().ToList();
            var allPerformances = new StringBuilder();

            if (performances.Any())
            {
                for (int i = 0; i < performances.Count; i++)
                {
                    if (i > 0)
                    {
                        allPerformances.Append(", ");
                    }

                    var date = performances[i].StartDateTime.ToString(Constants.DateTimeFormat);
                    allPerformances.AppendFormat(
                        "({1}, {0}, {2})",
                        performances[i].TheatreName,
                        performances[i].PerformanceTitle,
                        date);
                }

                return(allPerformances.ToString());
            }

            return(Constants.NoPerformancesMsg);
        }
Esempio n. 4
0
        public static string ExecutePrintAllPerformancesCommand(IPerformanceDatabase database)
        {
            var performances = database.ListAllPerformances().ToList();

            if (!performances.Any())
            {
                return("No performances");
            }

            var sb = new StringBuilder();

            //sb.AppendFormat("({0}, {1}, {2}), ",
            //        performances[0].PerformanceTitle,
            //        performances[0].TheatreName,
            //        performances[0].StartDateTime.ToString("dd.MM.yyyy HH:mm"));

            for (int i = 0; i < performances.Count; i++)
            {
                sb.AppendFormat("({0}, {1}, {2}), ",
                                performances[i].PerformanceTitle,
                                performances[i].TheatreName,
                                performances[i].StartDateTime.ToString("dd.MM.yyyy HH:mm"));
            }

            return(sb.ToString().Trim(' ', ','));
        }
Esempio n. 5
0
        private string ExecutePrintAllPerformancesCommand()
        {
            var    performances = database.ListAllPerformances().ToList();
            string result       = string.Empty;

            if (performances.Any())
            {
                var allPerformancesAsString = new StringBuilder();
                for (int i = 0; i < performances.Count; i++)
                {
                    if (i > 0)
                    {
                        allPerformancesAsString.Append(", ");
                    }

                    ITheatre teathre     = performances[i].Theatre;
                    string   performance = performances[i].PerformanceName;
                    string   date        = performances[i].Date.ToString("dd.MM.yyyy HH:mm");
                    allPerformancesAsString.AppendFormat("({0}, {1}, {2})", performance, teathre, date);
                }
                result = allPerformancesAsString.ToString();
            }
            else
            {
                result = "No performances";
            }

            return(result);
        }
Esempio n. 6
0
        public static string ExecutePrintAllPerformancesCommand(IPerformanceDatabase database)
        {
            var performances = database.ListAllPerformances().ToList();
            if (!performances.Any())
            {
                return "No performances";
            }

            var sb = new StringBuilder();

            //sb.AppendFormat("({0}, {1}, {2}), ",
            //        performances[0].PerformanceTitle,
            //        performances[0].TheatreName,
            //        performances[0].StartDateTime.ToString("dd.MM.yyyy HH:mm"));

            for (int i = 0; i < performances.Count; i++)
            {
                sb.AppendFormat("({0}, {1}, {2}), ",
                    performances[i].PerformanceTitle,
                    performances[i].TheatreName,
                    performances[i].StartDateTime.ToString("dd.MM.yyyy HH:mm"));
            }

            return sb.ToString().Trim(' ', ',');
        }
Esempio n. 7
0
        public static string ExecutePrintAllPerformancesCommand(IPerformanceDatabase dataBase)
        {
            var performances = dataBase.ListAllPerformances().ToList();
            var result = string.Empty;
            if (performances.Any())
            {
                for (var i = 0; i < performances.Count; i++)
                {
                    var sb = new StringBuilder();
                    sb.Append(result);
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }
                    var result1 = performances[i].Date.ToString("dd.MM.yyyy HH:mm");
                    sb.AppendFormat(
                        "({0}, {1}, {2})", performances
                            [i].PefrofmanceName, performances[i].Theatre, result1);
                    result = sb + "";
                }
                return result;
            }

            return "No performances";
        }
        public static string ExecutePrintAllPerformancesCommand()
        {
            var performancesCount = PerformanceDatabase.ListAllPerformances().Count();

            if (performancesCount > 0)
            {
                var performances = PerformanceDatabase
                                   .ListAllPerformances()
                                   .OrderBy(p => p.Theatre)
                                   .ThenBy(p => p.Date)
                                   .Select(p => string.Format(
                                               "({0}, {1}, {2})", p.Title, p.Theatre, p.Date.ToString(Constants.DateTimeFormat)))
                                   .ToList();

                return(String.Join(", ", performances));
            }

            return(Constants.NoPerformancesMessage);
        }
        private static string ExecutePrintAllPerformancesCommand()
        {
            var performances = performanceDb.ListAllPerformances()
                               .Select(p => string.Format(
                                           "({0}, {1}, {2})", p.Title, p.Theatre, FormatDateTime(p.StartDateTime)))
                               .ToList();

            if (performances.Any())
            {
                return(string.Join(", ", performances));
            }

            return(Constants.NoPerformancesMsg);
        }
Esempio n. 10
0
        public static void ExecutePrintAllPerformancesCommand()
        {
            var performances = theatresDatabase.ListAllPerformances().ToList();

            if (performances.Any())
            {
                string performancesResult = FormatAllPerformancesForPrinting(performances);
                PrintOutput(performancesResult);
            }
            else
            {
                Console.WriteLine(Constants.NoPerformancesMessage);
            }
        }
        private static string ExecutePrintAllPerformancesCommand()
        {
            var performances = performanceDB
                               .ListAllPerformances()
                               .Select(p => string.Format("({0}, {1}, {2})",
                                                          p.PerformanceTitle,
                                                          p.TheaterName,
                                                          p.PerformanceDateStart.ToString("dd.MM.yyyy HH:mm")))
                               .ToList();

            if (performances.Any())
            {
                return(string.Join(", ", performances));
            }

            return("No performances");
        }
Esempio n. 12
0
        private static string ExecutePrintAllPerformancesCommand()
        {
            var performances = Universal.ListAllPerformances().ToList();

            if (!performances.Any())
            {
                return("No performances");
            }

            var allPerformancesInfo = performances.Select(p => string.Format(
                                                              "({0}, {1}, {2})",
                                                              p.Title,
                                                              p.Theatre,
                                                              p.StartDateTime.ToString("dd.MM.yyyy HH:mm")));

            return(string.Join(", ", allPerformancesInfo));
        }
Esempio n. 13
0
        private static string ExecutePrintAllPerformancesCommand()
        {
            var performances = PerformanceDatabase.ListAllPerformances().ToList();
            var result       = new StringBuilder();

            if (performances.Any())
            {
                for (int i = 0; i < performances.Count; i++)
                {
                    if (i > 0)
                    {
                        result.Append(", ");
                    }

                    string startTime = performances[i].StartDateTime.ToString("dd.MM.yyyy HH:mm");
                    result.AppendFormat("({0}, {1}, {2})", performances[i].Name, performances[i].TheatreName, startTime);
                }

                return(result.ToString());
            }

            return("No performances");
        }
Esempio n. 14
0
        protected static void Main()
        {
            while (true)
            {
                var input = Console.ReadLine();

                if (input == null)
                {
                    return;
                }

                if (input != string.Empty)
                {
                    var    tokens     = input.Split(new[] { '(', ',', ')' }, StringSplitOptions.RemoveEmptyEntries);
                    var    command    = tokens[0];
                    var    parameters = tokens.Skip(1).Select(p => p.Trim()).ToArray();
                    string message;

                    try
                    {
                        switch (command)
                        {
                        case "AddTheatre":
                            var theatreName = parameters[0];
                            Database.AddTheatre(theatreName);
                            message = "Theatre added";
                            break;

                        case "PrintAllTheatres":
                            var theatres = Database.ListTheatres().ToList();
                            message = string.Join(", ", theatres);
                            break;

                        case "AddPerformance":
                            theatreName = parameters[0];
                            var performanceTitle = parameters[1];
                            var startDateTime    = DateTime.ParseExact(
                                parameters[2],
                                "dd.MM.yyyy HH:mm",
                                CultureInfo.InvariantCulture);
                            var duration = TimeSpan.Parse(parameters[3]);
                            var price    = decimal.Parse(parameters[4], NumberStyles.Float);
                            Database.AddPerformance(theatreName, performanceTitle, startDateTime, duration, price);
                            message = "Performance added";
                            break;

                        case "PrintAllPerformances":
                            var performances = Database.ListAllPerformances().ToList();
                            message = string.Join(", ", performances);
                            break;

                        case "PrintPerformances":
                            theatreName = parameters[0];
                            var performancesPerTheatre = Database.ListPerformances(theatreName).ToList();
                            message = string.Join(", ", performancesPerTheatre);
                            break;

                        default:
                            message = "Invalid command!";
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        message = "Error: " + ex.Message;
                    }

                    Console.WriteLine(message);
                }
            }
        }