Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///  Map the CourseSubtopic Model(EF generated) object to custom entity class CourseSubtopic object
        /// </summary>
        /// <param name="objectToMap">EF generated CourseSubtopic model object which will be used for mapping</param>
        /// <returns>Custom Entity class CourseSubtopic object if inputted parameter objectToMap is not null otherwise returns null</returns>
        public CourseSubtopic MapFromCourseSubtopic(EntityFramework.CourseSubtopic objectToMap)
        {
            if (objectToMap == null)
            {
                return(null);
            }

            return(new 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,
            });
        }