MyMongodb/Controllers/UserController.cs

(开头部分) 2KB

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

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyMongodb.Entity;
using MyMongodb.Service;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace MyMongodb.Controllers
{
    public class UserController : Controller
    {
        private static UserService userService = new UserService();

        public IActionResult Index(string search = "")
        {
            Expression<Func<User, bool>> exp = a=>a.UserName!="";
            if (!string.IsNullOrWhiteSpace(search))
            {
                exp = a => a.UserName.Contains(search);
            }
            List<User> list = userService.FindAll(exp);
            return View(list);
        }

        public IActionResult UserAdd()
        {
            return View();
        }

        [HttpPost]
        public ActionResult UserAdd(User model)
        {
            if (model != null)
            {
                if (userService.Add(model))
                {
                    return Json(new { success = true, msg = "新增成功" });
                }
            }
            return Json(new { success = false, msg = "新增失敗" });
        }

        [HttpPost]
        public ActionResult UserDelete(string id)
        {
            if (userService.Delete(id))
            {
                return Json(new { success = true, msg = "刪除成功" });
            }
            return Json(new { success = false, msg = "刪除失敗" });
        }

        [HttpGet]
        public ActionResult UserEdit(string id)
        {
            User model = userService.Get(id);
            return View(model);
        }

后面还有 12 行代码,解锁后查看完整代码

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

AI 解读

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

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