惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
V
Visual Studio Blog
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
B
Blog
I
InfoQ
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
H
Help Net Security
博客园 - Franky
宝玉的分享
宝玉的分享
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家

博客园 - 牛腩

鸿蒙开发DevEco Studio创建hello world项目 SQL Server数据库中用存储过程来取顺序号 cmd命令行下用命令执行SQL脚本到SQL Server数据库中 Blazor项目中建立WebApi NETCORE下用SKIT类库发送微信模板消息 ASP.NET CORE微信支付回调示例代码 nuget离线安装 高德地图API使用(根据地址查经纬度,计算二个坐标之间的距离) ModernWMS - 仓库管理系统简记 windows服务器上用nginx转发到iis中的网站 uniapp中防抖函数debounce的使用 winform中的picturebox控件显示和保存byte[]图片 ASP.NET CORE kindeditor在线编辑器示例(上传多图和插入VIDEO标签) uni app uview新增商品页(无限级分类选择和多图上传) C#获取HTML源码 Ant for Blazor做单个表的增删查改 ASP.NET MVC中使用Autofac依赖注入 NET8下生成二维码 NET 7 中使用Session
.NET开源商城CoreShop简记
牛腩 · 2024-07-07 · via 博客园 - 牛腩

.NET开源商城CoreShop简记

  1. 先附加SQLSERVER库,
  2. 运行redis,
  3. vs打开后项目9.APP下的admin是后台,api是接口,二个项目里的Appsetting.json里的数据库连接字符串和redis的字符串都得改,redis运行时默认密码是空的,然后api的那个跨域也设置为true(取消跨域),运行api项目,再运行admin项目,默认用户名密码都是coreshop,不出意外的话后台应该就能看到了,
  4. 用hbuilder打开项目文件夹uniapp下的coreshop文件夹,改D:\workspace\CoreShop-v1.5.5\CoreCms.Net.Uni-App\CoreShop\common\setting\constVarsHelper.js文件里的baseurl为之前API的地址,如:export const apiBaseUrl = 'http://localhost:2015';,再在浏览器中运行,不出意外的话应该是可以看到了,自己测试过小程序,结果在小程序上运行不起来,不知道怎么回事。。算了。。先不管了。。
  5. 后台用的 layuiadmin ,在D:\workspace\CoreShop-v1.5.5\CoreCms.Net.Web.Admin\wwwroot\lib\layuiAdmin\config.js里看相关的配置的,默认视图是在wwwroot下的views下,在VS中创建文件 D:\workspace\CoreShop-v1.5.5\CoreCms.Net.Web.Admin\wwwroot\views\content\article\niunandemo\index.html,内容:
<h1>牛腩测试一下</h1>
<input id="aaa" class="layui-input" />
<button type="button" class="layui-btn" onclick="aaa()">添加数据测试</button>

<script>
    function aaa() {
        layui.use([ 'laydate'],
            function () {
                var $ = layui.$, laydate = layui.laydate;
                laydate.render({
                    elem: '#aaa'
                });
                var url = layui.setter.apiUrl + "Api/NiunanUserInfo/Test";
                var postdata = { username: "niunan", password: "123456" }
                $.get(url, postdata, function (data) {
                    alert("服务端返回:" + JSON.stringify(data));
                });
            });
    }
</script>

6. 接下来做自己的后端接口,流程:数据库中建表 --》2.Entity项目中建立模型 --》4.Repository里建立仓储接口和仓储实现 --》3.Services中建立服务接口和实现 --》9.App 中的CoreCms.Net.Web.Admin项目中建立控制器来实现接口

create table NiunanUserInfo(
 Id int primary key identity,
 CreateTime datetime not null default getdate(),
 UpdateTime datetime not null default getdate(),
 UserName nvarchar(50) not null default ''
)
// CoreCms.Net.Model\Entities\NiunanDemo\NiunanUserInfo.cs
using SqlSugar;
using System.ComponentModel.DataAnnotations;

