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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 言午

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