partial void DeleteEvent(Event instance);
 partial void UpdateEvent(Event instance);
 partial void InsertEvent(Event instance);
        public int GetLastPastEvent()
        {
            EventGame result = new EventGame();

            using (MasterDBDataContext db = new MasterDBDataContext())
            {
                DateTime date = DateTime.Now;

                var eventGames = db.Event.Where(ev => ev.EndDate < date).OrderByDescending(ev => ev.EndDate);

                if (eventGames != null)
                {
                    Event[] arrayEventGames = new Event[eventGames.ToArray().Count()];
                    arrayEventGames = eventGames.ToArray();

                    return arrayEventGames[0].idEvent;
                }
            }
            return -1;
        }
        public int[] GetAllPastEvent()
        {
            using (MasterDBDataContext db = new MasterDBDataContext())
            {
                DateTime date = DateTime.Now;

                var eventGames = db.Event.Where(ev => ev.EndDate < date).OrderByDescending(ev => ev.EndDate);

                if (eventGames != null)
                {
                    int numberOfPastEvents = eventGames.ToArray().Count();
                    int[] result = new int[numberOfPastEvents];

                    Event[] arrayEventGames = new Event[numberOfPastEvents];
                    arrayEventGames = eventGames.ToArray();

                    for(int i = 0; i < numberOfPastEvents; i++)
                    {
                        result[i] = arrayEventGames[i].idEvent;
                    }
                    return result;
                }
            }
            return null;
        }
        public int CreateOrUpdateEvent(int id, string name, DateTime startDate, DateTime endDate, byte[] image, string description)
        {
            using (MasterDBDataContext db = new MasterDBDataContext())
            {
                Event eventGame = null;
                if (id == 0)
                {
                    eventGame = new Event()
                    {
                        Name = name,
                        StartDate = startDate,
                        EndDate = endDate,
                        Image = "",
                        Description = description
                    };

                    db.Event.InsertOnSubmit(eventGame);
                }
                else
                {
                    eventGame = db.Event.SingleOrDefault(e => e.idEvent == id);
                    if (name != "")
                    {
                        eventGame.Name = name;
                    }
                    eventGame.StartDate = startDate;
                    eventGame.EndDate = endDate;
                    if (description != "")
                    {
                        eventGame.Description = description;
                    }
                }
                try
                {
                    if (image != null)
                    {
                        if (id == 0)
                            db.SubmitChanges();

                        string path = IMAGE_PATH + "events\\" + eventGame.idEvent + "-" + eventGame.Name;
                        if (!Directory.Exists(path))
                            Directory.CreateDirectory(IMAGE_PATH + "events\\" + eventGame.idEvent + "-" + eventGame.Name);

                        using (FileStream fs = new FileStream(path + "\\" + "cover", FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            fs.Write(image, 0, image.Length);
                            eventGame.Image = path + "\\" + "cover";
                        }
                    }

                    db.SubmitChanges();

                    return eventGame.idEvent;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR CreateEvent " + ex.Message);
                    return -1;
                }
            }
        }