Esempio n. 1
0
        /// <summary>
        /// Save current page to audit
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SavePageTemplateLog(PageTemplateLogManageModel model)
        {
            var pageTemplate = _pageTemplateRepository.GetById(model.PageTemplateId);
            if (pageTemplate != null)
            {
                /*
                 * Map page template log model to log entity
                 * Get last updated version of template log
                 * If there are nothing change then do not do anything
                 * Otherwise insert log
                 */
                Mapper.CreateMap<PageTemplateLogManageModel, PageTemplateLog>();
                var log = Mapper.Map<PageTemplateLogManageModel, PageTemplateLog>(model);

                var pageTemplateLog = GetAll().Where(a => a.PageTemplateId == pageTemplate.Id).OrderByDescending(a => a.Id).FirstOrDefault();

                log.ChangeLog = pageTemplateLog != null
                                      ? ChangeLog(pageTemplateLog, model)
                                      : string.Format("** Create Page Template **");

                if (string.IsNullOrEmpty(log.ChangeLog))
                {
                    return new ResponseModel
                    {
                        Success = true
                    };
                }
                log.SessionId = HttpContext.Current.Session.SessionID;
                return Insert(log);
            }
            return new ResponseModel
            {
                Success = false,
                Message = _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::ObjectNotFounded:::Page Template is not founded.")
            };
        }
Esempio n. 2
0
        /// <summary>
        /// Save page template
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SavePageTemplate(PageTemplateManageModel model)
        {
            ResponseModel response;
            var pageTemplate = GetById(model.Id);
            if (pageTemplate != null)
            {
                var log = new PageTemplateLogManageModel(pageTemplate);
                var childTemplates = new List<PageTemplate>();
                if (pageTemplate.Name.Equals(DefaultTemplateName))
                {
                    childTemplates = GetAll().Where(t => !t.Name.Equals(DefaultTemplateName)).ToList();
                }
                else if (!pageTemplate.Content.Equals(model.Content) || pageTemplate.ParentId != model.ParentId)
                {
                    childTemplates = _pageTemplateRepository.GetHierarcies(pageTemplate).ToList();
                }
                if (childTemplates.Any())
                {
                    foreach (var childTemplate in childTemplates)
                    {
                        Update(childTemplate);
                    }
                }

                pageTemplate.Name = model.Name;
                pageTemplate.Content = model.Content;

                pageTemplate.ParentId = model.ParentId;

                response = HierarchyUpdate(pageTemplate);

                if (response.Success)
                {
                    _pageTemplateLogServices.SavePageTemplateLog(log);
                }

                return response.SetMessage(response.Success ?
                    _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::UpdateSuccessfully:::Update page template successfully.")
                    : _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::UpdateFailure:::Update page template failed. Please try again later."));
            }
            Mapper.CreateMap<PageTemplateManageModel, PageTemplate>();
            pageTemplate = Mapper.Map<PageTemplateManageModel, PageTemplate>(model);
            response = HierarchyInsert(pageTemplate);
            return response.SetMessage(response.Success ?
                _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::CreateSuccessfully:::Create page template successfully.")
                : _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::CreateFailure:::Create page template failed. Please try again later."));
        }
Esempio n. 3
0
        /// <summary>
        /// Update data and create change log
        /// </summary>
        /// <param name="pageTemplateLog"></param>
        /// <param name="pageTemplateLogModel"></param>
        /// <returns></returns>
        private string ChangeLog(PageTemplateLog pageTemplateLog, PageTemplateLogManageModel pageTemplateLogModel)
        {
            var changeLog = new StringBuilder();
            const string format = "- Update field: {0}\n";
            if (!ConvertUtilities.Compare(pageTemplateLog.Name, pageTemplateLogModel.Name))
            {
                changeLog.AppendFormat(format, "Name");
                pageTemplateLog.Name = pageTemplateLogModel.Name;
            }
            if (!ConvertUtilities.Compare(pageTemplateLog.Content, pageTemplateLogModel.Content))
            {
                changeLog.AppendFormat(format, "Content");
                pageTemplateLog.Content = pageTemplateLogModel.Content;
            }
            if (!ConvertUtilities.Compare(pageTemplateLog.ParentId, pageTemplateLogModel.ParentId))
            {
                changeLog.AppendFormat(format, "ParentId");
                pageTemplateLog.ParentId = pageTemplateLogModel.ParentId;
            }

            if (!string.IsNullOrEmpty(changeLog.ToString()))
            {
                changeLog.Insert(0, string.Format("** Update Page Template **\n"));
            }

            return changeLog.ToString();
        }