public async Task <Guid> CreateAsync(IFormFile file, double duration, string type = "wav")
        {
            if (file != null)
            {
                var id = Guid.NewGuid();

                var filename    = $"{id}.wav";
                var path        = Path.Combine(_voicesPath, filename);
                var abstrctPath = Path.Combine(_abstractPath, filename);

                using (var writer = new FileStream(abstrctPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    await file.CopyToAsync(writer);
                }
                await _dbContext.Voices.AddAsync(new Voice
                {
                    CreationTime = DateTime.Now,
                    AudioType    = type,
                    Id           = id,
                    Duration     = duration,
                    SavePath     = path
                });

                await _dbContext.SaveChangesAsync();

                return(id);
            }
            return(Guid.Empty);
        }
Beispiel #2
0
        public async Task <(string groupName, long id)> CreateOrUpdateRecord(string serviceId, string customerId, string title)
        {
            var groupName = $"group_{Guid.NewGuid()}";
            var chat      = await FindFirstAsync(c => c.Owner == serviceId && c.Other == customerId && c.ServiceRecordId.HasValue == false);

            if (chat != null)
            {
                groupName          = chat.GroupName;
                chat.DisplayInList = true;
                chat.Online        = true;
                _dbContext.Update(chat);
            }
            else
            {
                chat = new Chat
                {
                    UpdateTime    = DateTime.Now,
                    Other         = customerId,
                    Owner         = serviceId,
                    Title         = title,
                    GroupName     = groupName,
                    Online        = true,
                    DisplayInList = true
                };
                await _dbContext.Chats.AddAsync(chat);

                await _dbContext.SaveChangesAsync();
            }
            return(groupName, chat.Id);
        }
Beispiel #3
0
        public async Task <FeedbackInfo> AddAsync(FeedbackInfo feedbackInfo)
        {
            var entry = await _context.AddAsync(feedbackInfo);

            await _context.SaveChangesAsync();

            return(entry.Entity);
        }
Beispiel #4
0
        public async Task <bool> AddModular(Modular modular)
        {
            if (!Existed(modular.ModularId))
            {
                await _dbContext.Modulars.AddAsync(modular);

                return(await _dbContext.SaveChangesAsync() > 0);
            }
            return(true);
        }
Beispiel #5
0
        public async Task <string> CreateFlowAsync(KnowledgeMap flow)
        {
            if (_dbContext.KnowledgeMaps.Any(f => f.Identifier == flow.Identifier))
            {
                return($"{flow.Identifier}已存在");
            }

            await _dbContext.KnowledgeMaps.AddAsync(flow).ConfigureAwait(false);

            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

            return(string.Empty);
        }
Beispiel #6
0
        public async Task MarkResolved(Guid id, string intent = null)
        {
            var strategy = _context.Database.CreateExecutionStrategy();
            await strategy.ExecuteInTransactionAsync(async() =>
            {
                var unknow = _context.Unknowns.FirstOrDefault(u => u.Id == id);
                if (unknow != null)
                {
                    unknow.IsResolved            = true;
                    _context.Entry(unknow).State = EntityState.Modified;

                    if (string.IsNullOrEmpty(intent) == false)
                    {
                        await _context.MetadataSet.AddAsync(new Metadata
                        {
                            Intent   = intent,
                            Question = unknow.Content
                        });
                    }

                    await _context.SaveChangesAsync();
                }
            }, async() => await _context.Unknowns.AnyAsync(u => u.Id == id && u.IsResolved));
        }
Beispiel #7
0
        public async Task SetAsync(string key, string value)
        {
            MoMoBotAssert.KeyNotNullOrEmpty(key);
            MoMoBotAssert.ValueNullOrWhiteSpace(value);

            var setting = await _dbContext.Settings.FirstOrDefaultAsync(s => s.Key == key);

            if (setting != null)
            {
                if (setting.ReadOnly == false)
                {
                    setting.Value = value;
                    _dbContext.Settings.Update(setting);
                    await _dbContext.SaveChangesAsync();
                    await GetSettingsFromDBAsync();
                }
            }
        }
Beispiel #8
0
        public async Task <bool> SaveChangesAsync()
        {
            var result = await _dbContext.SaveChangesAsync();

            return(result > 0);
        }
 public async Task <bool> SaveChangesAsync()
 {
     return(await _context.SaveChangesAsync() > 0);
 }