コード例 #1
0
        public void DeleteEvent(int id)
        {
            List <Event> @events = GetAllEvents().ToList();

            foreach (var e in @events)
            {
                if (e.Id == id)
                {
                    @events.Remove(e);
                    break;
                }
            }
            JsonFileWritter.WriteToJson(@events, JsonFileName);
        }
コード例 #2
0
        public void UpdateEvent(Event @evt)
        {
            List <Event> @events = GetAllEvents().ToList();

            if (@evt != null)
            {
                foreach (var e in @events)
                {
                    if (e.Id == @evt.Id)
                    {
                        e.Id          = evt.Id;
                        e.Name        = evt.Name;
                        e.City        = evt.City;
                        e.Description = evt.Description;
                        e.DateTime    = evt.DateTime;
                    }
                }
            }
            JsonFileWritter.WriteToJson(@events, JsonFileName);
        }
コード例 #3
0
        public void AddEvent(Event evt)
        {
            List <Event> @events  = GetAllEvents().ToList();
            List <int>   eventIds = new List <int>();

            foreach (var ev in events)
            {
                eventIds.Add(ev.Id);
            }
            if (eventIds.Count != 0)
            {
                int start = eventIds.Max();
                evt.Id = start + 1;
            }
            else
            {
                evt.Id = 1;
            }
            events.Add(evt);
            JsonFileWritter.WriteToJson(@events, JsonFileName);
        }