private int HandleComponentCondition(PathwayComponentCondition input, Pathway pathway, PathwayComponent component, ref SaveStatus status) { int newId = 0; List <string> messages = new List <string>(); string statusMessage = ""; input.ParentComponentId = component.Id; if (pccm.Save(input, ref messages)) { newId = input.Id; activityMgr.SiteActivityAdd(new SiteActivity() { ActivityType = "PathwayComponent", Activity = "Import", Event = "Add", Comment = string.Format("Added PathwayComponentCondition via Import: '{0}' for Component: '{1}'", input.Name, component.Name), ActivityObjectId = newId, }); } else { status.AddErrorRange(messages); } if (newId == 0 || (!string.IsNullOrWhiteSpace(statusMessage) && statusMessage != "successful")) { status.AddError(string.Format("Row: Issue encountered updating pathway ComponentCondition: {0} for Component: '{1}': {2}", input.Name, component.Name, statusMessage)); return(0); } //================================================== //handle target components - better organization to move this to HandleComponentCondition since all components should now exist List <PathwayComponent> profiles = new List <PathwayComponent>(); messages = new List <string>(); foreach (var tc in input.HasTargetComponentList) { var targetComponent = PathwayComponentManager.Get(tc); if (targetComponent == null || targetComponent.Id == 0) { //shouldn't happen here - although the add attempt could have failed? status.AddError(string.Format("The target pathway component: {0} for ConditionComponent: {1} was not found. This could have been due the an issue adding the component - which should have resulted in an earlier error message.", tc, input.Name)); continue; } profiles.Add(targetComponent); } //now replace relationships if (!epcmgr.Replace(input.RowId, PathwayComponent.PathwayComponentRelationship_TargetComponent, profiles, ref status)) { //status.AddErrorRange( messages ); } return(newId); }
/// <summary> /// Delete all HoldersProfiles for parent /// </summary> /// <param name="parent"></param> /// <param name="status"></param> /// <returns></returns> public bool DeleteAll(Entity parent, ref SaveStatus status) { bool isValid = true; int count = 0; if (parent == null || parent.Id == 0) { status.AddError(thisClassName + ". Error - the provided target parent entity was not provided."); return(false); } try { using (var context = new EntityContext()) { //check if target is a reference object and is only in use here var results = context.Entity_HoldersProfile .Where(s => s.EntityId == parent.Id) .OrderBy(s => s.Created) .ToList(); if (results == null || results.Count == 0) { return(true); } foreach (var item in results) { if (item.HoldersProfile != null && item.HoldersProfile.Id > 0) { var messages = new List <string>(); //this will delete the Entity_HoldersProfile as well. Delete(item.HoldersProfile.Id, ref messages); if (messages.Any()) { status.AddErrorRange(messages); } } //context.Entity_HoldersProfile.Remove( item ); //count = context.SaveChanges(); //if ( count > 0 ) //{ //} } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".DeleteAll"); } return(isValid); }
/// <summary> /// Delete all EarningsProfiles for parent /// </summary> /// <param name="parent"></param> /// <param name="status"></param> /// <returns></returns> public bool DeleteAll(Guid parentUid, ref SaveStatus status) { bool isValid = true; int count = 0; Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { status.AddError(thisClassName + ".DeleteAll Error - the provided target parent entity was not provided."); return(false); } if (parent == null || parent.Id == 0) { status.AddError(thisClassName + ". Error - the provided target parent entity was not provided."); return(false); } using (var context = new EntityContext()) { //check if target is a reference object and is only in use here var results = context.Entity_EarningsProfile .Where(s => s.EntityId == parent.Id) .OrderBy(s => s.Created) .ToList(); if (results == null || results.Count == 0) { return(true); } foreach (var item in results) { if (item.EarningsProfile != null && item.EarningsProfile.EntityStateId > 0) { var messages = new List <string>(); new EarningsProfileManager().Delete(item.Id, ref messages); if (messages.Any()) { status.AddErrorRange(messages); } continue; } context.Entity_EarningsProfile.Remove(item); count = context.SaveChanges(); if (count > 0) { } } } return(isValid); }
public bool SaveList(List <ThisEntity> input, Entity parentEntity, ref SaveStatus status) { bool allIsValid = true; try { //need to handle deletes for parent? //will be an issue for shared datasets //DeleteAll( parentEntity, ref status ); using (var context = new EntityContext()) { //get all datasetProfiles for this parent var existing = context.Entity_DataSetProfile.Where(s => s.EntityId == parentEntity.Id).ToList(); //huh - only deleting //object get all e_dsp for current parent where the ctid is not found in the input list. // - we will want to delete the e_dsp for the latter (and maybe dsp if no other connections) var result = existing.Where(ex => input.All(p2 => p2.CTID != ex.DataSetProfile.CTID)).ToList(); var messages = new List <string>(); foreach (var item in result) { Delete(item.Id, ref messages); } if (messages.Any()) { status.AddErrorRange(messages); } } if (input == null || !input.Any()) { return(true); } foreach (var item in input) { //current the datasetProfile is not being deleted - may be OK - TBD var e = GetByCtid(item.CTID); item.Id = e.Id; if (!Save(item, parentEntity, ref status)) { allIsValid = false; } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".SaveList()"); } return(allIsValid); }
public bool SaveList(List <ThisEntity> input, int dataSetProfileId, ref SaveStatus status) { bool allIsValid = true; int dataSetTimeFrameId = 0; int icnt = 0; if (input != null && input.Any()) { icnt = input.Count(); } //need to handle deletes for parent? //if ( input == null || !input.Any() ) // DeleteAll( dataSetProfileId, ref status ); //if one existing, and one input, just replace using (var context = new EntityContext()) { bool doingDelete = false; var existing = context.DataSetTimeFrame.Where(s => s.DataSetProfileId == dataSetProfileId).ToList(); if (existing != null && existing.Any()) { if (existing.Count() == 1 && icnt == 1) { dataSetTimeFrameId = existing[0].Id; } else { //may always be a delete regardless of this if? if (icnt < existing.Count() || icnt > 1) { doingDelete = true; } } } if (doingDelete) { var messages = new List <string>(); DeleteAll(dataSetProfileId, ref messages); if (messages.Any()) { status.AddErrorRange(messages); } dataSetTimeFrameId = 0; } } if (input == null || !input.Any()) { return(true); } foreach (var item in input) { if (dataSetTimeFrameId > 0) { var e = GetBasic(dataSetTimeFrameId); if (e != null) { item.Id = e.Id; } } item.DataSetProfileId = dataSetProfileId; if (!Save(item, ref status)) { allIsValid = false; } } return(allIsValid); }
public bool SaveList(List <ThisEntity> input, int dataSetTimeFrameId, ref SaveStatus status) { bool allIsValid = true; int dataProfileId = 0; int icnt = 0; if (input != null && input.Any()) { icnt = input.Count(); } //need to handle deletes for parent? //DeleteAll( dataSetTimeFrameId, ref status ); using (var context = new EntityContext()) { bool doingDelete = false; var existing = context.DataProfile.Where(s => s.DataSetTimeFrameId == dataSetTimeFrameId).ToList(); if (existing != null && existing.Any()) { //a possibility would to skip delete if input and output count are equal if (existing.Count() == 1 && icnt == 1) { dataSetTimeFrameId = existing[0].DataSetTimeFrameId; dataProfileId = existing[0].Id; } else { //may always be a delete regardless of this if? if (icnt < existing.Count() || icnt > 1) { doingDelete = true; } } } if (doingDelete) { var messages = new List <string>(); DeleteAll(dataSetTimeFrameId, ref messages); if (messages.Any()) { status.AddErrorRange(messages); } dataProfileId = 0; } } if (input == null || !input.Any()) { return(true); } //status.Messages = new List<StatusMessage>(); foreach (var item in input) { //this would only be valid for the first record, should reset it just in case if (dataProfileId > 0) { var e = GetBasic(dataProfileId); if (e != null) { item.Id = e.Id; } dataProfileId = 0; } item.DataSetTimeFrameId = dataSetTimeFrameId; //status.HasErrors = false; if (!Save(item, ref status)) { allIsValid = false; } } return(allIsValid); }