public static ThisEntity Get(int parentId, int TransferValueProfileId) { ThisEntity entity = new ThisEntity(); if (parentId < 1 || TransferValueProfileId < 1) { return(entity); } try { using (var context = new EntityContext()) { EM.Entity_TransferValueProfile from = context.Entity_TransferValueProfile .SingleOrDefault(s => s.TransferValueProfileId == TransferValueProfileId && s.EntityId == parentId); if (from != null && from.Id > 0) { entity.Id = from.Id; entity.TransferValueProfileId = from.TransferValueProfileId; entity.EntityId = from.EntityId; entity.TransferValueProfile = new TransferValueProfile(); TransferValueProfileManager.MapFromDB(from.TransferValueProfile, entity.TransferValueProfile); if (IsValidDate(from.Created)) { entity.Created = ( DateTime )from.Created; } } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".Get"); } return(entity); } //
/// <summary> /// Add an Entity TransferValueProfile /// </summary> /// <param name="parentUid"></param> /// <param name="transferValueProfileId"></param> /// <param name="relationshipTypeId"></param> /// <param name="allowMultiples">If false, check if an TransferValueProfile exists. If found, do an update</param> /// <param name="messages"></param> /// <returns></returns> public int Add(Guid parentUid, int transferValueProfileId, ref SaveStatus status) { int id = 0; int count = 0; if (transferValueProfileId < 1) { status.AddError(string.Format("A valid TransferValueProfile identifier ({0}) was not provided to the {1}.EntityTransferValueProfile_Add method.", transferValueProfileId, thisClassName)); return(0); } Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { status.AddError("Error - the parent entity was not found."); return(0); } using (var context = new EntityContext()) { DBEntity efEntity = new DBEntity(); try { //first check for duplicates efEntity = context.Entity_TransferValueProfile .FirstOrDefault(s => s.EntityId == parent.Id && s.TransferValueProfileId == transferValueProfileId); if (efEntity != null && efEntity.Id > 0) { return(0); } efEntity = new DBEntity(); efEntity.EntityId = parent.Id; efEntity.TransferValueProfileId = transferValueProfileId; efEntity.Created = System.DateTime.Now; context.Entity_TransferValueProfile.Add(efEntity); // submit the change to database count = context.SaveChanges(); if (count > 0) { id = efEntity.Id; return(efEntity.Id); } else { //?no info on error status.AddError(thisClassName + "Error - the add was not successful."); string message = thisClassName + string.Format(".Add Failed", "Attempted to add a TransferValueProfile for a profile. The process appeared to not work, but there was no exception, so we have no message, or no clue. Parent Profile: {0}, Type: {1}, TransferValueProfileId: {2}", parentUid, parent.EntityType, transferValueProfileId); EmailManager.NotifyAdmin(thisClassName + ".Add Failed", message); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbex) { string message = HandleDBValidationError(dbex, thisClassName + ".Add() ", "Entity_TransferValueProfile"); status.AddError("Error - the save was not successful. " + message); LoggingHelper.LogError(dbex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId)); } catch (Exception ex) { string message = FormatExceptions(ex); status.AddError("Error - the save was not successful. " + message); LoggingHelper.LogError(ex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId)); } } return(id); }