public void DeleteOrderAuto(Objects.orders.OrderAuto item) { var _entity = _ctx.orders_auto.FirstOrDefault(x => x.id == item.id); if (_entity == null) { throw new ArgumentException("Order not exist"); } _ctx.orders_auto.Remove(_entity); _ctx.SaveChanges(); }
public Objects.orders.OrderAuto UpdateOrderAuto(Objects.orders.OrderAuto item) { var _entity = _ctx.orders_auto.FirstOrDefault(x => x.id == item.id); if (_entity == null) { throw new ArgumentException("Order not exist"); } // recherche saison if (item.season == null) { 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 != 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 != null) { _activity = _ctx.activities.FirstOrDefault(x => x.id == item.restriction_activity.id); if (_activity == null) { throw new ArgumentException("Activity not exist"); } } //recherche catégorie [facultatif] Entities.activities.Category _category = null; if (item.restriction_category != 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.restriction_section = _section; _entity.restriction_section_id = (_section != null) ? (int?)_section.id : null; __entity.restriction_activity = _activity; _entity.restriction_activity_id = (_activity != null) ? (int?)_activity.id : null; __entity.restriction_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.OrderAuto>(__entity)); }