123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.TeachingMaterial;
- using EMIS.ViewModel;
- using EMIS.DataLogic.Common.TeachingMaterial;
- using System.Linq.Expressions;
- using EMIS.Entities;
- using Bowin.Common.Linq;
- namespace EMIS.CommonLogic.TeachingMaterial
- {
- public class SupplierDiscountSetServices : BaseServices, ISupplierDiscountSetServices
- {
- public SupplierDiscountSetDAL supplierDiscountSetDAL { get; set; }
- public IGridResultSet<SupplierDiscountSetView> GetSupplierDiscountSetViewGrid(ConfiguretView configuretView, bool? isDefault, int pageIndex, int pageSize)
- {
- Expression<Func<ET_SupplierDiscountSet, bool>> exp = (x => true);
- if (isDefault.HasValue)
- {
- exp = exp.And(x => x.IsDefault == isDefault);
- }
- var query = supplierDiscountSetDAL.GetSupplierDiscountSetGridView(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToGridResultSet<TeachersOrderView>(pageIndex, pageSize);
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.SupplierDiscountSetID);
- var result = query.OrderBy(x => x.SupplierDiscountSetID).ToGridResultSet<SupplierDiscountSetView>(pageIndex, pageSize);
- return result;
- }
- public List<SupplierDiscountSetView> GetSupplierDiscountSetViewList(ConfiguretView configuretView, bool? isDefault, List<Guid?> supplierDiscountSetIDList)
- {
- Expression<Func<ET_SupplierDiscountSet, bool>> exp = (x => true);
- if (isDefault.HasValue)
- {
- exp = exp.And(x => x.IsDefault == isDefault);
- }
- if (supplierDiscountSetIDList != null)
- {
- exp = exp.And(x => supplierDiscountSetIDList.Contains(x.SupplierDiscountSetID));
- }
- var query = supplierDiscountSetDAL.GetSupplierDiscountSetGridView(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToGridResultSet<TeachersOrderView>(pageIndex, pageSize);
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.SupplierDiscountSetID);
- var result = query.OrderBy(x => x.UnitCode).ToList();
- return result;
- }
- public SupplierDiscountSetView GetSupplierDiscountSetView(Guid SupplierDiscountSetID)
- {
- return supplierDiscountSetDAL.GetSupplierDiscountSetGridView(x => x.SupplierDiscountSetID == SupplierDiscountSetID).FirstOrDefault();
- }
- public void SupplierDiscountSetViewEdit(SupplierDiscountSetView supplierDiscountSetView)
- {
- try
- {
- //查询数据库进行验证
- var supplierDiscountSetVerification = supplierDiscountSetDAL.supplierDiscountSetRepository
- .GetSingle(x => x.SupplierDiscountSetID != supplierDiscountSetView.SupplierDiscountSetID
- && x.PublishID == supplierDiscountSetView.PublishID
- && x.Discount == supplierDiscountSetView.Discount);
- if (supplierDiscountSetVerification == null)
- {
- if (supplierDiscountSetView.IsDefault == true)
- {//只允许一个供应商为默认
- List<ET_SupplierDiscountSet> supplierDiscountSetList = supplierDiscountSetDAL.supplierDiscountSetRepository.GetList(x => x.IsDefault == true).ToList();
- foreach (ET_SupplierDiscountSet sdset in supplierDiscountSetList)
- {
- sdset.IsDefault = false;//当新增或修改的供应商为默认时,将数据库中为默认的供应商改为false
- SetModifyStatus(sdset);
- }
- }
- if (supplierDiscountSetView.SupplierDiscountSetID != Guid.Empty)
- {
- var supplierDiscountSet = supplierDiscountSetDAL.supplierDiscountSetRepository
- .GetSingle(x => x.SupplierDiscountSetID == supplierDiscountSetView.SupplierDiscountSetID);
- //修改
- supplierDiscountSet.PublishID = supplierDiscountSetView.PublishID;
- supplierDiscountSet.Discount = supplierDiscountSetView.Discount;
-
- supplierDiscountSet.IsDefault = supplierDiscountSetView.IsDefault;
- SetModifyStatus(supplierDiscountSet);
- }
- else
- {
- //新增
- ET_SupplierDiscountSet supplierDiscountSet = new ET_SupplierDiscountSet();
- supplierDiscountSet.SupplierDiscountSetID = Guid.NewGuid();
- supplierDiscountSet.PublishID = supplierDiscountSetView.PublishID;
- supplierDiscountSet.Discount = supplierDiscountSetView.Discount;
- supplierDiscountSet.IsDefault = supplierDiscountSetView.IsDefault;
- SetNewStatus(supplierDiscountSet);
- UnitOfWork.Add(supplierDiscountSet);
- }
- }
- else
- {
- throw new Exception("已存在相同的供应商折扣率设置,请核查");
- }
- //事务提交
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="graduationCourseIDList"></param>
- /// <returns></returns>
- public void SupplierDiscountSetDelete(IList<Guid?> supplierDiscountSetIDList)
- {
- try
- {
- UnitOfWork.Delete<ET_SupplierDiscountSet>(x => supplierDiscountSetIDList.Contains(x.SupplierDiscountSetID));
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- public decimal? GetDiscountByPublishID(Guid publishID)
- {
- decimal? discount = 1;
- if (supplierDiscountSetDAL.supplierDiscountSetRepository.GetSingle(x => x.PublishID == publishID) != null)
- {
- discount = supplierDiscountSetDAL.supplierDiscountSetRepository.GetSingle(x => x.PublishID == publishID).Discount;
- }
- return discount;
- }
- }
- }
|