public int InsertModel(ModelBase model) { if (model == null) { return(0); } lock (s_ServiceLocker) { ModelMapping mp = new ModelMapping(model.GetType()); Exception ex = null; int rid = ModelFactoryCollection.InsertModelReturnRid(model, mp, out ex); if (ex == null) { ModelAccessManager.CacheManager.Save(model); ExcuteAction action = new ExcuteAction(); action.ExcuteObject = model; model.Rid = rid; action.ExcuteType = ExcuteType.Insert; SendAll(action); } else { m_callback.ErrorNotify(this.ToString(), ex.Message, ExcuteType.Insert); } return(rid); } }
public bool Excute(SuperControl.ServiceModel.ExcuteAction[] actions) { bool issuccessed = false; List <ExcuteAction> retList = new List <ExcuteAction>(); lock (s_ServiceLocker) { foreach (ExcuteAction action in actions) { ModelBase model = action.ExcuteObject as ModelBase; if (model == null) { continue; } Exception ex = null; string logstring = string.Empty; int maxrid = 0; switch (action.ExcuteType) { case ExcuteType.Delete: ModelMapping mp = new ModelMapping(model.GetType()); ModelFactoryCollection.DeleteModel(model, mp, out ex); logstring = "delete"; if (ex == null) { ModelAccessManager.CacheManager.Remove(model); retList.Add(action); } break; case ExcuteType.Append: case ExcuteType.Insert: mp = new ModelMapping(model.GetType()); //model.Rid = ModelFactoryCollection.GetMaxRid(mp); ModelFactoryCollection.InsertModel(model, mp, out ex); logstring = "insert"; maxrid = ModelFactoryCollection.GetMaxRid(mp); if (ex == null) { ModelAccessManager.CacheManager.Save(model); retList.Add(action); } break; case ExcuteType.Update: mp = new ModelMapping(model.GetType()); logstring = "update"; ModelFactoryCollection.UpdateModel(model, mp, out ex); if (ex == null) { ModelAccessManager.CacheManager.Save(model); retList.Add(action); } break; default: break; } try { if (ex != null) { issuccessed = false; m_callback.ErrorNotify("Registration", ex.Message, action.ExcuteType); } else { issuccessed = true; } } catch (Exception e) { m_callback = null; Console.WriteLine(e.Message); } } if (retList.Count > 0) { SendAll(retList.ToArray()); } } return(issuccessed); }