Example #1
0
 public JsonResult AddCustomer()
 {
     var context = new StoreContext();
     var result = context.CustomerSet.Add(new Customer());
     context.SaveChanges();
     return Json(CustomerTable());
 }
Example #2
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
     );
 }
Example #3
0
 public JsonResult CustomerTable()
 {
     var customers = new StoreContext().CustomerSet;
     var table = new ComponentTable
     {
         headers = new List<string>{ "ID", "First Name", "Last Name" },
         rows = customers.AsEnumerable().Select(c =>
         {
             return new ComponentRow
             {
                 components = new List<component>
                 {
                     new component(new TestCell { text = c.ID.ToString() }),
                     new component(new TextBox { boundRecord = new BoundRecordInfo(c), value = c.FirstName, name = "FirstName" }),
                     new component(new TextBox { boundRecord = new BoundRecordInfo(c), value = c.LastName, name = "LastName" })
                 },
                 record = new BoundRecordInfo(c)
             };
         }).ToList()
     };
     return Json(table, JsonRequestBehavior.AllowGet);
 }
Example #4
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;
            }
        }
Example #5
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;
 }
Example #6
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;
 }
Example #7
0
 public JsonResult BoundRecordTest()
 {
     var customer = new StoreContext().CustomerSet.ToList().Last();
     var boundRecord = new BoundRecordInfo(customer);
     return Json(boundRecord, JsonRequestBehavior.AllowGet);
 }
Example #8
0
 public JsonResult RecordUpdateTest()
 {
     var customer = new StoreContext().CustomerSet.First();
     var request = new RecordUpdateRequest
     {
         boundRecord = new BoundRecordInfo(customer),
         fieldToUpdate = "FirstName",
         newValue = "roflrolf"
     };
     var response = request.Submit(DryRun.On);
     return Json(response, JsonRequestBehavior.AllowGet);
 }
Example #9
0
 public JsonResult ListAllCustomers()
 {
     var customers = new StoreContext().CustomerSet;
     return Json(customers, JsonRequestBehavior.AllowGet);
 }