1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using CZFW.Framework.Interface;
- using CZFW.Framework.Model.Entity;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using CZFW.Framework.Model.ViewModel;
- using System.Linq;
- namespace CZFW.Framework.Logic
- {
- public class CustomerUserPrivilegeLogic : LogicBase<CustomerUserPrivilegeEntity>, ICustomerUserPrivilege
- {
- public ResultModel AddCustomerUserPrivileges(IList<CustomerUserPrivilegeEntity> customerUserPrivileges)
- {
- var res = AddEntities(customerUserPrivileges);
- return res;
- }
- public IList<CustomerUserPrivilegeModel> GetCustomerUserPrivileges(int userId)
- {
- var res = Queryable.Where(x => x.UserId == userId).Select(x => new CustomerUserPrivilegeModel
- {
- DataId = x.DataId,
- DataLevel = x.DataLevel,
- UserId = x.UserId,
- EntId = x.EntId,
- Id = x.Id,
- OriginalId = x.OriginalId,
- SortOrder = x.SortOrder ?? 0
- }).ToList();
- return res;
- }
- public ResultModel RevokeCustomerUserPrivilegesByIds(IList<int> customerUserPriviligeIds)
- {
- var res = RemoveEntities(x => customerUserPriviligeIds.Contains(x.Id));
- return res;
- }
- public ResultModel RevokeCustomerUserPrivileges( int userId, int entId, IList<CustomerUserPrivilegeEntity> customerUserPrivileges)
- {
- var ids = new List<int>();
- var tp1 = Queryable.Where(x => x.UserId == userId && x.EntId == entId).ToList();
- customerUserPrivileges.ForEach(x=> {
- var id = tp1.Where(y => y.DataId == x.DataId && y.DataLevel == x.DataLevel).SingleOrDefault()?.Id;
- ids.Add(id??0);
- });
- var res = RevokeCustomerUserPrivilegesByIds(ids);
- return res;
- }
- public (bool result, string message) Validate(CustomerUserPrivilegeEntity entity)
- {
- var any = Queryable.Any(x => x.UserId == entity.UserId && x.DataId == entity.DataId && x.DataLevel == entity.DataLevel);
- return (!any, any ? "已经存在" : null);
- }
- }
- }
|