Ejemplo n.º 1
0
        /// <summary>
        /// Update value for property of model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateBodyTemplateData(XEditableModel model)
        {
            var bodyTemplate = GetById(model.Pk);

            if (bodyTemplate != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(BodyTemplateManageModel))
                    .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase));
                if (property != null)
                {
                    object value = model.Value.ToType(property, WorkContext.CurrentTimezone);

                    #region Validate

                    var manageModel = new BodyTemplateManageModel(bodyTemplate);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

                    if (validationResults.Any())
                    {
                        return(new ResponseModel
                        {
                            Success = false,
                            Message = validationResults.BuildValidationMessages()
                        });
                    }

                    #endregion

                    bodyTemplate.SetProperty(model.Name, value);
                    var response = Update(bodyTemplate);
                    return(response.SetMessage(response.Success
                        ? T("BodyTemplate_Message_UpdateBodyTemplateInfoSuccessfully")
                        : T("BodyTemplate_Message_UpdateBodyTemplateInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("BodyTemplate_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("BodyTemplate_Message_ObjectNotFound")
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save online template
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public ResponseModel DownloadedOnlineTemplate(int id, string name)
        {
            var template = GetOnlineTemplate(id);

            if (template != null)
            {
                var model = new BodyTemplateManageModel
                {
                    Name        = name,
                    Description = template.Description,
                    ImageUrl    = template.ImageUrl,
                    Content     = template.Content
                };

                #region Validate

                var validationResults = model.ValidateModel();

                if (validationResults.Any())
                {
                    return(new ResponseModel
                    {
                        Success = false,
                        Message = validationResults.BuildValidationMessages()
                    });
                }

                #endregion

                var response = SaveBodyTemplate(model);

                return(response.SetMessage(response.Success
                    ? T("BodyTemplate_Message_DownloadOnlineBodyTemplateSuccessfully")
                    : T("BodyTemplate_Message_DownloadOnlineBodyTemplateFailure")));
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("BodyTemplate_Message_OnlineTemplateNotFound")
            });
        }