コード例 #1
0
ファイル: LearningPathDal.cs プロジェクト: TrainingTracker/TT
        public bool UpdateSubtopicContent(SubtopicContent dataToUpdate)
        {
            try
            {
                using (var context = new TrainingTrackerEntities())
                {
                    var entityToUpdate = context.SubtopicContents.Find(dataToUpdate.Id);
                    if (entityToUpdate == null)
                    {
                        return(false);
                    }

                    entityToUpdate.Name             = dataToUpdate.Name;
                    entityToUpdate.Description      = dataToUpdate.Description;
                    entityToUpdate.Url              = dataToUpdate.Url;
                    entityToUpdate.CourseSubtopicId = dataToUpdate.CourseSubtopicId;

                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                return(false);
            }
        }
コード例 #2
0
ファイル: LearningPathDal.cs プロジェクト: TrainingTracker/TT
        public bool AddSubtopicContent(SubtopicContent dataToAdd, out int id)
        {
            try
            {
                using (var context = new TrainingTrackerEntities())
                {
                    EntityFramework.SubtopicContent entityToAdd = new EntityFramework.SubtopicContent
                    {
                        Name             = dataToAdd.Name,
                        Description      = dataToAdd.Description,
                        CourseSubtopicId = dataToAdd.CourseSubtopicId,
                        Url       = dataToAdd.Url,
                        SortOrder = context.SubtopicContents.Where(s => s.CourseSubtopicId == dataToAdd.CourseSubtopicId).Count() + 1,
                        AddedBy   = dataToAdd.AddedBy,
                        CreatedOn = dataToAdd.CreatedOn,
                        IsActive  = dataToAdd.IsActive
                    };
                    context.SubtopicContents.Add(entityToAdd);
                    context.SaveChanges();

                    id = entityToAdd.Id;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                id = 0;
                return(false);
            }
        }