/// <summary> /// Obtiene un elemento de la colección AgroData, de acuerdo al tipo, seleccionará la colección correspondente para retornar el objeto. /// </summary> /// <typeparam name="T">Tipo de elemento a retornar</typeparam> /// <param name="id">identificador del elemento</param> /// <returns></returns> private static T GetElement <T>(string id) { // índice de la clase, de acuerdo al modelo mdm. var index = Mdm.GetIndex(typeof(T)); // excepción si no tiene el atributo. if (!index.HasValue) { throw new System.Exception("el objeto debe tener el atributo ReferenceHeader"); } // de acuerdo al entityRelated entregará el elemento. var entityRelated = (EntityRelated)index.Value; switch (entityRelated) { case EntityRelated.WAITINGHARVEST: throw new Exception("waitin harvest no es un elemento de base de datos, este elemento no hereda de DocumentBase"); case EntityRelated.BARRACK: return((T)(object)AgroData.Barracks.First(s => s.Id.Equals(id))); case EntityRelated.BUSINESSNAME: return((T)(object)AgroData.BusinessNames.First(s => s.Id.Equals(id))); case EntityRelated.CATEGORY_INGREDIENT: return((T)(object)AgroData.IngredientCategories.First(s => s.Id.Equals(id))); case EntityRelated.CERTIFIED_ENTITY: return((T)(object)AgroData.CertifiedEntities.First(s => s.Id.Equals(id))); case EntityRelated.COSTCENTER: return((T)(object)AgroData.CostCenters.First(s => s.Id.Equals(id))); case EntityRelated.DOSES: return((T)(object)AgroData.Doses.First(s => s.Id.Equals(id))); case EntityRelated.INGREDIENT: return((T)(object)AgroData.Ingredients.First(s => s.Id.Equals(id))); case EntityRelated.JOB: return((T)(object)AgroData.Jobs.First(s => s.Id.Equals(id))); case EntityRelated.NEBULIZER: return((T)(object)AgroData.Nebulizers.First(s => s.Id.Equals(id))); case EntityRelated.PHENOLOGICAL_EVENT: return((T)(object)AgroData.PhenologicalEvents.First(s => s.Id.Equals(id))); case EntityRelated.PLOTLAND: return((T)(object)AgroData.PlotLands.First(s => s.Id.Equals(id))); case EntityRelated.PRODUCT: return((T)(object)AgroData.Products.First(s => s.Id.Equals(id))); case EntityRelated.ROLE: return((T)(object)AgroData.Roles.First(s => s.Id.Equals(id))); case EntityRelated.ROOTSTOCK: return((T)(object)AgroData.Rootstocks.First(s => s.Id.Equals(id))); case EntityRelated.SEASON: return((T)(object)AgroData.Seasons.First(s => s.Id.Equals(id))); case EntityRelated.SECTOR: return((T)(object)AgroData.Sectors.First(s => s.Id.Equals(id))); case EntityRelated.PREORDER: return((T)(object)AgroData.PreOrders.First(s => s.Id.Equals(id))); case EntityRelated.TARGET: return((T)(object)AgroData.ApplicationTargets.First(s => s.Id.Equals(id))); case EntityRelated.TRACTOR: return((T)(object)AgroData.Tractors.First(s => s.Id.Equals(id))); case EntityRelated.USER: break; case EntityRelated.VARIETY: return((T)(object)AgroData.Varieties.First(s => s.Id.Equals(id))); case EntityRelated.NOTIFICATION_EVENT: break; case EntityRelated.POLLINATOR: break; case EntityRelated.ORDER_FOLDER: return((T)(object)AgroData.OrderFolders.First(s => s.Id.Equals(id))); case EntityRelated.EXECUTION_ORDER: break; case EntityRelated.ORDER: break; case EntityRelated.BARRACK_EVENT: break; case EntityRelated.DOSES_ORDER: break; case EntityRelated.EXECUTION_ORDER_STATUS: break; case EntityRelated.SPECIE: return((T)(object)AgroData.Species.First(s => s.Id.Equals(id))); case EntityRelated.GEOPOINT: break; case EntityRelated.BRAND: return((T)(object)AgroData.Brands.First(s => s.Id.Equals(id))); default: throw new Exception("not good"); } throw new Exception("not good"); }
/// <summary> /// Borra un elemento de una colección de AgroData, /// la colección esta determinada por el tipo de dato. /// </summary> /// <typeparam name="T">Tipo de dato a eliminar</typeparam> /// <param name="id">identificador del elemento a eliminar</param> private static void RemoveElementFromDb <T>(string id) { // índice del tipo en el modelo mdm. var index = Mdm.GetIndex(typeof(T)); // si no tiene atributo if (!index.HasValue) { throw new System.Exception("el objeto debe tener el atributo ReferenceHeader"); } // de acuerdo al tipo de entityRelated eliminará el elemento. var entityRelated = (EntityRelated)index.Value; switch (entityRelated) { case EntityRelated.WAITINGHARVEST: AgroData.WaitingHarvest = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.WaitingHarvest); break; case EntityRelated.BARRACK: AgroData.Barracks = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Barracks); break; case EntityRelated.BUSINESSNAME: AgroData.BusinessNames = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.BusinessNames); break; case EntityRelated.CATEGORY_INGREDIENT: AgroData.IngredientCategories = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.IngredientCategories); break; case EntityRelated.CERTIFIED_ENTITY: AgroData.CertifiedEntities = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.CertifiedEntities); break; case EntityRelated.COSTCENTER: AgroData.CostCenters = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.CostCenters); break; case EntityRelated.DOSES: AgroData.Doses = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Doses); break; case EntityRelated.INGREDIENT: AgroData.Ingredients = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Ingredients); break; case EntityRelated.JOB: break; case EntityRelated.NEBULIZER: break; case EntityRelated.PHENOLOGICAL_EVENT: break; case EntityRelated.PLOTLAND: break; case EntityRelated.PRODUCT: AgroData.Products = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Products); break; case EntityRelated.ROLE: break; case EntityRelated.ROOTSTOCK: AgroData.Rootstocks = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Rootstocks); break; case EntityRelated.SEASON: AgroData.Seasons = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Seasons); break; case EntityRelated.SECTOR: AgroData.Sectors = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Sectors); break; case EntityRelated.PREORDER: break; case EntityRelated.TARGET: break; case EntityRelated.TRACTOR: break; case EntityRelated.USER: break; case EntityRelated.VARIETY: AgroData.Varieties = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Varieties); break; case EntityRelated.NOTIFICATION_EVENT: break; case EntityRelated.POLLINATOR: break; case EntityRelated.ORDER_FOLDER: break; case EntityRelated.EXECUTION_ORDER: break; case EntityRelated.ORDER: break; case EntityRelated.BARRACK_EVENT: break; case EntityRelated.DOSES_ORDER: break; case EntityRelated.EXECUTION_ORDER_STATUS: break; case EntityRelated.SPECIE: AgroData.Species = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Species); break; case EntityRelated.GEOPOINT: break; case EntityRelated.BRAND: AgroData.Brands = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.Brands); break; default: break; } }
/// <summary> /// Añade un elemento a una colección de AgroData, de acuerdo al tipo de elemento a insertar. /// </summary> /// <typeparam name="T">Tipo de elemento a insertar</typeparam> /// <param name="element">elemento a insertar en una de las colecciones</param> private static void AddElement <T>(T element) where T : DocumentBase { // obtiene el índice desde mdm, utiliza el atributo para identificar a que entitySearch pertenece. var index = Mdm.GetIndex(typeof(T)); // si no tiene el atributo, lanzará error. if (!index.HasValue) { throw new System.Exception("el objeto debe tener el atributo ReferenceHeader"); } // de acuerdo al entityRelated insertaremos en la colección. var entityRelated = (EntityRelated)index.Value; switch (entityRelated) { case EntityRelated.WAITINGHARVEST: // no es un elemento de base de datos break; case EntityRelated.BARRACK: AgroData.Barracks = Mdm.Reflection.Collections.UpsertToCollection((Barrack)(object)element, AgroData.Barracks); break; case EntityRelated.BUSINESSNAME: AgroData.BusinessNames = Mdm.Reflection.Collections.UpsertToCollection((BusinessName)(object)element, AgroData.BusinessNames); break; case EntityRelated.CATEGORY_INGREDIENT: AgroData.IngredientCategories = Mdm.Reflection.Collections.UpsertToCollection((IngredientCategory)(object)element, AgroData.IngredientCategories); break; case EntityRelated.CERTIFIED_ENTITY: AgroData.CertifiedEntities = Mdm.Reflection.Collections.UpsertToCollection((CertifiedEntity)(object)element, AgroData.CertifiedEntities); break; case EntityRelated.COSTCENTER: AgroData.CostCenters = Mdm.Reflection.Collections.UpsertToCollection((CostCenter)(object)element, AgroData.CostCenters); break; case EntityRelated.DOSES: AgroData.Doses = Mdm.Reflection.Collections.UpsertToCollection((Dose)(object)element, AgroData.Doses); break; case EntityRelated.INGREDIENT: AgroData.Ingredients = Mdm.Reflection.Collections.UpsertToCollection((Ingredient)(object)element, AgroData.Ingredients); break; case EntityRelated.JOB: AgroData.Jobs = Mdm.Reflection.Collections.UpsertToCollection((Job)(object)element, AgroData.Jobs); break; case EntityRelated.NEBULIZER: AgroData.Nebulizers = Mdm.Reflection.Collections.UpsertToCollection((Nebulizer)(object)element, AgroData.Nebulizers); break; case EntityRelated.PHENOLOGICAL_EVENT: AgroData.PhenologicalEvents = Mdm.Reflection.Collections.UpsertToCollection((PhenologicalEvent)(object)element, AgroData.PhenologicalEvents); break; case EntityRelated.PLOTLAND: AgroData.PlotLands = Mdm.Reflection.Collections.UpsertToCollection((PlotLand)(object)element, AgroData.PlotLands); break; case EntityRelated.PRODUCT: AgroData.Products = Mdm.Reflection.Collections.UpsertToCollection((Product)(object)element, AgroData.Products); break; case EntityRelated.ROLE: AgroData.Roles = Mdm.Reflection.Collections.UpsertToCollection((Role)(object)element, AgroData.Roles); break; case EntityRelated.ROOTSTOCK: AgroData.Rootstocks = Mdm.Reflection.Collections.UpsertToCollection((Rootstock)(object)element, AgroData.Rootstocks); break; case EntityRelated.SEASON: AgroData.Seasons = Mdm.Reflection.Collections.UpsertToCollection((Season)(object)element, AgroData.Seasons); break; case EntityRelated.SECTOR: AgroData.Sectors = Mdm.Reflection.Collections.UpsertToCollection((Sector)(object)element, AgroData.Sectors); break; case EntityRelated.PREORDER: AgroData.PreOrders = Mdm.Reflection.Collections.UpsertToCollection((PreOrder)(object)element, AgroData.PreOrders); break; case EntityRelated.TARGET: AgroData.ApplicationTargets = Mdm.Reflection.Collections.UpsertToCollection((ApplicationTarget)(object)element, AgroData.ApplicationTargets); break; case EntityRelated.TRACTOR: AgroData.Tractors = Mdm.Reflection.Collections.UpsertToCollection((Tractor)(object)element, AgroData.Tractors); break; case EntityRelated.USER: break; case EntityRelated.VARIETY: AgroData.Varieties = Mdm.Reflection.Collections.UpsertToCollection((Variety)(object)element, AgroData.Varieties); break; case EntityRelated.NOTIFICATION_EVENT: AgroData.NotificationEvents = Mdm.Reflection.Collections.UpsertToCollection((NotificationEvent)(object)element, AgroData.NotificationEvents); break; case EntityRelated.POLLINATOR: break; case EntityRelated.ORDER_FOLDER: AgroData.OrderFolders = Mdm.Reflection.Collections.UpsertToCollection((OrderFolder)(object)element, AgroData.OrderFolders); break; case EntityRelated.EXECUTION_ORDER: break; case EntityRelated.ORDER: break; case EntityRelated.BARRACK_EVENT: break; case EntityRelated.DOSES_ORDER: break; case EntityRelated.EXECUTION_ORDER_STATUS: break; case EntityRelated.SPECIE: AgroData.Species = Mdm.Reflection.Collections.UpsertToCollection((Specie)(object)element, AgroData.Species); break; case EntityRelated.GEOPOINT: break; case EntityRelated.BRAND: AgroData.Brands = Mdm.Reflection.Collections.UpsertToCollection((Brand)(object)element, AgroData.Brands); break; default: throw new System.Exception("not good"); } }