コード例 #1
0
ファイル: DTopic.cs プロジェクト: enviriot/EnviriotSW
        public Task <JSC.JSValue> SetField(string fPath, JSC.JSValue val)
        {
            var ds = new TopicField(this, fPath, val);

            App.PostMsg(ds);
            return(ds.Task);
        }
コード例 #2
0
        public async Task <long> AllocateTopicAsync(string topicReference, IDictionary <string, string> fields)
        {
            using var log = BeginFunction(nameof(CommunicationMicroService), nameof(AllocateTopicAsync), topicReference);
            try
            {
                using var ctx = CreateQuiltContext();

                var dbTopic = await ctx.Topics.Where(r => r.TopicReference == topicReference)
                              .Include(r => r.TopicFields)
                              .FirstOrDefaultAsync().ConfigureAwait(false);

                if (dbTopic == null)
                {
                    dbTopic = new Topic()
                    {
                        TopicReference = topicReference
                    };

                    if (fields != null)
                    {
                        foreach (var key in fields.Keys)
                        {
                            var dbTopicField = new TopicField()
                            {
                                FieldCode  = key,
                                FieldValue = fields[key]
                            };
                            dbTopic.TopicFields.Add(dbTopicField);
                        }
                    }

                    _ = ctx.Topics.Add(dbTopic);

                    _ = await ctx.SaveChangesAsync().ConfigureAwait(false);
                }
                else
                {
                    if (fields != null)
                    {
                        foreach (var key in fields.Keys)
                        {
                            var dbTopicField = dbTopic.TopicFields.Where(r => r.FieldCode == key).FirstOrDefault();
                            if (dbTopicField != null)
                            {
                                dbTopicField.FieldValue = fields[key];
                            }
                            else
                            {
                                dbTopicField = new TopicField()
                                {
                                    FieldCode  = key,
                                    FieldValue = fields[key]
                                };
                                dbTopic.TopicFields.Add(dbTopicField);
                            }
                        }
                    }
                }

                var result = dbTopic.TopicId;

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }