Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }