BrowerBookmariks.Services/NewBookMark/NewBookmarkService.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using BrowerBookmariks.Model;
using BrowerBookmariks.Model.Entitys;
using BrowerBookmariks.Model.Services;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrowerBookmariks.Services.NewBookMark
{
    public class NewBookmarkService : INewBookmarkService
    {
        private readonly MyDbContext _dbContext;
        public NewBookmarkService(MyDbContext dbContext)
        {
            _dbContext = dbContext;
        }
        public async Task<ApiResponse> addNewBookAsync(Newbookmark newbookmark)
        {
            try
            {
                await _dbContext.Newbookmark.AddAsync(newbookmark);
            }
            catch (Exception e)
            {
                await Console.Out.WriteLineAsync(e.Message);
                return new ApiResponse() { Message = e.Message };
            }
            await _dbContext.SaveChangesAsync();
            return new ApiResponse() { Message = "添加成功!" };
        }

        public async Task<ApiResponse> delNewBookAsync(int Id)
        {
            try
            {
                var newbookmark = await _dbContext.Newbookmark.FindAsync(Id);
                if(newbookmark == null)
                {
                    return new ApiResponse() { Message = $"新书签不存在!",StatusCode=201};
                }
                _dbContext.Newbookmark.Remove(newbookmark);
                await _dbContext.SaveChangesAsync();
                return new ApiResponse() { Message = $"删除成功!"};
            }
            catch (Exception ex)
            {
                await Console.Out.WriteLineAsync(ex.Message);
                return new ApiResponse() { Message = $"删除失败!{ex.Message}", StatusCode = 500 };
            }
        }

        public Task<List<Newbookmark>> getAllNewBookmarksAsync(int PathId)
        {
            return _dbContext.Newbookmark.Where(n => n.MenusId == PathId).ToListAsync();
        }
    }
后面还有 1 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。