首页 > 其他分享 >.NET开源商城CoreShop简记

.NET开源商城CoreShop简记

时间:2024-07-07 10:30:25浏览次数:16  
标签:Entities CoreShop System CoreCms public 简记 using NET Net

.NET开源商城CoreShop简记 大概本地运行起来了,官网 https://www.coreshop.cn/

  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;
            }
        }
    }
}

 

标签:Entities,CoreShop,System,CoreCms,public,简记,using,NET,Net
From: https://www.cnblogs.com/niunan/p/18288253

相关文章

  • NET 中的 12 个简单干净代码技巧
    编写干净的代码对于可维护性、可读性和可扩展性至关重要。这里有12个简单的技巧可以帮助您在.Net中编写更干净的代码,每个技巧都附有好的和坏的代码片段。1.使用有意义的名字糟糕的代码publicclassC{publicvoidM(){vara=10;var......
  • 记一次.NET引用性能分析 - 客户说关联权限后查询不出数据
    背景:有客户说操作员关联权限后,某个页面查询不出数据,不关联权限就可以现象:1、用带权限的账号登进去后,查询不出数据,F12发现报错,"Anerroroccurredwhileexecutingthecommanddefinition.Seetheinnerexceptionfordetails."         2、浏览器......
  • netdot webapi发布centos stream 9 被dos攻击
    前言-刚刚发布一个demo一直被一个叼毛攻击,不停的扫描端口,弄得接口一访问就是503错误99元买了一个2核2g的服务器,1元钱买了一个服务器,有个人一直扫描我的端口安装一个 nginxdnfinstallnginx安装完成后启动nginx服务#启动systemctlstartnginx#设置开机自启动sys......
  • EtherCAT转Profinet网关配置说明第二讲:上位机软件配置
    EtherCAT协议转Profinet协议网关模块(XD-ECPNS20),不仅可以实现数据之间的通信,还可以实现不同系统之间的数据共享。EtherCAT协议转Profinet协议网关模块(XD-ECPNS20)具有高速传输的特点,因此通过EtherCAT转Profinet网关实现数据传输和控制时速度的提升。在大规模的工业自动化生产过程中,......
  • EtherCAT转Profinet网关配置说明第一讲:配置软件安装及介绍
     网关XD-ECPNS20为EtherCAT转Profinet协议网关,使EtherCAT协议和Profinet协议两种工业实时以太网网络之间双向传输IO数据。适用于具有EtherCAT协议网络与Profinet协议网络跨越网络界限进行数据交换的解决方案。本网关通过上位机来进行配置。首先安装上位机软件一、上位机......
  • 昇思25天学习打卡营第11天|ResNet50图像分类
    文章目录昇思MindSpore应用实践基于MindSpore的ResNet50图像分类1、ResNet50简介2、数据集预处理及可视化3、构建网络构建BuildingBlock构建BottleneckBlock构建ResNet50网络4、模型训练5、图像分类模型推理Reference昇思MindSpore应用实践本系列文章主......
  • Kubernetes——Helm(二)
    我们已经知道了如何将信息传到模板中。但是传入的信息并不能被修改。有时我们希望以一种更有用的方式来转换所提供的数据。一、函数初体验quote函数:把.Values对象中的字符串属性用引号引起来,然后放到模板中。apiVersion:v1kind:ConfigMapmetadata:name:{{.Rele......
  • 主干网络篇 | YOLOv5/v7 更换主干网络之 ShuffleNetv2 | 高效CNN架构设计的实用指南(2)
    主干网络篇|YOLOv5/v7更换主干网络之ShuffleNetv2|高效CNN架构设计的实用指南概述YOLOv5和YOLOv7是目前主流的轻量级目标检测模型,在速度和精度方面取得了良好的平衡。然而,传统的YOLOv5/v7模型使用FPN和CSPNet等结构作为主干网络,在移动设备和嵌入式系统等资源受限的场景......
  • Kubernetes client-go源码走读
    Informer机制Kubernetes使用Informer代替Controller去访问APIServer,Controller的所有操作都和Informer进行交互,而Informer并不会每次都去访问APIServer。Informer使用ListAndWatch的机制,在Informer首次启动时,会调用LISTAPI获取所有最新版本的资源对象,然后再通过WATCH......
  • Linux容器篇-使用kubeadm搭建一个kubernetes集群
    kubernetes集群架构和组件master节点组件kube-apiserver:KubernetesAPI,集群的统一入口,各组件的协调者,以RESTfulAPI提供接口服务,所有对象资源的增删改查和监听操作都交给APIserver处理后再交给Etcd存储。kube-controller-manager:处理集群中的常规后台事务,一个资源对应......