예제 #1
0
파일: CrudBase.cs 프로젝트: ldcdev/WebApi
        public static void EnsureEntity <T, TKey>(this CrudBase <T, TKey> crud, TKey id, Action <T> update)
            where T : class
        {
            var entity = crud.Find(id);

            if (entity == null)
            {
                entity = Activator.CreateInstance <T>();
                crud.SetEntityId(entity, id);
                crud.Add(entity);
            }
            update(entity);
        }
예제 #2
0
        public static T EnsureEntity <T, TKey>(this CrudBase <T, TKey> crud, string id, Action <T> update)
            where T : DbObject
        {
            var guid   = new Guid(id);
            var entity = crud.All().FirstOrDefault(e => e.Guid == guid);

            if (entity == null)
            {
                entity      = Activator.CreateInstance <T>();
                entity.Guid = guid;
                crud.Add(entity);
            }
            update(entity);
            return(entity);
        }
예제 #3
0
 protected ODataCrudController(IEdmModel model, CrudBase <T, TKey> crud)
 {
     Model = model;
     Crud  = crud;
 }