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

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
月光博客
月光博客
Martin Fowler
Martin Fowler
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog
爱范儿
爱范儿
博客园_首页
Last Week in AI
Last Week in AI
N
Netflix TechBlog - Medium
NISL@THU
NISL@THU
H
Help Net Security
A
Arctic Wolf
K
Kaspersky official blog
Y
Y Combinator Blog
G
GRAHAM CLULEY
T
Threatpost
I
Intezer
Attack and Defense Labs
Attack and Defense Labs
Jina AI
Jina AI
Recent Announcements
Recent Announcements
D
Docker
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
GbyAI
GbyAI
The Hacker News
The Hacker News
C
Cyber Attacks, Cyber Crime and Cyber Security
Help Net Security
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
F
Fortinet All Blogs
S
Security Affairs
Security Archives - TechRepublic
Security Archives - TechRepublic
量子位
AWS News Blog
AWS News Blog
Google DeepMind News
Google DeepMind News
罗磊的独立博客
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Hacker News: Front Page
Security Latest
Security Latest
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
M
MIT News - Artificial intelligence
B
Blog
云风的 BLOG
云风的 BLOG

博客园 - 言午

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