public static bool Save <T>(IEntity entity, bool bypassConflicts) where T : IEntity, new() { bool ret = true; try { IEntity copy = new T(); copy.ConnectionString = entity.ConnectionString; entity.__Elements.Where(ebd => ebd.UseForMatching).ToList().ForEach(ebd => copy.__Elements.Find(c => c.Name.Equals(ebd.Name)).Data = ebd.Data); //copy.Elements[0].Data = entity.Elements[0].Data; CRUDActions.Retrieve <T>(copy); if (copy.Notifications.Count == 0) { if (entity.__Memento.Count == 0) { long fieldsToSave = entity.Compare(copy); CRUDActions.Update <T>(entity, fieldsToSave); } else { long fieldsToSave = entity.Compare(); if (fieldsToSave == 0) { return(false); } Utility.SetWarnings(entity, copy); if (!bypassConflicts) { Utility.SetConflicts(entity, copy); ret = entity.CRUDConflict.Fields.Count == 0; } if (ret) { entity.__Elements.ForEach(e => UpdateField(e, copy, fieldsToSave)); CRUDActions.Update <T>(copy, fieldsToSave); entity.__Elements.Where(e => !e.IsCollection).ToList().ForEach(e => SaveCollection(e, copy)); } } } else { //copy.Notifications.ForEach(n => getNLogger().Info(n.Message)); CRUDActions.Create <T>(entity); } } catch (System.Exception ex) { entity.Exceptions.Add(new EntityException(1, ex.Message, ex)); } return(ret); }
public static Collection <Enumeration> GetCollection(List <CriteriaParameter> Parameters, string ConnectionString, string CollectionName = "Enumerations") { Collection <Enumeration> collection = new Collection <Enumeration>(); collection.CollectionName = CollectionName; collection.ConnectionString = ConnectionString; collection.Parameters = Parameters; CRUDActions.Retrieve <Enumeration>(collection); return(collection); }
public static List <FieldPresentation> Summary(string ConnectionString = null) { Collection <FieldPresentation> collection = new Collection <FieldPresentation>(); if (!String.IsNullOrWhiteSpace(ConnectionString)) { collection.ConnectionString = ConnectionString; } CRUDActions.Retrieve <FieldPresentation>(collection); return(collection.ToList()); }
public static void Load <T>(IEntity entity) where T : IEntity { entity.Populated = true; CRUDActions.Retrieve <T>(entity); for (int i = 0; i < entity.__Elements.Count(); i++) { entity.__Memento.Add(new DataProxy() { ElementId = i, Data = entity.__Elements[i].Data }); } }
/*public static bool Save<T>(IEntity entity, bool bypassConflicts) where T : IEntity, new() * { * bool ret = true; * try * { * bool isNew = false; * entity.__Elements.Where(ebd => ebd.UseForMatching).ToList().ForEach(ebd => * { * if ((ebd.TypeName.Equals("int") && int.Parse(ebd.Data.ToString()) == 0) || (ebd.TypeName.Equals("Guid") && Guid.Parse(ebd.Data.ToString()).Equals(Guid.Empty))) * isNew = true; * }); * * if (isNew) * { * CRUDActions.Create<T>(entity); * return true; * } * * IEntity copy = new T(); * copy.ConnectionString = entity.ConnectionString; * entity.__Elements.Where(ebd => ebd.UseForMatching).ToList().ForEach(ebd => copy.__Elements.Find(c => c.Name.Equals(ebd.Name)).Data = ebd.Data); * * CRUDActions.Retrieve<T>(copy); * * if (copy.Notifications.Count == 0) * { * if (entity.__Memento.Count == 0) * { * long fieldsToSave = entity.Compare(copy); * CRUDActions.Merge<T>(entity, fieldsToSave); * } * else * { * long fieldsToSave = entity.Compare(); * if (fieldsToSave == 0) * return false; * * SetWarnings(entity, copy); * * if (!bypassConflicts) * { * SetConflicts(entity, copy); * ret = entity.CRUDConflict.Fields.Count == 0; * } * * if (ret) * { * entity.__Elements.ForEach(e => UpdateField(e, copy, fieldsToSave)); * CRUDActions.Merge<T>(copy, fieldsToSave); * * entity.__Elements.Where(e => !e.IsCollection).ToList().ForEach(e => SaveCollection(e, copy)); * } * } * } * else * { * CRUDActions.Create<T>(entity); * } * } * catch (System.Exception ex) * { * entity.Exceptions.Add(new EntityException(1, ex.Message, ex)); * } * return ret; * }*/ public static void Delete(IEntity entity) { CRUDActions.Delete(entity); if (entity.Exceptions.Count > 0) { string message = entity.Exceptions[0].Print(entity); File.WriteAllText(@"D:\BluePrint\BluePrint.root\BluePrint\BluePrint.Entity.Constructor\bin\Debug\ExceptionMessenger\Exception.html", message); System.Diagnostics.Process.Start(@"D:\BluePrint\BluePrint.root\BluePrint\BluePrint.Entity.Constructor\bin\Debug\ExceptionMessenger\Exception.html"); } return; }
public static int Add <T>(IEntity entity, Collection <T> entities, bool bypassConflicts) where T : IEntity { int ret = 0; //Collection<T> newEntities = new Collection<T>(); Collection <T> copies = new Collection <T>(); Load <T>(copies /*, entity.EntityName*/); Collection <T> newEntities = copies.Except(entities); if (!bypassConflicts && newEntities.Count > 0 && newEntities.ToList().Find(p => p.__Elements.Where(e => e.UseForMatching).Equals(entity.__Elements.Where(e => e.UseForMatching))) != null) { List <CRUDOption> options = new List <CRUDOption>(); options.Add(new CRUDOption() { Message = "Add Anyway", OptionType = CRUDOption.CRUDOptionType.SaveAll }); options.Add(new CRUDOption() { Message = "Cancel Add", OptionType = CRUDOption.CRUDOptionType.Cancel }); //CRUDConflict ex = new CRUDConflict() //{ //Message = "A matching profile was added by another user during your current session.", // Options = options //}; //entity.CRUDConflicts.Add(ex); } else { if (newEntities.Count > 0) { entities.AddRange(newEntities); ////ret = newEntities.ToList().Last().Id + 1; } else { ////ret = entities.ToList().Last().Id + 1; ////entity.Id = ret; //getNLogger().Info(String.Format("Calling CRUDActions.Create({0})", entity.EntityName)); CRUDActions.Create <T>(entity); } } return(ret); }
public static void Load <T>(IEntity entity) where T : IEntity { //getNLogger().Info(String.Format("Calling CRUDActions.Retrieve<T>({0})", entity.EntityName)); entity.Populated = true; CRUDActions.Retrieve <T>(entity); for (int i = 0; i < entity.__Elements.Count(); i++) { entity.__Memento.Add(new DataProxy() { ElementId = i, Data = entity.__Elements[i].Data }); } }
public static bool Update <T>(IEntity entity, bool bypassConflicts = false) where T : IEntity, new() { bool ret = true; try { IEntity copy = new T(); copy.ConnectionString = entity.ConnectionString; copy.__Elements[0].Data = entity.__Elements[0].Data; //getNLogger().Info(String.Format("Calling CRUDActions.Retrieve<T>({0}) for copy", entity.EntityName)); CRUDActions.Retrieve <T>(copy); if (copy.Notifications.Count == 0) { long fieldsToSave = entity.Compare(); //getNLogger().Info(String.Format("fieldsToSave {0}", fieldsToSave)); if (fieldsToSave == 0) { return(false); } Utility.SetWarnings(entity, copy); if (!bypassConflicts) { Utility.SetConflicts(entity, copy); ret = entity.CRUDConflict.Fields.Count == 0; } if (ret) { entity.__Elements.ForEach(e => UpdateField(e, copy, fieldsToSave)); //getNLogger().Info(String.Format("Calling CRUDActions.Update({0}, {1})", entity.EntityName, fieldsToSave.ToString())); CRUDActions.Update <T>(copy, fieldsToSave); } } else { throw new System.Exception("CRUDActions.Retrieve failed during Update"); } } catch (System.Exception ex) { entity.Exceptions.Add(new EntityException(1, ex.Message, ex)); ret = false; } return(ret); }
public static bool Create <T>(IEntity entity) where T : IEntity { bool ret = true; try { //getNLogger().Info(String.Format("Calling CRUDActions.Create<T>({0})", entity.EntityName)); CRUDActions.Create <T>(entity); } catch (SystemException ex) { entity.Exceptions.Add(new EntityException(1, ex.Message, ex)); ret = false; } return(ret); }
public static string CRUDMessage(FeedbackMessageType messageType, CRUDActions action, string targetObject) { var actionSufix = ""; var actionPrefix = ""; switch (messageType) { case FeedbackMessageType.Sucess: actionSufix = "d"; break; case FeedbackMessageType.Failed: actionPrefix = "To"; action.ToString().ToLower(); break; } var feedbackMessage = $"{messageType}: {actionPrefix} {action}{actionSufix} {targetObject}!"; return(feedbackMessage); }
public static bool Save <T>(IEntity entity) where T : IEntity, new() { //return Save<T>(entity, false); //bool ret = true; try { bool isNew = false; entity.__Elements.Where(ebd => ebd.SqlDbIsPrimaryKey).ToList().ForEach(ebd => { if ((ebd.TypeName.Equals("int") && int.Parse(ebd.Data.ToString()) == 0) || (ebd.TypeName.Equals("Guid") && Guid.Parse(ebd.Data.ToString()).Equals(Guid.Empty))) { isNew = true; } }); if (isNew) { CRUDActions.Create <T>(entity); } else { CRUDActions.Update <T>(entity); } ProcessExceptions(entity); //if (entity.Exceptions.Count > 0) //{ // string message = entity.Exceptions[0].Print(entity); // File.WriteAllText(@"D:\BluePrint\BluePrint.root\BluePrint\BluePrint.Entity.Constructor\bin\Debug\ExceptionMessenger\Exception.html", message); // System.Diagnostics.Process.Start(@"D:\BluePrint\BluePrint.root\BluePrint\BluePrint.Entity.Constructor\bin\Debug\ExceptionMessenger\Exception.html"); //} return(true); } catch (System.Exception ex) { entity.Exceptions.Add(new EntityException(1, ex.Message, ex)); return(false); } }
public static int Add <T>(IEntity entity, Collection <T> entities, bool bypassConflicts) where T : IEntity { int ret = 0; Collection <T> copies = new Collection <T>(); Load <T>(copies); Collection <T> newEntities = copies.Except(entities); if (!bypassConflicts && newEntities.Count > 0 && newEntities.ToList().Find(p => p.__Elements.Where(e => e.UseForMatching).Equals(entity.__Elements.Where(e => e.UseForMatching))) != null) { List <CRUDOption> options = new List <CRUDOption>(); options.Add(new CRUDOption() { Message = "Add Anyway", OptionType = CRUDOption.CRUDOptionType.SaveAll }); options.Add(new CRUDOption() { Message = "Cancel Add", OptionType = CRUDOption.CRUDOptionType.Cancel }); } else { if (newEntities.Count > 0) { entities.AddRange(newEntities); } else { CRUDActions.Create <T>(entity); } } return(ret); }
public static void Load <T>(Collection <T> entities) where T : IEntity { //getNLogger().Info(String.Format("Calling CRUDActions.Retrieve<T>({0})", entities.GetType())); CRUDActions.Retrieve <T>(entities); }
public void Delete() { CRUDActions.Delete(this); }
public void Load() { CRUDActions.Retrieve <Field>(this); }
public static void Load <T>(Collection <T> entities) where T : IEntity { CRUDActions.Retrieve <T>(entities); }
public static bool Merge <T>(IEntity entity, bool bypassConflicts = false) where T : IEntity, new() { bool ret = true; try { bool isNew = true; foreach (ElementBaseData ebd in entity.__Elements.Where(ebd => ebd.SqlDbIsPrimaryKey).ToList()) { if ((ebd.TypeName.Equals("int") && int.Parse(ebd.Data.ToString()) != 0) || (ebd.TypeName.Equals("Guid") && !Guid.Parse(ebd.Data.ToString()).Equals(Guid.Empty))) { isNew = false; break; } } if (isNew) { CRUDActions.Create <T>(entity); return(true); } IEntity copy = new T(); copy.ConnectionString = entity.ConnectionString; entity.__Elements.Where(ebd => ebd.SqlDbIsPrimaryKey).ToList().ForEach(ebd => copy.__Elements.Find(c => c.Name.Equals(ebd.Name)).Data = ebd.Data); CRUDActions.Retrieve <T>(copy); if (copy.Notifications.Count == 0) { if (entity.__Memento.Count == 0) { long fieldsToSave = entity.Compare(copy); CRUDActions.Merge <T>(entity, fieldsToSave); } else { long fieldsToSave = entity.Compare(); if (fieldsToSave == 0) { return(false); } SetWarnings(entity, copy); if (!bypassConflicts) { SetConflicts(entity, copy); ret = entity.CRUDConflict.Fields.Count == 0; } if (ret) { entity.__Elements.ForEach(e => UpdateField(e, copy, fieldsToSave)); CRUDActions.Merge <T>(copy, fieldsToSave); entity.__Elements.Where(e => !e.IsCollection).ToList().ForEach(e => SaveCollection(e, copy)); } } } else { CRUDActions.Create <T>(entity); } } catch (System.Exception ex) { entity.Exceptions.Add(new EntityException(1, ex.Message, ex)); } return(ret); }
public void Load() { CRUDActions.Retrieve <Entity>(this); }
public void Load() { CRUDActions.Retrieve <Argument>(this); }
public void Load() { CRUDActions.Retrieve <Attribute>(this); }
public void Load() { CRUDActions.Retrieve <Interface>(this); }
public void Load() { CRUDActions.Retrieve <Action>(this); }
public void Load() { CRUDActions.Retrieve <FieldPresentation>(this); }
public void Load() { CRUDActions.Retrieve <DataType>(this); }
public void Load() { CRUDActions.Retrieve <Method>(this); }