Esempio n. 1
0
        public void Update(int eventId, IEnumerable <Team> teams)
        {
            var teamAssociations = _appDbContext.EventAssociations.Where(x => x.EventId == eventId);

            foreach (var team in teams)
            {
                var association = teamAssociations.FirstOrDefault(x => x.TeamId == team.Id);

                if (association != null && !team.Selected)
                {
                    _appDbContext.EventAssociations.Remove(association);
                }

                else if (association == null && team.Selected)
                {
                    var date = DateTime.Now;
                    association = new EventAssociation()
                    {
                        Created  = date,
                        Modified = date,
                        TeamId   = team.Id,
                        EventId  = eventId
                    };
                    _appDbContext.EventAssociations.Add(association);
                }
            }
            CommitChanges();
        }
Esempio n. 2
0
        public void Remove(EventAssociation entity, bool commit = true)
        {
            _appDbContext.EventAssociations.Remove(entity);

            if (commit)
            {
                CommitChanges();
            }
        }