コード例 #1
0
        public static Task <TextMoodModel> PatchTextModel(TextMoodModel text)
        {
            var textModelDelta = new Delta <TextMoodModel>();

            textModelDelta.TrySetPropertyValue(nameof(TextMoodModel.Text), text.Text);
            textModelDelta.TrySetPropertyValue(nameof(TextMoodModel.IsDeleted), text.IsDeleted);

            return(PatchTextModel(text.Id, textModelDelta));
        }
コード例 #2
0
        public static Task <TextMoodModel> PatchTextModel(TextMoodModel text)
        {
            return(PerformDatabaseWrite(patchTextModelFunction));

            async Task <TextMoodModel> patchTextModelFunction(DatabaseContext context)
            {
                var textFromDatabase = await GetTextModel(text.Id).ConfigureAwait(false);

                textFromDatabase.Id             = text.Id;
                textFromDatabase.SentimentScore = text.SentimentScore;
                textFromDatabase.IsDeleted      = text.IsDeleted;

                textFromDatabase.UpdatedAt = DateTimeOffset.UtcNow;

                context.Update(textFromDatabase);

                return(textFromDatabase);
            }
        }
コード例 #3
0
        public static Task <TextMoodModel> InsertTextModel(TextMoodModel text)
        {
            return(PerformDatabaseWrite(insertTextModelFunction));

            async Task <TextMoodModel> insertTextModelFunction(DatabaseContext context)
            {
                if (string.IsNullOrWhiteSpace(text.Id))
                {
                    text.Id = Guid.NewGuid().ToString();
                }

                text.CreatedAt = DateTimeOffset.UtcNow;
                text.UpdatedAt = DateTimeOffset.UtcNow;

                await context.AddAsync(text).ConfigureAwait(false);

                return(text);
            }
        }
コード例 #4
0
        public static Task <TextMoodModel> InsertTextModel(TextMoodModel text)
        {
            Func <DataContext, TextMoodModel> insertTextModelFunction = dataContext =>
            {
                if (string.IsNullOrWhiteSpace(text.Id))
                {
                    text.Id = Guid.NewGuid().ToString();
                }

                text.CreatedAt = DateTimeOffset.UtcNow;
                text.UpdatedAt = DateTimeOffset.UtcNow;

                dataContext.GetTable <TextMoodModel>().InsertOnSubmit(text);

                return(text);
            };

            return(PerformDatabaseFunction(insertTextModelFunction));
        }