/// <summary> /// Convert Venue Entity into Venue Object /// </summary> ///<param name="model">VenueViewModel</param> ///<param name="VenueEntity">DataAccess.Venue</param> ///<returns>VenueViewModel</returns> public static VenueViewModel ToViewModel( this DataAccess.Venue entity, VenueViewModel model) { model.Id = entity.Id; model.Name = entity.Name; model.Latitude = entity.Latitude; model.Longitude = entity.Longitude; model.IsActive = entity.IsActive; return(model); }
/// <summary> /// Convert Venue Object into Venue Entity /// </summary> ///<param name="model">Venue</param> ///<param name="VenueEntity">DataAccess.Venue</param> ///<returns>DataAccess.Venue</returns> public static DataAccess.Venue ToEntity(this VenueViewModel model, DataAccess.Venue entity) { if (entity.Id == 0) { entity.CreatedUserId = model.SessionUserId; } else { entity.UpdatedUserId = model.SessionUserId; entity.UpdatedTimestamp = DateTime.Now; } entity.Name = model.Name; entity.Longitude = model.Longitude; entity.Latitude = model.Latitude; entity.IsActive = model.IsActive; return(entity); }
/// <summary> /// Fetches the event bookings list. /// </summary> /// <returns>List of EventBookings;.</returns> public static List <EventBookings> FetchEventBookingsList() { // create a list to hold the returned data var eventBookingsList = new List <EventBookings>(); // get a connection to the database var conn = DBConnection.GetDBConnection(); // create a query to send through the connection string query = "sp_EventBookingsGetAllDetails"; // create a command object - SP var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; // try-catch try { // open connection conn.Open(); // execute the command and return a data reader SqlDataReader reader = cmd.ExecuteReader(); // before trying to read the reader, be sure it has data if (reader.HasRows) { // now we just need a loop to process the reader while (reader.Read()) { EventType eventType = new EventType() { EventTypeID = reader.GetInt32(4), EventTypeName = reader.GetString(5), EventTypeDescription = reader.GetString(6) }; Venue venue = new Venue() { VenueID = reader.GetInt32(7), BuildingName = reader.GetString(8) }; Customer customer = new Customer() { CustomerID = reader.GetInt32(9), FirstName = reader.GetString(10), LastName = reader.GetString(11) }; Caterers caterer = new Caterers() { CatererID = reader.GetInt32(12), CatererName = reader.GetString(13) }; UserProfile user = new UserProfile() { UserID = reader.GetInt32(14), UserName = reader.GetString(15), }; EventBookings eventBooking = new EventBookings() { BookingID = (Int32)reader["BookingID"], //reader.GetInt32(0), StartTime = (TimeSpan)reader["StartTime"], //reader.GetTimeSpan(1) EndTime = (TimeSpan)reader["EndTime"], //reader.GetTimeSpan(2), EventDate = (DateTime)reader["EventDate"], //reader.GetDateTime(3), EventType = eventType, Venue = venue, Customer = customer, Caterer = caterer, UserProfile = user, }; //BookingID,StartTime,EndTime,EventDate, //EventTypeID,EventType,EventTypeDescription, //VenueID,BuildingName, //CustomerID,FirstName,LastName, //CatererID,CatererName, //UserID,UserName eventBookingsList.Add(eventBooking); } } } catch (Exception) { // rethrow all Exceptions, let the logic layer sort them out throw; } finally { conn.Close(); } // this list may be empty, if so, the logic layer will need to deal with it return(eventBookingsList); }