public static void MapFromDB(DBEntityItem from, ThisEntityItem to, bool includingItems = true) { to.Id = from.Id; to.ParentId = from.EntityFrameworkId; to.RowId = from.RowId; to.Name = StripJqueryTag(from.Name); to.Description = from.Description; to.TargetName = from.TargetName; to.TargetDescription = from.TargetDescription; to.TargetUrl = from.TargetUrl; to.CodedNotation = from.CodedNotation; if (IsValidDate(from.AlignmentDate)) { to.AlignmentDate = (( DateTime )from.AlignmentDate).ToShortDateString(); } else { to.AlignmentDate = ""; } if (IsValidDate(from.Created)) { to.Created = ( DateTime )from.Created; } to.CreatedById = from.CreatedById == null ? 0 : ( int )from.CreatedById; if (IsValidDate(from.LastUpdated)) { to.LastUpdated = ( DateTime )from.LastUpdated; } to.LastUpdatedById = from.LastUpdatedById == null ? 0 : ( int )from.LastUpdatedById; to.LastUpdatedBy = SetLastUpdatedBy(to.LastUpdatedById, from.Account_Modifier); }
} // /// <summary> /// Get a competency record /// </summary> /// <param name="profileId"></param> /// <returns></returns> public static ThisEntityItem Entity_Competency_Get(int profileId) { ThisEntityItem entity = new ThisEntityItem(); if (profileId == 0) { return(entity); } try { using (var context = new EntityContext()) { DBEntityItem item = context.Entity_CompetencyFrameworkItem .SingleOrDefault(s => s.Id == profileId); if (item != null && item.Id > 0) { MapFromDB(item, entity, true); } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".Entity_Competency_Get"); } return(entity); } //
public IEnumerable <WeatherForecast> WeatherForecasts() { DBController connection = new DBController(); DBEntityItem item = connection.GetItemTextByID(1111); return(Enumerable.Range(0, 5).Select(index => new WeatherForecast { DateFormatted = DateTime.Now.AddDays(index).ToString("d"), TemperatureC = 0, Summary = index == 0 ? item.question.entity_text : item.answers[index - 1].entity_text })); }
/// <summary> /// Delete a competency /// </summary> /// <param name="recordId"></param> /// <param name="statusMessage"></param> /// <returns></returns> public bool Entity_Competency_Delete(int recordId, ref string statusMessage) { bool isOK = true; using (var context = new EntityContext()) { DBEntityItem p = context.Entity_CompetencyFrameworkItem.FirstOrDefault(s => s.Id == recordId); if (p != null && p.Id > 0) { context.Entity_CompetencyFrameworkItem.Remove(p); int count = context.SaveChanges(); } else { statusMessage = string.Format("The record was not found: {0}", recordId); isOK = false; } } return(isOK); }
} // public static void MapToDB(ThisEntityItem from, DBEntityItem to) { //want to ensure fields from create are not wiped //to.Id = from.Id; to.EntityFrameworkId = from.ParentId; to.Name = StripJqueryTag(from.Name); to.Description = from.Description; to.TargetName = from.TargetName; to.TargetDescription = from.TargetDescription; to.TargetUrl = from.TargetUrl; to.CodedNotation = from.CodedNotation; if (IsValidDate(from.AlignmentDate)) { to.AlignmentDate = DateTime.Parse(from.AlignmentDate); } else { to.AlignmentDate = null; } }
/// <summary> /// Add/Update a competency /// </summary> /// <param name="entity"></param> /// <param name="parentUid"></param> /// <param name="userId"></param> /// <param name="messages"></param> /// <returns></returns> public bool Entity_Competency_Save(ThisEntityItem entity, int userId, ref SaveStatus status) { bool isValid = true; int intialCount = messages.Count; if (entity.ParentId == 0) { status.AddWarning("Error: the parent identifier was not provided."); } if (messages.Count > intialCount) { return(false); } int count = 0; DBEntityItem efEntity = new DBEntityItem(); using (var context = new EntityContext()) { bool isEmpty = false; if (ValidateProfile(entity, ref isEmpty, ref status) == false) { return(false); } if (isEmpty) { status.AddWarning("The Competency Profile is empty. "); return(false); } if (entity.Id == 0) { //add efEntity = new DBEntityItem(); MapToDB(entity, efEntity); efEntity.Created = efEntity.LastUpdated = DateTime.Now; efEntity.CreatedById = efEntity.LastUpdatedById = userId; efEntity.RowId = Guid.NewGuid(); context.Entity_CompetencyFrameworkItem.Add(efEntity); count = context.SaveChanges(); entity.Id = efEntity.Id; entity.RowId = efEntity.RowId; if (count == 0) { status.AddWarning(string.Format(" Unable to add Profile: {0} <br\\> ", string.IsNullOrWhiteSpace(entity.Name) ? "no description" : entity.Description)); } } else { efEntity = context.Entity_CompetencyFrameworkItem.SingleOrDefault(s => s.Id == entity.Id); if (efEntity != null && efEntity.Id > 0) { entity.RowId = efEntity.RowId; //update MapToDB(entity, efEntity); //has changed? if (HasStateChanged(context)) { efEntity.LastUpdated = System.DateTime.Now; efEntity.LastUpdatedById = userId; count = context.SaveChanges(); } } } } return(isValid); }