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

推荐订阅源

量子位
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
N
News | PayPal Newsroom
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
S
Secure Thoughts
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 【当耐特】
博客园 - 聂微东
S
Securelist
宝玉的分享
宝玉的分享
爱范儿
爱范儿
IT之家
IT之家
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
AI
AI
Security Latest
Security Latest
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Last Watchdog
The Last Watchdog
月光博客
月光博客
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
人人都是产品经理
人人都是产品经理
Webroot Blog
Webroot Blog
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
J
Java Code Geeks
N
News and Events Feed by Topic
Recent Commits to openclaw:main
Recent Commits to openclaw:main
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
S
Security Affairs
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
罗磊的独立博客
Spread Privacy
Spread Privacy
Help Net Security
Help Net Security
T
Tailwind CSS Blog
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 言午

Nopcommerce 二次开发2 Admin Nopcommerce 二次开发2 WEB Nopcommerce 二次开发0 sqlce中不支持sp_rename修改表名 C#读取Excel遇到无法读取的解决方法 狼奔代码生成器 银行账户类 累 interface 抽象类 抽象方法 Message 类的继承 多态(虚方法) 事件event 委托 代理 索引! 第五周作业 第四周作业 考试! 线程安全 二 线程安全 一
Nopcommerce 二次开发1 基础
言午 · 2016-10-27 · via 博客园 - 言午

1  Doamin    酒店

namespace Nop.Core.Domain.Hotels
{
    /// <summary>
    /// 酒店
    /// </summary>
    public partial class Hotel : BaseEntity
    {
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 联系电话
        /// </summary>
        public string Telephone { get; set; }
        /// <summary>
        /// 介绍
        /// </summary>
        public string Introduce { get; set; }
        /// <summary>
        /// 星级
        /// </summary>
        public int Level { get; set; }
        
        /// <summary>
        /// Gets or sets the shipping address identifier
        /// </summary>
        public int? AddressId { get; set; }

        /// <summary>
        /// Gets or sets the shipping address
        /// </summary>
        public virtual Address Address { get; set; }
    }
}

2  数据库 表

/****** Object:  Table [dbo].[Hotel]    Script Date: 10/27/2016 09:11:41 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Hotel](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](500) NULL,
    [Telephone] [nvarchar](500) NULL,
    [Introduce] [nvarchar](1000) NULL,
    [Level] [int] NULL,
    [AddressId] [int] NULL,
 CONSTRAINT [PK_Hotel] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

3 Map 

using Nop.Core.Domain.Hotels;

namespace Nop.Data.Mapping.Hotels
{
    public partial class HotelMap : NopEntityTypeConfiguration<Hotel>
    {
        public HotelMap()
        {
            this.ToTable("Hotel");
            this.HasKey(f => f.Id);
            this.Property(f => f.Name).IsRequired().HasMaxLength(200);
             
        }
    }
}

4 Services 层

using System.Collections.Generic;
using Nop.Core;
using Nop.Core.Domain.Hotels;

namespace Nop.Services.Hotels
{
    public partial interface IHotelService
    {
        /// <summary>
        /// Deletes a news
        /// </summary>
        /// <param name="hotel">News item</param>
        void DeleteHotel(Hotel hotel);

       
        Hotel GetHotelById(int hotelId);

       
        IList<Hotel> GetHotelByIds(int[] hotelIds);

       
        IPagedList<Hotel> GetAllHotels( int pageIndex = 0, int pageSize = int.MaxValue, bool showHidden = false);


        void InsertHotel(Hotel hotel);

        void UpdateHotel(Hotel hotel);

    }
}

service

using System;
using System.Collections.Generic;
using System.Linq;
using Nop.Core;
using Nop.Core.Data;
using Nop.Core.Domain.Hotels;
using Nop.Services.Events;

namespace Nop.Services.Hotels
{
    public partial class HotelService : IHotelService
    {
        #region Fields

        private readonly IRepository<Hotel> _hotelRepository;
        private readonly IEventPublisher _eventPublisher;

        #endregion

        #region Ctor
        public HotelService(IRepository<Hotel> hotelRepository, IEventPublisher eventPublisher)
        {
            _hotelRepository = hotelRepository;
            _eventPublisher = eventPublisher;
        }

        #endregion

        public void DeleteHotel(Hotel hotel)
        {
            if (hotel == null)
                throw new ArgumentNullException("hotel");

            _hotelRepository.Delete(hotel);

            //event notification
            _eventPublisher.EntityDeleted(hotel);
        }

        public Hotel GetHotelById(int hotelId)
        {
            if (hotelId == 0)
                return null;

            return _hotelRepository.GetById(hotelId);
        }

        public IList<Hotel> GetHotelByIds(int[] hotelIds)
        {
            var query = _hotelRepository.Table;
            
            return query.Where(p=>hotelIds.Contains(p.Id)).ToList();
        }

        public IPagedList<Hotel> GetAllHotels(int pageIndex = 0, int pageSize = int.MaxValue, bool showHidden = false)
        {
            var query = _hotelRepository.Table;
            var hotels = new PagedList<Hotel>(query, pageIndex, pageSize);
            return hotels;

        }

        public void InsertHotel(Hotel hotel)
        {
            if (hotel == null)
                throw new ArgumentNullException("hotel");

            _hotelRepository.Insert(hotel);

            //event notification
            _eventPublisher.EntityInserted(hotel);
        }

        public void UpdateHotel(Hotel hotel)
        {
            if (hotel == null)
                throw new ArgumentNullException("hotel");

            _hotelRepository.Update(hotel);

            //event notification
            _eventPublisher.EntityUpdated(hotel);
        }
    }
}