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

推荐订阅源

博客园_首页
F
Full Disclosure
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
L
LangChain Blog
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
GbyAI
GbyAI
Y
Y Combinator Blog
博客园 - Franky
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
Google Developers Blog
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
Jina AI
Jina AI
N
Netflix TechBlog - Medium
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
腾讯CDC
H
Help Net Security
H
Heimdal Security Blog
J
Java Code Geeks
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
The Exploit Database - CXSecurity.com
The Register - Security
The Register - Security
大猫的无限游戏
大猫的无限游戏
T
Threatpost
B
Blog RSS Feed
T
Threat Research - Cisco Blogs
Microsoft Security Blog
Microsoft Security Blog
S
Securelist
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
量子位
AWS News Blog
AWS News Blog
Project Zero
Project Zero
P
Proofpoint News Feed
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
S
Schneier on Security

博客园 - 言午

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