示例#1
0
        /// <summary>
        /// Creates a new dialog
        /// </summary>
        /// <param name="dialog">Dialog to create</param>
        /// <returns>Created dialog, with filled id</returns>
        public async Task <TaleDialog> CreateDialog(TaleDialog dialog)
        {
            if (string.IsNullOrEmpty(dialog.RelatedObjectId))
            {
                throw new InvalidOperationException("Can not create a new dialog without related object");
            }

            dialog.Id = Guid.NewGuid().ToString();
            await _DialogCollection.InsertOneAsync(dialog);

            return(dialog);
        }
示例#2
0
        /// <summary>
        /// Deletes a dialog
        /// </summary>
        /// <param name="dialog">Dialog</param>
        /// <returns>Task</returns>
        public async Task DeleteDialog(TaleDialog dialog)
        {
            TaleDialog existingDialog = await GetDialogById(dialog.Id);

            if (existingDialog == null)
            {
                throw new NullReferenceException();
            }

            IMongoCollection <TaleDialog> recyclingBin = _Database.GetCollection <TaleDialog>(TaleDialogRecyclingBinCollectionName);
            await recyclingBin.InsertOneAsync(existingDialog);

            DeleteResult result = await _DialogCollection.DeleteOneAsync(p => p.Id == dialog.Id);
        }
示例#3
0
        /// <summary>
        /// Gets a dialog by the related object
        /// </summary>
        /// <param name="relatedObjectId">Related object Id</param>
        /// <returns>Dialog</returns>
        public async Task <TaleDialog> GetDialogByRelatedObjectId(string relatedObjectId)
        {
            TaleDialog dialog = await _DialogCollection.Find(p => p.RelatedObjectId == relatedObjectId).FirstOrDefaultAsync();

            return(dialog);
        }
示例#4
0
        /// <summary>
        /// Gets a dialog by the id
        /// </summary>
        /// <param name="id">Dialog Id</param>
        /// <returns>Dialog</returns>
        public async Task <TaleDialog> GetDialogById(string id)
        {
            TaleDialog dialog = await _DialogCollection.Find(p => p.Id == id).FirstOrDefaultAsync();

            return(dialog);
        }
示例#5
0
 /// <summary>
 /// Updates a dialog
 /// </summary>
 /// <param name="dialog">Dialog</param>
 /// <returns>Task</returns>
 public async Task UpdateDialog(TaleDialog dialog)
 {
     ReplaceOneResult result = await _DialogCollection.ReplaceOneAsync(p => p.Id == dialog.Id, dialog);
 }