Пример #1
0
        public Objects.activities.Category UpdateCategory(Objects.activities.Category item)
        {
            var _entity = _ctx.activities_categories.FirstOrDefault(x => x.id == item.id);

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

            //parent exist ?
            if (item.season == null)
            {
                throw new ArgumentException("Season is null");
            }
            var _parent = _ctx.seasons.FirstOrDefault(x => x.id == item.season.id);

            if (_parent == null)
            {
                throw new ArgumentException("Season not exist");
            }

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

            __entity.season            = _parent;
            __entity.season_id         = _parent.id;
            _ctx.Entry(__entity).State = System.Data.Entity.EntityState.Modified;
            _ctx.SaveChanges();
            return(Mapper.Map <Objects.activities.Category>(__entity));
        }
Пример #2
0
        public Objects.members.Member UpdateMember(Objects.members.Member item)
        {
            var _entity = _ctx.members.FirstOrDefault(x => x.id == item.id);

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

            //request all attributes
            _entity.metas.ToList();

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

            _ctx.Entry(__entity).State = System.Data.Entity.EntityState.Modified;
            _ctx.SaveChanges();
            return(Mapper.Map <Objects.members.Member>(__entity));
        }
Пример #3
0
        public Objects.Season Update(Objects.Season item)
        {
            var _entity = _ctx.seasons.FirstOrDefault(x => x.id == item.id);

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

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

            _ctx.Entry(__entity).State = System.Data.Entity.EntityState.Modified;
            _ctx.SaveChanges();
            return(Mapper.Map <Objects.Season>(__entity));
        }
Пример #4
0
        public Objects.orders.Order UpdateOrder(Objects.orders.Order item)
        {
            var _entity = _ctx.orders.FirstOrDefault(x => x.id == item.id);

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

            //recherche saison
            if (item.season_id == 0)
            {
                throw new ArgumentNullException("Season");
            }
            var _season = _ctx.seasons.FirstOrDefault(x => x.id == item.season_id);

            if (_season == null)
            {
                throw new ArgumentException("Season not exist");
            }

            //recherche section [facultatif]
            Entities.activities.Section _section = null;
            if (item.restriction_section_id != null)
            {
                _section = _ctx.activities_sections.FirstOrDefault(x => x.id == item.restriction_section_id);
                if (_section == null)
                {
                    throw new ArgumentException("Section not exist");
                }
            }

            //recherche section [facultatif]
            Entities.activities.Activity _activity = null;
            if (item.restriction_activity_id != null)
            {
                _activity = _ctx.activities.FirstOrDefault(x => x.id == item.restriction_activity_id);
                if (_activity == null)
                {
                    throw new ArgumentException("Activity not exist");
                }
            }

            //recherche section [facultatif]
            Entities.activities.Category _category = null;
            if (item.restriction_category_id != null)
            {
                _category = _ctx.activities_categories.FirstOrDefault(x => x.id == item.restriction_category_id);
                if (_category == null)
                {
                    throw new ArgumentException("Category not exist");
                }
            }

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

            __entity.season   = _season; _entity.season_id = _season.id;
            __entity.section  = _section; _entity.restriction_section_id = (_section != null) ? (int?)_section.id : null;
            __entity.activity = _activity; _entity.restriction_activity_id = (_activity != null) ? (int?)_activity.id : null;
            __entity.category = _category; _entity.restriction_category_id = (_category != null) ? (int?)_category.id : null;

            //bdd
            _ctx.Entry(__entity).State = System.Data.Entity.EntityState.Modified;
            _ctx.SaveChanges();
            return(Mapper.Map <Objects.orders.Order>(__entity));
        }