/// <summary>
        /// 添加关系
        /// </summary>
        /// <param name="consumerDirectoryName"></param>
        /// <param name="providerDirectoryName"></param>
        public void AddRelation(string consumerDirectoryName, string[] providerDirectoryName)
        {
            var consumerDirectory = RepositoryRegistry.Directory.FindBy(consumerDirectoryName);
            if (string.IsNullOrEmpty(consumerDirectoryName) || providerDirectoryName == null || providerDirectoryName.Length == 0)
            {
                return;
            }

            string newMd5;
            bool isSame = new RelationShipCheckService().IsSame(providerDirectoryName,consumerDirectory.UsedServiceMd5, out newMd5);
            if (isSame)
            {
                return;
            }

            var providerDirectorys = RepositoryRegistry.Directory.FindBy(providerDirectoryName);
            if(providerDirectorys.Count() != providerDirectoryName.Length)
            {
                return;
            }

            var list = new List<Model.Relationship>();
            foreach (var item in providerDirectorys)
            {
                var consumerInfo = new ConsumerInfo(consumerDirectory.Name, consumerDirectory.Id);
                var providerInfo = new ProviderInfo(item.Name, item.Id);
                var relationship = new Model.Relationship(consumerInfo, providerInfo);
                list.Add(relationship);
            }
            RepositoryRegistry.Relationship.Add(list);

            this.PublishEvent("AddRelation", new UpdateMD5DomainEvent(consumerDirectory.Id, newMd5));
        }
 public static Model.Relationship Create()
 {
     var relationship = new Model.Relationship(new ConsumerInfo("订单", 1), new ProviderInfo("菜单", 1));
     return relationship;
 }
Esempio n. 3
0
        public void Save()
        {
            using (var db = new AspNetDatingDataContext())
            {
                var relationship = new Model.Relationship()
                                        {
                                            r_id = id,
                                            u_username = fromUsername,
                                            r_username = toUsername,
                                            r_type = (int) type,
                                            r_pendingtype = pendingType.HasValue ? (int?) pendingType : null,
                                            r_accepted = accepted,
                                            r_timestamp = timestamp

                                        };
                if (id == 0)
                {
                    db.Relationships.InsertOnSubmit(relationship);
                }
                else
                {
                    db.Relationships.Attach(relationship, true);
                }

                db.SubmitChanges();

                if (id == 0) id = relationship.r_id;
            }
        }