Example #1
0
 /// <summary>
 /// Copy link information to the other link without the Id.
 /// </summary>
 internal void CopyTo(ResourceLink other)
 {
     other.SourceResourceName = SourceResourceName;
     other.Relation = Relation;
     other.DestinationResourceName = DestinationResourceName;
     other.Parameters = Parameters.Select(v => v.Clone()).ToList();
 }
Example #2
0
        public ResourceLinkModel(ResourceLink link, ResourceDescriptor destinationResourceDescriptor)
            : this()
        {
            Id = link.Id;
            Relation = link.Relation;
            DestinationResourceName = link.DestinationResourceName;

            foreach (var linkParam in link.Parameters)
            {
                var param = destinationResourceDescriptor.InputPramameters.FirstOrDefault(p => p.Name == linkParam.Name);
                if (param != null)
                {
                    var paramModel = new ResourceLinkParameterModel
                    {
                        Name = linkParam.Name,
                        Value = linkParam.Value,
                        UseFixedValue = linkParam.UseFixedValue,
                        Required = param.Required,
                        ParameterType = param.ParameterType.Name
                    };

                    if (param.Required)
                    {
                        RequiredParameters.Add(paramModel);
                    }
                    else
                    {
                        OptionalParameters.Add(paramModel);
                    }
                }
            }
        }
Example #3
0
        public void UpdateTo(ResourceLink link)
        {
            link.Relation = Relation;
            link.DestinationResourceName = DestinationResourceName;

            var parameters = new List<ResourceLinkParameter>();
            parameters.AddRange(ToResourceLinkParameters(RequiredParameters));
            parameters.AddRange(ToResourceLinkParameters(OptionalParameters));

            link.Parameters = parameters;
        }
        public ActionResult SaveLink(string sourceResourceName, ResourceLinkModel linkModel)
        {
            ResourceLink link = null;

            if (!String.IsNullOrEmpty(linkModel.Id))
            {
                link = _resourceLinkPersistence.GetById(linkModel.Id);
                linkModel.UpdateTo(link);
                _resourceLinkPersistence.Save(link);
            }
            else
            {
                link = new ResourceLink
                {
                    SourceResourceName = sourceResourceName
                };
                linkModel.UpdateTo(link);
                _resourceLinkPersistence.Save(link);
            }

            return AjaxForm().Success().WithModel(new
            {
                Id = link.Id
            });
        }