コード例 #1
0
        public async Task <IConversation> Create(string topic)
        {
            if (string.IsNullOrWhiteSpace(topic))
            {
                return(null);
            }
            DAL.Conversation entity = new DAL.Conversation
            {
                IsActive     = true,
                OpenDateTime = DateTime.UtcNow,
                Topic        = topic
            };
            this._commandContext.Conversations.Add(entity);
            await this._commandContext.SaveChangesAsync();

            var conversation = new Conversation
            {
                ConversationId = entity.ConversationId,
                IsActive       = true,
                OpenDateTime   = entity.OpenDateTime,
                Topic          = topic
            };

            return(conversation);
        }
コード例 #2
0
        public async Task <IConversation> Persist(IConversation conversation)
        {
            if (conversation == null)
            {
                return(null);
            }

            DAL.Conversation entity    = null;
            bool             addEntity = false;

            if (conversation.ConversationId > 0)
            {
                entity = await _queryContext.Conversations.AsNoTracking().Where(d => d.ConversationId == conversation.ConversationId).FirstOrDefaultAsync();
            }
            if (entity == null)
            {
                addEntity = true;
                entity    = new DAL.Conversation
                {
                    OpenDateTime = DateTime.UtcNow,
                    IsActive     = true
                };
            }
            else
            {
                this._commandContext.Conversations.Attach(entity);
            }
            entity.Topic = conversation.Topic;
            if (addEntity)
            {
                this._commandContext.Conversations.Add(entity);
            }
            await this._commandContext.SaveChangesAsync();

            conversation.ConversationId = entity.ConversationId;
            return(conversation);
        }