namespace CoreCms.Net.Model.Entities
{
    /// <summary>
    /// 牛腩自己建的用户表
    /// </summary>
    [SugarTable("NiunanUserInfo", TableDescription = "牛腩用户表")]
    public partial class NiunanUserInfo
    {
        /// <summary>
        /// 用户表
        /// </summary>
        public NiunanUserInfo()
        {
        }

        /// <summary>
        /// 用户ID
        /// </summary>
        [Display(Name = "用户ID")]
        [SugarColumn(ColumnDescription = "用户ID", IsPrimaryKey = true, IsIdentity = true)]
        [Required(ErrorMessage = "请输入{0}")]
        public System.Int32 Id { get; set; }
 
        /// <summary>
        /// UserName
        /// </summary>
        [Display(Name = "UserName")]
        [SugarColumn(ColumnDescription = "UserName", IsNullable = true)]
        [StringLength(50, ErrorMessage = "【{0}】不能超过{1}字符长度")]
        public System.String UserName { get; set; }
       
        /// <summary>
        /// 创建时间
        /// </summary>
        [Display(Name = "创建时间")]
        [SugarColumn(ColumnDescription = "创建时间", IsNullable = true)]
        public System.DateTime CreateTime { get; set; } = System.DateTime.Now;
        /// <summary>
        /// 更新时间
        /// </summary>
        [Display(Name = "更新时间")]
        [SugarColumn(ColumnDescription = "更新时间", IsNullable = true)]
        public System.DateTime UpdateTime { get; set; }  = System.DateTime.Now;
    }
}
// CoreCms.Net.IRepository\NiunanDemo\INiunanUserInfoRepository.cs
using CoreCms.Net.Model.Entities;

namespace CoreCms.Net.IRepository
{
 
    public interface INiunanUserInfoRepository : IBaseRepository<NiunanUserInfo>
    {
    }
}


// CoreCms.Net.Repository\NiunanDemo\NiunanUserInfoRepository.cs
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;

namespace CoreCms.Net.Repository
{ 
    public class NiunanUserInfoRepository : BaseRepository<NiunanUserInfo>, INiunanUserInfoRepository
    {
        public NiunanUserInfoRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }


    }
}
// CoreCms.Net.IServices\NiunanDemo\INiunanUserInfoServices.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using CoreCms.Net.Model.Entities;

namespace CoreCms.Net.IServices
{ 
    public interface INiunanUserInfoServices  : IBaseServices<NiunanUserInfo>
    {
     
    }
}

// CoreCms.Net.Services\NiunanDemo\NiunanUserInfoServices.cs
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;

namespace CoreCms.Net.Services
{ 
    public class NiunanUserInfoServices : BaseServices<NiunanUserInfo>, INiunanUserInfoServices
    {
        private readonly INiunanUserInfoRepository _dal;
        private readonly IUnitOfWork _unitOfWork;

        public NiunanUserInfoServices(IUnitOfWork unitOfWork, INiunanUserInfoRepository dal)
        {
            _dal = dal;
            BaseDal = dal;
            _unitOfWork = unitOfWork;
        }
    }
}
// CoreCms.Net.Web.Admin\Controllers\NiunanDemo\NiunanUserInfoController.cs
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Web.Admin.Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.ComponentModel;

namespace CoreCms.Net.Web.Admin.Controllers
{
    /// <summary>
    ///     牛腩测试
    /// </summary>
    [Description("牛腩测试")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    [RequiredErrorForAdmin]
    [Authorize(Permissions.Name)]
    public class NiunanUserInfoController : ControllerBase
    {
        private readonly INiunanUserInfoServices _services;

        public NiunanUserInfoController(INiunanUserInfoServices _services)
        {
            this._services = _services;
        }
        [AllowAnonymous]
        [HttpGet]
        public string Test(string username, string password)
        {
            try
            {
                int id = _services.Insert(new NiunanUserInfo()
                {
                    UserName = username,
                });
                return "插入成功,返回的ID是:"+id;
            }
            catch (Exception ex)
            {
                return "出错:" + ex.Message;
            }
        }
    }
}