public Objects.activities.Activity AddActivity(Objects.activities.Activity item) { item.id = 0; //parent exist ? if (item == null) { throw new ArgumentException("Activity is null"); } if (item.category == null) { throw new ArgumentException("Category is null"); } var _parent = _ctx.activities_categories.FirstOrDefault(x => x.id == item.category.id); if (_parent == null) { throw new ArgumentException("Category not exist"); } var _entity = Mapper.Map <Entities.activities.Activity>(item); _entity.category = _parent; _entity.category_id = _parent.id; _entity = _ctx.activities.Add(_entity); _ctx.SaveChanges(); return(Mapper.Map <Objects.activities.Activity>(_entity)); }
public List <Objects.activities.Section> GetsSections(Objects.activities.Activity activity = null) { var query = _ctx.activities_sections.Where(x => true); if (activity != null) { query = query.Where(x => x.activity_id == activity.id); } query = query.OrderBy(x => x.name); return(Mapper.Map <List <Objects.activities.Section> >(query.ToList())); }
public void DeleteActivity(Objects.activities.Activity item) { var _entity = _ctx.activities.FirstOrDefault(x => x.id == item.id); if (_entity == null) { throw new ArgumentException("Activity not exist"); } _ctx.activities.Remove(_entity); _ctx.SaveChanges(); }
public Objects.activities.Activity UpdateActivity(Objects.activities.Activity item) { if (item == null) { throw new ArgumentException("Activity is null"); } var _entity = _ctx.activities.FirstOrDefault(x => x.id == item.id); if (_entity == null) { throw new ArgumentException("Activity not exist"); } //parent exist ? if (item.category == null) { throw new ArgumentException("Category is null"); } var _parent = _ctx.activities_categories.FirstOrDefault(x => x.id == item.category.id); if (_parent == null) { throw new ArgumentException("Category not exist"); } //_entity.category = _parent; //_entity.category_id = _parent.id; var __entity = Mapper.Map(item, _entity); __entity.category = _parent; __entity.category_id = _parent.id; _ctx.Entry(__entity).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); return(Mapper.Map <Objects.activities.Activity>(__entity)); }