Ejemplo n.º 1
0
 public ActionResult CreateEvent(DateTime date, int maxPeople)
 {
     var db = new HockeySignupsDb(_connectionString);
     Event e = new Event {Date = date, MaxPeople = maxPeople};
     db.AddEvent(e);
     TempData["Message"] = "Event Successfully created, Id: " + e.Id;
     return RedirectToAction("Index", "Hockey");
 }
Ejemplo n.º 2
0
        public void AddEvent(Event e)
        {
            InitiateDbAction(cmd =>
            {
                cmd.CommandText = "INSERT INTO Events (Date, MaxPeople) VALUES (@Date, @MaxPeople); SELECT @@Identity";
                cmd.Parameters.AddWithValue("@Date", e.Date);
                cmd.Parameters.AddWithValue("@MaxPeople", e.MaxPeople);

                e.Id = (int)(decimal)cmd.ExecuteScalar();
            });
        }
Ejemplo n.º 3
0
        public Event GetLatestEvent()
        {
            Event e = null;
            InitiateDbAction(cmd =>
            {
                cmd.CommandText = "SELECT TOP 1 * FROM Events ORDER BY Id DESC";
                var reader = cmd.ExecuteReader();
                reader.Read();
                e = new Event
                {
                    Date = (DateTime)reader["Date"],
                    Id = (int)reader["Id"],
                    MaxPeople = (int)reader["MaxPeople"]
                };
            });

            return e;
        }
Ejemplo n.º 4
0
        public Event GetEventById(int eventId)
        {
            Event e = null;
            InitiateDbAction(cmd =>
            {
                cmd.CommandText = "SELECT * FROM Events WHERE Id = @id";
                cmd.Parameters.AddWithValue("@id", eventId);
                var reader = cmd.ExecuteReader();
                reader.Read();
                e = new Event
                     {
                         Date = (DateTime)reader["Date"],
                         Id = (int)reader["Id"],
                         MaxPeople = (int)reader["MaxPeople"]
                     };
            });

            return e;
        }
Ejemplo n.º 5
0
        public IEnumerable<Event> GetEvents()
        {
            List<Event> events = new List<Event>();
            InitiateDbAction(cmd =>
            {
                cmd.CommandText = "SELECT * FROM Events ORDER BY Date DESC";
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var e = new Event
                    {
                        Date = (DateTime)reader["Date"],
                        Id = (int)reader["Id"],
                        MaxPeople = (int)reader["MaxPeople"]
                    };
                    events.Add(e);
                }
            });

            return events;
        }
Ejemplo n.º 6
0
        public EventStatus GetEventStatus(Event e)
        {
            if (e.Date < DateTime.Today)
            {
                return EventStatus.InThePast;
            }

            int pplAmount = 0;
            InitiateDbAction(cmd =>
            {
                cmd.CommandText = "SELECT COUNT(*) FROM EventSignups WHERE EventId = @eventId";
                cmd.Parameters.AddWithValue("@eventId", e.Id);
                pplAmount = (int) cmd.ExecuteScalar();
            });

            if (pplAmount < e.MaxPeople)
            {
                return EventStatus.Open;
            }

            return EventStatus.Full;
        }