Exemplo n.º 1
0
        public void DeleteSession(Objects.activities.Session item)
        {
            var _entity = _ctx.activities_sessions.FirstOrDefault(x => x.id == item.id);

            if (_entity == null)
            {
                throw new ArgumentException("Session not exist");
            }
            _ctx.activities_sessions.Remove(_entity);
            _ctx.SaveChanges();
        }
Exemplo n.º 2
0
        public Objects.activities.Session UpdateSession(Objects.activities.Session item)
        {
            if (item == null)
            {
                throw new ArgumentException("Session is null");
            }

            var _entity = _ctx.activities_sessions.FirstOrDefault(x => x.id == item.id);

            if (_entity == null)
            {
                throw new ArgumentException("Session not exist");
            }

            //place exist ?
            if (item.place == null)
            {
                throw new ArgumentException("Place is null");
            }
            var _place = _ctx.activities_places.FirstOrDefault(x => x.id == item.place.id);

            if (_place == null)
            {
                throw new ArgumentException("Place not exist");
            }

            //section exist ?
            if (item.section == null)
            {
                throw new ArgumentException("Section is null");
            }
            var _section = _ctx.activities_sections.FirstOrDefault(x => x.id == item.section.id);

            if (_section == null)
            {
                throw new ArgumentException("Section not exist");
            }



            var __entity = Mapper.Map(item, _entity);

            __entity.place      = _place;
            __entity.place_id   = _place.id;
            __entity.section    = _section;
            __entity.section_id = _section.id;

            _ctx.Entry(__entity).State = System.Data.Entity.EntityState.Modified;
            _ctx.SaveChanges();

            return(Mapper.Map <Objects.activities.Session>(__entity));
        }
Exemplo n.º 3
0
        public Objects.activities.Session AddSession(Objects.activities.Session item)
        {
            if (item == null)
            {
                throw new ArgumentException("Session is null");
            }

            item.id = 0;

            //place exist ?
            if (item.place == null)
            {
                throw new ArgumentException("Place is null");
            }
            var _place = _ctx.activities_places.FirstOrDefault(x => x.id == item.place.id);

            if (_place == null)
            {
                throw new ArgumentException("Place not exist");
            }

            //section exist ?
            if (item.section == null)
            {
                throw new ArgumentException("Section is null");
            }
            var _section = _ctx.activities_sections.FirstOrDefault(x => x.id == item.section.id);

            if (_section == null)
            {
                throw new ArgumentException("Section not exist");
            }

            var _entity = Mapper.Map <Entities.activities.Session>(item);

            _entity.place      = _place;
            _entity.place_id   = _place.id;
            _entity.section    = _section;
            _entity.section_id = _section.id;
            _entity            = _ctx.activities_sessions.Add(_entity);
            _ctx.SaveChanges();
            return(Mapper.Map <Objects.activities.Session>(_entity));
        }