public ConfigurationServiceResponse Save(DCTemplateContract template)
        {
            var response = new ConfigurationServiceResponse();

            try {
                var templateRepository    = new DCTemplateRepository <DCTemplateModel>(UserConnection);
                var repositoryReadOptions = new DCRepositoryReadOptions <DCTemplateModel, DCReplicaModel> {
                    TemplateReadOptions = DCTemplateReadOption.ExcludeAttributes
                                          | DCTemplateReadOption.ExcludeReplicaHtmlContent
                };
                var existedTemplate = templateRepository.ReadByRecordId(template.RecordId, repositoryReadOptions);
                if (existedTemplate != null)
                {
                    template.Id = existedTemplate.Id;
                }
                else if (template.Id.Equals(Guid.Empty))
                {
                    template.Id = Guid.NewGuid();
                }
                templateRepository.Save((DCTemplateModel)template);
            } catch (Exception e) {
                response.Exception = e;
            }
            return(response);
        }
Example #2
0
        /// <summary>
        /// Returns template model with linked entity models by template's unique identifier
        /// using <see cref="Entity"/>.
        /// </summary>
        /// <param name="templateId">Unique identifier of template to read.</param>
        /// <param name="options">Options flags for reads template.</param>
        /// <returns>Template model instance of type <see cref="DCTemplateModel"/></returns>
        protected virtual T ReadTemplate(Guid templateId, DCRepositoryReadOptions <T, DCReplicaModel> options)
        {
            var template = GetEntity(TemplateTableName);

            if (!template.FetchFromDB(templateId))
            {
                return(null);
            }
            return(GetTemplateModelWithLinkedEntities(templateId, options, template));
        }
Example #3
0
        /// <summary>
        /// Returns template model with linked entity models by template's linked entity identifier
        /// using <see cref="Entity"/>.
        /// </summary>
        /// <param name="recordId">Unique identifier of template linked entity.</param>
        /// <param name="options">Options flags for reads template.</param>
        /// <returns>Template model instance of type <see cref="DCTemplateModel"/></returns>
        protected virtual T ReadTemplateByRecordId(Guid recordId, DCRepositoryReadOptions <T, DCReplicaModel> options)
        {
            var template = GetEntity(TemplateTableName);

            if (!template.FetchFromDB("RecordId", recordId))
            {
                return(null);
            }
            ;
            var templateId = template.GetTypedColumnValue <Guid>("Id");

            return(GetTemplateModelWithLinkedEntities(templateId, options, template));
        }
Example #4
0
        private T GetTemplateModelWithLinkedEntities(Guid templateId,
                                                     DCRepositoryReadOptions <T, DCReplicaModel> options, Entity template)
        {
            var groupModels     = ReadTemplateGroups(templateId).ToList();
            var attributeModels = ReadAttributes(templateId).ToList();
            var blockModels     = ReadTemplateBlocks(groupModels).ToList();
            var replicaModels   = ReadReplicas(templateId, options.TemplateReadOptions).ToList();

            SetAttributeIndexesForBlocks(blockModels, attributeModels);
            SetBlockIndexesForReplicas(blockModels, replicaModels);
            var templateModel = new T {
                Id         = template.GetTypedColumnValue <Guid>("Id"),
                RecordId   = template.GetTypedColumnValue <Guid>("RecordId"),
                Attributes = options.TemplateReadOptions.HasFlag(DCTemplateReadOption.ExcludeAttributes)
                                        ? new List <DCAttributeModel>()
                                        : attributeModels,
                Groups   = groupModels,
                Blocks   = blockModels,
                Replicas = replicaModels
            };

            return(templateModel);
        }
Example #5
0
 /// <summary>
 /// Returns template data model for specified linked record id by ESQ with rights checking.
 /// If there is no template in DB or no rights to read method returns NULL.
 /// </summary>
 /// <param name="recordId">Unique identifier of template to read.</param>
 /// <param name="options">Options flags for reads template.</param>
 /// <returns>Template model of type <see cref="DCTemplateModel"/></returns>
 /// <exception cref="ArgumentNullOrEmptyException">Thrown when <paramref name="recordId"/>
 /// equals <see cref="Guid.Empty"/>.</exception>
 public T ReadByRecordId(Guid recordId, DCRepositoryReadOptions <T, DCReplicaModel> options)
 {
     recordId.CheckArgumentEmpty(nameof(recordId));
     return(ReadTemplateByRecordId(recordId, options));
 }
Example #6
0
 /// <summary>
 /// Returns template data model for specified tempate id by ESQ with rights checking.
 /// If there is no template in DB or no rights to read method returns NULL.
 /// Result model is formed on the basis of <paramref name="options"/>.
 /// </summary>
 /// <param name="templateId">Unique identifier of template to read.</param>
 /// <param name="options">Options flags for reads template.</param>
 /// <returns>Template model of type <see cref="DCTemplateModel"/>.</returns>
 public T Read(Guid templateId, DCRepositoryReadOptions <T, DCReplicaModel> options)
 {
     templateId.CheckArgumentEmpty(nameof(templateId));
     return(ReadTemplate(templateId, options));
 }