internal static VisualEditorPlugin SavePluginProperties(VisualEditorPlugin plugin) { var entities = QPContext.EFContext; DateTime timeStamp; using (var scope = new QPConnectionScope()) { timeStamp = Common.GetSqlDate(scope.DbConnection); } var dal = MapperFacade.VisualEditorPluginMapper.GetDalObject(plugin); dal.LastModifiedBy = QPContext.CurrentUserId; dal.Modified = timeStamp; dal.Created = timeStamp; entities.VePluginSet.AddObject(dal); DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.VisualEditorPlugin, plugin); if (plugin.ForceId != 0) { dal.Id = plugin.ForceId; } entities.SaveChanges(); DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.VisualEditorPlugin); var forceIds = plugin.ForceCommandIds == null ? null : new Queue <int>(plugin.ForceCommandIds); foreach (var command in plugin.VeCommands) { var dalCommand = MapperFacade.VisualEditorCommandMapper.GetDalObject(command); dalCommand.PluginId = dal.Id; if (forceIds != null) { dalCommand.Id = forceIds.Dequeue(); } dalCommand.LastModifiedBy = QPContext.CurrentUserId; dalCommand.Modified = timeStamp; dalCommand.Created = timeStamp; entities.VeCommandSet.AddObject(dalCommand); } DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.VisualEditorCommand); entities.SaveChanges(); DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.VisualEditorCommand); return(MapperFacade.VisualEditorPluginMapper.GetBizObject(dal)); }
internal static VisualEditorPlugin UpdatePluginProperties(VisualEditorPlugin plugin) { var entities = QPContext.EFContext; DateTime timeStamp; using (var scope = new QPConnectionScope()) { timeStamp = Common.GetSqlDate(scope.DbConnection); } var dal = MapperFacade.VisualEditorPluginMapper.GetDalObject(plugin); dal.LastModifiedBy = QPContext.CurrentUserId; dal.Modified = timeStamp; entities.Entry(dal).State = EntityState.Modified; UpdateCommands(plugin, entities, timeStamp); DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.VisualEditorPlugin, plugin); entities.SaveChanges(); DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.VisualEditorPlugin); return(GetPluginPropertiesById(plugin.Id)); }
private static void UpdateCommands(VisualEditorPlugin plugin, QP8Entities entities, DateTime timeStamp) { // delete var newIds = new HashSet <decimal>(plugin.VeCommands.Select(c => Converter.ToDecimal(c.Id))); var commandsToDelete = entities.VeCommandSet.Where(n => n.PluginId == (decimal)plugin.Id && !newIds.Contains(n.Id)); foreach (var c in commandsToDelete) { entities.VeCommandSet.DeleteObject(c); } // save and update var forceIds = plugin.ForceCommandIds == null ? null : new Queue <int>(plugin.ForceCommandIds); foreach (var command in plugin.VeCommands) { var dalCommand = MapperFacade.VisualEditorCommandMapper.GetDalObject(command); dalCommand.Modified = timeStamp; dalCommand.LastModifiedBy = QPContext.CurrentUserId; if (dalCommand.Id == 0) { dalCommand.Created = timeStamp; if (forceIds != null) { dalCommand.Id = forceIds.Dequeue(); } entities.VeCommandSet.AddObject(dalCommand); } else { entities.VeCommandSet.Attach(dalCommand); entities.ObjectStateManager.ChangeObjectState(dalCommand, EntityState.Modified); } } }