示例#1
0
        /// <summary>
        /// Add Course
        /// </summary>
        /// <param name="courseToAdd">Course data object</param>
        /// <returns>Course Id of the added course if successful otherwise 0 </returns>
        public int AddCourse(Course courseToAdd)
        {
            try
            {
                using (var context = new TrainingTrackerEntities())
                {
                    EntityFramework.Course newCourseEntity = ModelMapper.MapToCourseModel(courseToAdd);

                    context.Courses.Add(newCourseEntity);
                    context.SaveChanges();
                    return(newCourseEntity.Id);
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                return(0);
            }
        }
示例#2
0
        /// <summary>
        /// Map the Course Model(EF generated) object to custom entity class Course object
        /// </summary>
        /// <param name="objectToMap">EF generated course model object which will be used for mapped</param>
        /// <returns>Mapped custom entity course object if inputted parameter objectToMap is not null otherwise returns null</returns>
        public Course MapFromCourseModel(EntityFramework.Course objectToMap)
        {
            if (objectToMap == null)
            {
                return(null);
            }

            return(new Course
            {
                Id = objectToMap.Id,
                Name = objectToMap.Name,
                Description = objectToMap.Description,
                Icon = objectToMap.Icon,
                AddedBy = objectToMap.AddedBy,
                IsActive = objectToMap.IsActive,
                IsPublished = objectToMap.IsPublished,
                Duration = objectToMap.Duration,
                CreatedOn = objectToMap.CreatedOn,
            });
        }