using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.TeachingMaterial; using EMIS.ViewModel.TeachingMaterial; using EMIS.ViewModel; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.Repositories; using EMIS.Entities; namespace EMIS.CommonLogic.TeachingMaterial { public class LibraryServices:BaseServices,ILibraryServices { #region --定义-- public LibraryDAL LibraryDAL { get; set; } public LibraryRepository LibraryRepository { get; set; } public UserRepository UserRepository { get; set; } public CampusRepository CampusRepository { get; set; } #endregion #region 1.0 查询书库信息列表 /// /// 获取书库信息列表 /// /// /// public IGridResultSet GetLibraryViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize) { var query = LibraryDAL.GetLibraryGridView(x => true); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.LibraryName).ToGridResultSet(pageIndex, pageSize); return query.OrderByDescending(x => x.LibraryName).ToGridResultSet(pageIndex, pageSize); } #endregion #region 2.0 编辑保存书库信息 /// /// 编辑书库 /// /// public void EditLibrary(LibraryView libraryView, Guid createUserID) { try { if (this.LibraryRepository.GetList(x => x.LibraryCode == libraryView.LibraryCode && x.LibraryID != libraryView.LibraryID).Count() > 0) { throw new Exception("书库编号已经存在,请重新输入!"); } if (libraryView.LibraryID != null && libraryView.LibraryID != Guid.Empty) { CF_Library library = LibraryRepository.GetSingle(x => x.LibraryID == libraryView.LibraryID); library.LibraryName = libraryView.LibraryName; library.LibraryCode = libraryView.LibraryCode; library.ContectTelNumber = libraryView.ContectTelNumber; library.HeadPeople = libraryView.HeadPeople; library.CampusID = libraryView.CampusID.GetValueOrDefault(); library.ModifyUserID = createUserID; library.ModifyTime = DateTime.Now; LibraryRepository.UnitOfWork.Update(library); LibraryRepository.UnitOfWork.Commit(); } else { CF_Library publish = new CF_Library() { LibraryID = Guid.NewGuid(), CampusID = libraryView.CampusID.GetValueOrDefault(), ContectTelNumber = libraryView.ContectTelNumber, HeadPeople = libraryView.HeadPeople, LibraryCode = libraryView.LibraryCode, LibraryName = libraryView.LibraryName, Desc = libraryView.Desc, CreateTime = DateTime.Now, ModifyTime = DateTime.Now, CreateUserID = createUserID, ModifyUserID = createUserID }; LibraryRepository.UnitOfWork.Add(publish); LibraryRepository.UnitOfWork.Commit(); } } catch (Exception ex) { throw ex; } } #endregion #region 3.0 删除书库信息 /// /// 删除书库信息 /// /// public void DeleteLibrary(List libraryIDs) { try { LibraryRepository.UnitOfWork.Delete(x => libraryIDs.Contains(x.LibraryID)); } catch (Exception ex) { throw ex; } } #endregion #region 4.0 获取书库单位 /// /// 获取书库单位 /// /// public LibraryView GetSingleLibrary(Guid libraryID) { return LibraryDAL.GetSingleLibrary(libraryID); } #endregion #region 5.0 获取书库信息列表导出 /// /// 获取书库息列表导出 /// /// /// public IList GetLibraryViewExcel(ConfiguretView configuretView) { var query = LibraryDAL.GetLibraryGridView(x => true); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.LibraryName).ToList(); return query.OrderByDescending(x => x.LibraryName).ToList(); } #endregion #region 6.0 验证书库编号唯一 public bool IsExistLibraryCode(string libraryCode) { bool IsExist = false; var libraryEnt = LibraryRepository.GetSingle(x => x.LibraryCode == libraryCode); if (libraryEnt != null) { IsExist = true; } return IsExist; } #endregion } }