-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zmn
committed
Apr 8, 2017
1 parent
60a3de0
commit b7d4369
Showing
21 changed files
with
913 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Wlog.Library.BLL.Interfaces; | ||
|
||
namespace Wlog.BLL.Entities | ||
{ | ||
|
||
public class DictionaryEntity : IEntityBase | ||
{ | ||
public virtual string Name { get; set; } | ||
public virtual Guid ApplicationId { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Wlog.Library.BLL.Interfaces; | ||
|
||
namespace Wlog.BLL.Entities | ||
{ | ||
public class KeyPairEntity : IEntityBase | ||
{ | ||
public virtual string ItemKey { get; set; } | ||
public virtual string ItemValue { get; set; } | ||
public virtual Guid DictionaryId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using PagedList; | ||
using Wlog.BLL.Entities; | ||
using Wlog.Library.BLL.Classes; | ||
using Wlog.Library.BLL.Reporitories.Interfaces; | ||
|
||
namespace Wlog.Library.BLL.Reporitories | ||
{ | ||
public class DBKeyPairRepository : EntityRepository<KeyPairEntity>, IKeyPairRepository | ||
{ | ||
public DictionaryEntity CreateDictionary(DictionaryEntity d) | ||
{ | ||
using (var op = this.BeginUnitOfWork()) | ||
{ | ||
op.SaveOrUpdate(d); | ||
op.Commit(); | ||
return d; | ||
} | ||
} | ||
|
||
public string GetByKey(Guid dictionaryId, string key) | ||
{ | ||
using (var op = this.BeginUnitOfWork()) | ||
{ | ||
var item = op.Query<KeyPairEntity>().Where(x => x.DictionaryId.CompareTo(dictionaryId) == 0 && x.ItemKey.Equals(key)).FirstOrDefault(); | ||
if (item == null) return null; | ||
return item.ItemValue; | ||
} | ||
} | ||
|
||
public IPagedList<DictionaryEntity> GetDictionaries(Guid applicationId, string dictionaryName, int start, int count) | ||
{ | ||
using (var op = this.BeginUnitOfWork()) | ||
{ | ||
var query = op.Query<DictionaryEntity>(); | ||
if (applicationId != null) | ||
{ | ||
query = query.Where(x => x.ApplicationId == applicationId); | ||
} | ||
|
||
if (dictionaryName != null) | ||
{ | ||
query = query.Where(x => x.Name.Contains(dictionaryName)); | ||
} | ||
|
||
if (start > 0) | ||
{ | ||
query = query.Skip(start); | ||
} | ||
|
||
|
||
int total = query.Count(); | ||
|
||
if (count > 0) | ||
{ | ||
query = query.Take(count); | ||
} | ||
|
||
var items = query.ToList(); | ||
var page = 1; | ||
if (start > 0 && count > 0) | ||
{ | ||
page = (start / count)+1; | ||
} | ||
if (count == 0) count = int.MaxValue; | ||
return new StaticPagedList<DictionaryEntity>(items, page, count, total); | ||
} | ||
} | ||
|
||
public KeyPairEntity Save(Guid dictionaryId, string key, string value) | ||
{ | ||
|
||
|
||
|
||
using (var op = this.BeginUnitOfWork()) | ||
{ | ||
op.BeginTransaction(); | ||
|
||
var kpe = op.Query<KeyPairEntity>().Where(x => x.ItemKey == key && x.DictionaryId == dictionaryId).FirstOrDefault(); | ||
if (kpe == null) | ||
{ | ||
kpe = new KeyPairEntity() | ||
{ | ||
DictionaryId = dictionaryId, | ||
|
||
}; | ||
} | ||
|
||
kpe.ItemKey = key; | ||
kpe.ItemValue = value; | ||
|
||
op.SaveOrUpdate(kpe); | ||
op.Commit(); | ||
return kpe; | ||
} | ||
|
||
} | ||
|
||
public IPagedList<KeyPairEntity> Search(Guid dictionaryId, string key, int start, int count) | ||
{ | ||
using (var op = this.BeginUnitOfWork()) | ||
{ | ||
var query = op.Query<KeyPairEntity>(); | ||
if (dictionaryId != null) | ||
{ | ||
query = query.Where(x => x.DictionaryId == dictionaryId); | ||
} | ||
|
||
if (key != null) | ||
{ | ||
query = query.Where(x => x.ItemKey.Contains(key)); | ||
} | ||
|
||
int total = query.Count(); | ||
|
||
|
||
if (start > 0) | ||
{ | ||
query = query.Skip(start); | ||
} | ||
|
||
|
||
if (count > 0) | ||
{ | ||
query = query.Take(count); | ||
} | ||
|
||
var items = query.ToList(); | ||
var page = 1; | ||
if (start > 0 && count > 0) | ||
{ | ||
page = (start / count) + 1; | ||
} | ||
if (count == 0) count = int.MaxValue; | ||
return new StaticPagedList<KeyPairEntity>(items, page, count, total); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Wlog.Library/BLL/Reporitories/Interfaces/IKeyPairRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using PagedList; | ||
using Wlog.BLL.Entities; | ||
|
||
namespace Wlog.Library.BLL.Reporitories.Interfaces | ||
{ | ||
public interface IKeyPairRepository | ||
{ | ||
string GetByKey(Guid dictionaryId,string key); | ||
|
||
KeyPairEntity GetById(Guid itemId); | ||
|
||
KeyPairEntity Save(Guid dictionaryId, string key, string value); | ||
|
||
|
||
IPagedList<KeyPairEntity> Search(Guid dictionaryId, string key, int start, int count); | ||
|
||
|
||
|
||
IPagedList<DictionaryEntity> GetDictionaries(Guid id, string dictionaryName, int start, int count); | ||
DictionaryEntity CreateDictionary(DictionaryEntity d); | ||
bool Delete(KeyPairEntity value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using NHibernate.Mapping.ByCode; | ||
using NHibernate.Mapping.ByCode.Conformist; | ||
using Wlog.BLL.Entities; | ||
|
||
namespace Wlog.Library.DAL.Nhibernate.Mappings | ||
{ | ||
public class KeyPairMap : ClassMapping<KeyPairEntity> | ||
{ | ||
public KeyPairMap() | ||
{ | ||
Table("wl_keypair"); | ||
//Schema("dbo"); | ||
|
||
Id(x => x.Id, map => { map.Column("KeyPairId"); map.Generator(Generators.Guid); }); | ||
|
||
Property(x => x.DictionaryId, map => { map.UniqueKey("idx_dictuk"); }); | ||
Property(x => x.ItemKey, map=> { map.UniqueKey("idx_dictuk"); }); | ||
Property(x => x.ItemValue); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.