Exemplo n.º 1
0
 public JsonResult EntityByStringTest()
 {
     var context = new StoreContext();
     var type = Type.GetType("MvcPlayground.Models.Customer");
     var entitySet = context.Set(type);
     var entity = entitySet.Find(2);
     return Json(
         entity,
         JsonRequestBehavior.AllowGet
     );
 }
Exemplo n.º 2
0
        public dynamic Submit(DryRun dryRun = DryRun.Off)
        {
            var context = new StoreContext();
            var type = Type.GetType(boundRecord.entityClass);
            var entitySet = context.Set(type);
            var entity = entitySet.Find(boundRecord.primaryKey);
            context.Entry(entity);
            type.GetProperty(fieldToUpdate).SetValue(entity, newValue);

            if (dryRun == DryRun.Off)
            {
                var saveResult = context.SaveChanges();
                if (saveResult > 0)
                {
                    return boundRecord.primaryKey;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return this;
            }
        }
Exemplo n.º 3
0
 public bool Submit(DryRun dryRun = DryRun.Off)
 {
     var context = new StoreContext();
     var type = Type.GetType(boundRecord.entityClass);
     var entitySet = context.Set(type);
     var entity = entitySet.Find(boundRecord.primaryKey);
     entitySet.Remove(entity);
     var result = context.SaveChanges();
     if (result > 0)
     {
         return true;
     }
     return false;
 }
Exemplo n.º 4
0
 public object GetEntity(string fqn, dynamic primaryKey)
 {
     var context = new StoreContext();
     var type = Type.GetType(fqn);
     var entitySet = context.Set(type);
     var entity = entitySet.Find(primaryKey);
     return entity;
 }