Nopcommerce 二次开发1 基础

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(,) NOT NULL,
[Name] [nvarchar]() NULL,
[Telephone] [nvarchar]() NULL,
[Introduce] [nvarchar]() 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(); }
}
}

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 = , 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 == )
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 = , 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);
}
}
}
上一篇:通达OA 新旧两种数据库连接方式


下一篇:Linux强制访问控制机制模块分析之mls_type.h