private bool UpsertEvent(EventAdministrationViewModel viewModel, VenueModel venueModelForConcert, PerformerModel artistFromDb)
        {
            // Add event if it doesn't exist
            const ServerTargetEnum saveToShardDb = ServerTargetEnum.Primary;
            var eventDateTime = new DateTime(viewModel.Year, viewModel.Month, viewModel.Day, 20, 0, 0);

            if (_concertRepository.SaveNewConcert(viewModel.NewEvent, viewModel.Description, eventDateTime, saveToShardDb, venueModelForConcert.VenueId, artistFromDb.PerformerId) == null)
            {
                DisplayMessage(String.Format(" Failed to add new concert event. \'{0}\'", viewModel.NewEvent));
                return(false);
            }

            DisplayMessage(string.Format("Successfully added new event {0}.", viewModel.NewEvent));
            return(true);
        }
Ejemplo n.º 2
0
            public ConcertModel SaveNewConcert(String concertName, String concertDescription, DateTime concertDateTime, ServerTargetEnum saveToDatabase, int concertVenueId, int performerId)
            {
                ConcertModel concertModelToReturn = null;
                var          tempDs = new DataSet();

                #region Insert

                var insertQuery = String.Format(ConstInsertNewConcert, concertName, concertDescription, concertDateTime, ConstConcertduration, concertVenueId, performerId, (int)saveToDatabase);

                using (var insertConnection = WingtipTicketApp.CreateTenantConnectionDatabase1())
                {
                    insertConnection.Open();

                    using (var insertCommand = new SqlCommand(insertQuery, insertConnection))
                    {
                        insertCommand.ExecuteNonQuery();
                    }

                    insertConnection.Close();
                    insertConnection.Dispose();
                }

                #endregion

                #region Get Information

                var getCommandQuery = string.Format("{0} WHERE (concerts.ConcertName='{1}' AND concerts.VenueId={2} AND concerts.PerformerId={3}) {4}", ConstGetAllConcertsQuery, concertName, concertVenueId, performerId, ConstOrderByConcertDate);

                using (var getConnection = WingtipTicketApp.CreateTenantConnectionDatabase1())
                {
                    getConnection.Open();

                    using (var reader = new SqlCommand(getCommandQuery, getConnection).ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            concertModelToReturn = PopulateSingleConcertFromDbReader(reader);
                        }
                    }

                    getConnection.Close();
                    getConnection.Dispose();
                }

                #endregion

                #region Populate Ticket Levels

                var i = 1;
                var seatSectionQuery = string.Format(@"SELECT * FROM [SeatSection] Where VenueId={0}", concertVenueId);

                using (var seatCommand = new SqlCommand(seatSectionQuery, WingtipTicketApp.CreateTenantConnectionDatabase1()))
                {
                    using (var seatDataAdapter = new SqlDataAdapter(seatCommand))
                    {
                        seatDataAdapter.Fill(tempDs);

                        if (tempDs.Tables.Count > 0 && tempDs.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow drSeat in tempDs.Tables[0].Rows)
                            {
                                var ticketLevelInsert = string.Format(@"INSERT INTO [TicketLevels] (Description, SeatSectionId, ConcertId, TicketPrice) Values('Level-{0}', {0}, {1}, '{2}')", drSeat["SeatSectionId"].ToString(), concertModelToReturn.ConcertId, (50 + (5 * i++)).ToString() + ".00");

                                using (var ticketConnection = WingtipTicketApp.CreateTenantConnectionDatabase1())
                                {
                                    ticketConnection.Open();

                                    using (var ticketCommand = new SqlCommand(ticketLevelInsert, ticketConnection))
                                    {
                                        ticketCommand.ExecuteNonQuery();
                                    }

                                    ticketConnection.Close();
                                    ticketConnection.Dispose();
                                }
                            }
                        }
                    }
                }

                #endregion

                LogAction("Added new concert " + concertName + " for venueId " + concertVenueId);

                return(concertModelToReturn);
            }
Ejemplo n.º 3
0
            public ConcertModel SaveNewConcert(String concertName, String concertDescription, DateTime concertDateTime, ServerTargetEnum saveToDatabase, int concertVenueId, int performerId)
            {
                ConcertModel concertModelToReturn = null;
                var tempDs = new DataSet();

                #region Insert

                var insertQuery = String.Format(ConstInsertNewConcert, concertName, concertDescription, concertDateTime, ConstConcertduration, concertVenueId, performerId, (int)saveToDatabase);

                using (var insertConnection = WingtipTicketApp.CreateTenantSqlConnection())
                {
                    insertConnection.Open();

                    using (var insertCommand = new SqlCommand(insertQuery, insertConnection))
                    {
                        insertCommand.ExecuteNonQuery();
                    }

                    insertConnection.Close();
                    insertConnection.Dispose();
                }

                #endregion

                #region Get Information

                var getCommandQuery = string.Format("{0} WHERE (concerts.ConcertName='{1}' AND concerts.VenueId={2} AND concerts.PerformerId={3}) {4}", ConstGetAllConcertsQuery, concertName, concertVenueId, performerId, ConstOrderByConcertDate);

                using (var getConnection = WingtipTicketApp.CreateTenantSqlConnection())
                {
                    getConnection.Open();

                    using (var reader = new SqlCommand(getCommandQuery, getConnection).ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            concertModelToReturn = PopulateSingleConcertFromDbReader(reader);
                        }
                    }

                    getConnection.Close();
                    getConnection.Dispose();
                }

                #endregion

                #region Populate Ticket Levels

                var i = 1;
                var seatSectionQuery = string.Format(@"SELECT * FROM [SeatSection] Where VenueId={0}", concertVenueId);

                using (var seatCommand = new SqlCommand(seatSectionQuery, WingtipTicketApp.CreateTenantSqlConnection()))
                {
                    using (var seatDataAdapter = new SqlDataAdapter(seatCommand))
                    {
                        seatDataAdapter.Fill(tempDs);

                        if (tempDs.Tables.Count > 0 && tempDs.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow drSeat in tempDs.Tables[0].Rows)
                            {
                                var ticketLevelInsert = string.Format(@"INSERT INTO [TicketLevels] (Description, SeatSectionId, ConcertId, TicketPrice) Values('Level-{0}', {0}, {1}, '{2}')", drSeat["SeatSectionId"].ToString(), concertModelToReturn.ConcertId, (50 + (5 * i++)).ToString() + ".00");

                                using (var ticketConnection = WingtipTicketApp.CreateTenantSqlConnection())
                                {
                                    ticketConnection.Open();

                                    using (var ticketCommand = new SqlCommand(ticketLevelInsert, ticketConnection))
                                    {
                                        ticketCommand.ExecuteNonQuery();
                                    }

                                    ticketConnection.Close();
                                    ticketConnection.Dispose();
                                }
                            }
                        }
                    }
                }

                #endregion

                LogAction("Added new concert " + concertName + " for venueId " + concertVenueId);

                return concertModelToReturn;
            }
 public ConcertModel SaveNewConcert(string concertName, string concertDescription, DateTime concertDateTime, ServerTargetEnum saveToDatabase, int concertVenueId, int performerId)
 {
     return(Context.Concerts.SaveNewConcert(concertName, concertDescription, concertDateTime, saveToDatabase, concertVenueId, performerId));
 }
 public ConcertModel SaveNewConcert(string concertName, string concertDescription, DateTime concertDateTime, ServerTargetEnum saveToDatabase, int concertVenueId, int performerId)
 {
     return Context.Concerts.SaveNewConcert(concertName, concertDescription, concertDateTime, saveToDatabase, concertVenueId, performerId);
 }