Example #1
0
        public async Task <Result <CourseBookmarkDb> > DeleteAsync(CourseBookmarkDb bookmarkDb)
        {
            try
            {
                context.CourseBookmarks.Remove(bookmarkDb);
                await context.SaveChangesAsync().ConfigureAwait(false);

                return(Result <CourseBookmarkDb> .Ok(bookmarkDb));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Result <CourseBookmarkDb> .Fail <CourseBookmarkDb>($"Bookmark not deleted. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return(Result <CourseBookmarkDb> .Fail <CourseBookmarkDb>($"Invalid bookmark. {e.Message}"));
            }
        }
Example #2
0
        public async Task <Result <CourseBookmarkDb> > AddAsync(CourseBookmarkDb bookmarkDb)
        {
            try
            {
                context.CourseBookmarks.Add(bookmarkDb);
                await context.SaveChangesAsync();

                return(Result <CourseBookmarkDb> .Ok(bookmarkDb));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Result <CourseBookmarkDb> .Fail <CourseBookmarkDb>($"Cannot save bookmark. {e.Message}"));
            }
            catch (DbUpdateException e)
            {
                return(Result <CourseBookmarkDb> .Fail <CourseBookmarkDb>($"Cannot save bookmark. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return(Result <CourseBookmarkDb> .Fail <CourseBookmarkDb>($"Invalid bookmark. {e.Message}"));
            }
        }