public int AddCourseSubtopic(CourseSubtopic subtopicToAdd) { try { using (var context = new TrainingTrackerEntities()) { EntityFramework.CourseSubtopic newSubtopicEntity = new EntityFramework.CourseSubtopic { Name = subtopicToAdd.Name, CourseId = subtopicToAdd.CourseId, Description = subtopicToAdd.Description, SortOrder = context.CourseSubtopics.Where(c => c.CourseId == subtopicToAdd.CourseId).Count() + 1, AddedBy = subtopicToAdd.AddedBy, IsActive = subtopicToAdd.IsActive, CreatedOn = subtopicToAdd.CreatedOn }; context.CourseSubtopics.Add(newSubtopicEntity); context.SaveChanges(); return(newSubtopicEntity.Id); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(0); } }
public bool UpdateCourseSubtopic(CourseSubtopic subtopicToUpdate) { try { using (var context = new TrainingTrackerEntities()) { var subtopicEntityToUpdate = context.CourseSubtopics.Find(subtopicToUpdate.Id); if (subtopicEntityToUpdate == null) { return(false); } subtopicEntityToUpdate.Name = subtopicToUpdate.Name; subtopicEntityToUpdate.Description = subtopicToUpdate.Description; subtopicEntityToUpdate.CourseId = subtopicToUpdate.CourseId; context.SaveChanges(); return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
/// <summary> /// Map custom entity class CourseSubtopic object to EF generated class CourseSubtopic object /// </summary> /// <param name="objectToMap">Custom entity CourseSubtopic object</param> /// <returns>EF generated course object if inputted parameter objectToMap is not null otherwise returns null</returns> public EFModel.CourseSubtopic MapToEfCourseSubtopic(CommonModel.CourseSubtopic objectToMap) { if (objectToMap == null) { return(null); } return(new EFModel.CourseSubtopic { Id = objectToMap.Id, CourseId = objectToMap.CourseId, Name = objectToMap.Name, Description = objectToMap.Description, AddedBy = objectToMap.AddedBy, SortOrder = objectToMap.SortOrder, IsActive = objectToMap.IsActive, CreatedOn = objectToMap.CreatedOn }); }