Exemplo n.º 1
0
        public void Create(IntentInputModel inputModel)
        {
            var existIntent = GetByName(inputModel.Name);

            if (existIntent != null)
            {
                throw new SuchIntentNameAlreadyExists();
            }

            var now = DateTime.Now;

            var intent = new Intent
            {
                Name       = inputModel.Name,
                CreateDate = now
            };

            if (inputModel.Sentences != null)
            {
                var sentences = inputModel.Sentences.Select(p => new IntentSentence
                {
                    Text       = p.Text,
                    CreateDate = now,
                    Intent     = intent
                });

                _context.AddRange(sentences);
            }

            _context.Add(intent);
            _context.SaveChanges();
        }
Exemplo n.º 2
0
        public void Edit(IntentInputModel inputModel)
        {
            var intent = Get(inputModel.Id);

            if (intent.Name != inputModel.Name)
            {
                var existIntent = GetByName(inputModel.Name);

                if (existIntent != null)
                {
                    throw new SuchIntentNameAlreadyExists();
                }

                intent.Name = inputModel.Name;
            }

            UpdateSentences(inputModel.Id, inputModel.Sentences);
        }