public override void Validate() { if (DpType == DpTypeEnum.User) { if (string.IsNullOrEmpty(UserItCode)) { MSD.AddModelError("UserItCode", "用户为必填项"); } else { var user = DC.Set <FrameworkUserBase>().Where(x => x.ITCode == UserItCode).FirstOrDefault(); if (user == null) { MSD.AddModelError("UserItCode", "无法找到账号为" + UserItCode + "的用户"); } else { Entity.UserId = user.ID; } } } else { if (Entity.GroupId == null) { MSD.AddModelError("Entity.GroupId", "用户组为必填项"); } } base.Validate(); }
public virtual async Task DoDeleteAsync() { //如果是PersistPoco,则把IsValid设为false,并不进行物理删除 if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(PersistPoco))) { (Entity as PersistPoco).IsValid = false; (Entity as PersistPoco).UpdateTime = DateTime.Now; (Entity as PersistPoco).UpdateBy = LoginUserInfo?.ITCode; DC.UpdateProperty(Entity, "IsValid"); DC.UpdateProperty(Entity, "UpdateTime"); DC.UpdateProperty(Entity, "UpdateBy"); try { await DC.SaveChangesAsync(); } catch (DbUpdateException) { MSD.AddModelError("", Program._localizer["DeleteFailed"]); } } //如果是普通的TopBasePoco,则进行物理删除 else if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(TopBasePoco))) { DoRealDelete(); } }
/// <summary> /// 物理删除,对于普通的TopBasePoco和Delete操作相同,对于PersistPoco则进行真正的删除。子类如有自定义操作应重载本函数 /// </summary> public virtual void DoRealDelete() { try { DC.DeleteEntity(Entity); DC.SaveChanges(); var pros = typeof(TModel).GetProperties(); //如果包含附件,则先删除附件 var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment)).ToList(); foreach (var f in fa) { if (f.GetValue(Entity) is FileAttachment file) { FileAttachmentVM ofa = new FileAttachmentVM(); ofa.CopyContext(this); ofa.SetEntityById(file.ID); ofa.DoDelete(); } } } catch (Exception e) { MSD.AddModelError("", "数据使用中,无法删除"); } }
/// <summary> /// 物理删除,对于普通的TopBasePoco和Delete操作相同,对于PersistPoco则进行真正的删除。子类如有自定义操作应重载本函数 /// </summary> public virtual void DoRealDelete() { var pros = typeof(TModel).GetProperties(); //如果包含附件,则先删除附件 var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment)).ToList(); foreach (var f in fa) { if (f.GetValue(Entity) is FileAttachment file) { if (file.SaveFileMode == SaveFileModeEnum.Local && !string.IsNullOrEmpty(file.Path)) { Utils.DeleteFile(file.Path); } FileAttachmentData fd = new FileAttachmentData() { ID = file.ID }; DC.DeleteEntity(fd); DC.DeleteEntity(file); } } DC.DeleteEntity(Entity); try { DC.SaveChanges(); } catch (Exception) { MSD.AddModelError("", "数据使用中,无法删除"); } }
/// <summary> /// 进行注册 /// </summary> /// <returns></returns> public bool DoReg() { //检查两次新密码是否输入一致,如不一致则输出错误 if (Password != NewPasswordComfirm) { MSD.AddModelError("NewPasswordComfirm", Localizer["PasswordNotSame"]); return(false); } //检查itcode是否重复 var exist = DC.Set <FrameworkUserBase>().Any(x => x.ITCode.ToLower() == ITCode.ToLower()); if (exist == true) { MSD.AddModelError("ITCode", "账号重复"); return(false); } FrameworkUserBase user = new FrameworkUserBase { ITCode = ITCode, Name = Name, Password = Utils.GetMD5String(Password), IsValid = true, CellPhone = CellPhone, Email = Email }; DC.Set <FrameworkUserBase>().Add(user); DC.SaveChanges(); return(true); }
public override void DoAdd() { using (var transaction = DC.BeginTransaction()) { try { base.DoAdd(); //添加到账记录后解锁任务 var Tasks = DC.Set <VOS_Task>().Where(x => x.PlanId == Entity.Plan_noId); foreach (var task in Tasks) { task.IsLock = true; task.UnlockerId = LoginUserInfo.Id; task.UnlockTime = DateTime.Now; DC.Set <VOS_Task>().Update(task); } DC.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); MSD.AddModelError("123", "添加失败"); } } }
public override void Validate() { if (DpType == DpTypeEnum.User) { if (string.IsNullOrEmpty(UserItCode)) { MSD.AddModelError("UserItCode", Program._localizer["{0}required", Program._localizer["Account"]]); } else { var user = DC.Set <FrameworkUserBase>().Where(x => x.ITCode == UserItCode).FirstOrDefault(); if (user == null) { MSD.AddModelError("UserItCode", Program._localizer["CannotFindUser", UserItCode]); } else { Entity.UserId = user.ID; } } } else { if (Entity.GroupId == null) { MSD.AddModelError("Entity.GroupId", Program._localizer["{0}required", Program._localizer["Group"]]); } } base.Validate(); }
/// <summary> /// 物理删除,对于普通的TopBasePoco和Delete操作相同,对于PersistPoco则进行真正的删除。子类如有自定义操作应重载本函数 /// </summary> public virtual void DoRealDelete() { try { List <Guid> fileids = new List <Guid>(); var pros = typeof(TModel).GetProperties(); //如果包含附件,则先删除附件 var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBasePoco).IsAssignableFrom(x.PropertyType)).ToList(); foreach (var f in fa) { if (f.GetValue(Entity) is FileAttachment file) { fileids.Add(file.ID); } f.SetValue(Entity, null); } DC.DeleteEntity(Entity); DC.SaveChanges(); foreach (var item in fileids) { FileAttachmentVM ofa = new FileAttachmentVM(); ofa.CopyContext(this); ofa.SetEntityById(item); ofa.DoDelete(); } } catch (Exception e) { MSD.AddModelError("", "数据使用中,无法删除"); } }
/// <summary> /// 删除,进行默认的删除操作。子类如有自定义操作应重载本函数 /// </summary> public virtual void DoDelete() { //如果是PersistPoco,则把IsValid设为false,并不进行物理删除 if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(PersistPoco))) { (Entity as PersistPoco).IsValid = false; (Entity as PersistPoco).UpdateTime = DateTime.Now; (Entity as PersistPoco).UpdateBy = LoginUserInfo?.ITCode; DC.UpdateProperty(Entity, "IsValid"); DC.UpdateProperty(Entity, "UpdateTime"); DC.UpdateProperty(Entity, "UpdateBy"); try { DC.SaveChanges(); } catch (DbUpdateException) { MSD.AddModelError("", "数据使用中,无法删除"); } } //如果是普通的TopBasePoco,则进行物理删除 else if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(TopBasePoco))) { DoRealDelete(); } }
public override void Validate() { if (DpType == DpTypeEnum.User) { if (string.IsNullOrEmpty(Entity.UserCode)) { MSD.AddModelError("Entity.UserCode", Localizer["Validate.{0}required", Localizer["_Admin.Account"]]); } else { var user = DC.Set <FrameworkUser>().Where(x => x.ITCode == Entity.UserCode).FirstOrDefault(); if (user == null) { MSD.AddModelError("Entity.UserCode", Localizer["Sys.CannotFindUser", Entity.UserCode]); } } } else { if (string.IsNullOrEmpty(Entity.GroupCode)) { MSD.AddModelError("Entity.GroupId", Localizer["Validate.{0}required", Localizer["_Admin.Group"]]); } } base.Validate(); }
public override void DoAdd() { var Ctt = DC.Set <contract_pop>() .Include("Contract") .Where(r => r.ID == Entity.ContractPopID).FirstOrDefault().Contract; //var MaxCost = DC.Set<contract>().Where(r => r.ID == OrderPop.ContractPop.ContractID).FirstOrDefault().MaxCost; var CurQty = DC.Set <order_pop>() .Include("ContractPop") .Include("ContractPop.Contract") .Where(r => r.ContractPopID == Entity.ContractPopID).Sum(x => x.OrderQty); var Price = DC.Set <contract_pop>() .Include("Contract") .Where(r => r.ID == Entity.ContractPopID).FirstOrDefault().Price; if (Ctt.MaxCost > 0 && (CurQty + Entity.OrderQty) * Price > Ctt.MaxCost) { MSD.AddModelError("OverCost", "合同订货金额超出最大限制"); return; } if (Ctt.StartDate > DateTime.Now.Date && Ctt.EndDate < DateTime.Now.Date) { MSD.AddModelError("OverDate", "已经不再合同订购期内,无法订货"); return; } Entity.Price = Price; base.DoAdd(); }
/// <summary> /// 物理删除,对于普通的TopBasePoco和Delete操作相同,对于PersistPoco则进行真正的删除。子类如有自定义操作应重载本函数 /// </summary> public virtual void DoRealDelete() { try { List <Guid> fileids = new List <Guid>(); var pros = typeof(TModel).GetAllProperties(); //如果包含附件,则先删除附件 var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBasePoco).IsAssignableFrom(x.PropertyType)).ToList(); foreach (var f in fa) { if (f.GetValue(Entity) is FileAttachment file) { fileids.Add(file.ID); } f.SetValue(Entity, null); } var fas = pros.Where(x => typeof(IEnumerable <ISubFile>).IsAssignableFrom(x.PropertyType)).ToList(); foreach (var f in fas) { IEnumerable <ISubFile> subs = f.GetValue(Entity) as IEnumerable <ISubFile>; if (subs == null) { var fullEntity = DC.Set <TModel>().AsQueryable().Include(f.Name).AsNoTracking().CheckID(Entity.ID).FirstOrDefault(); subs = f.GetValue(fullEntity) as IEnumerable <ISubFile>; } if (subs != null) { foreach (var sub in subs) { fileids.Add(sub.FileId); } f.SetValue(Entity, null); } } if (typeof(TModel) != typeof(FileAttachment)) { foreach (var pro in pros) { if (pro.PropertyType.GetTypeInfo().IsSubclassOf(typeof(TopBasePoco))) { pro.SetValue(Entity, null); } } } DC.DeleteEntity(Entity); DC.SaveChanges(); var fp = KnifeVirgo.HttpContext.RequestServices.GetRequiredService <VirgoFileProvider>(); foreach (var item in fileids) { fp.DeleteFile(item.ToString(), DC.ReCreate()); } } catch (Exception) { MSD.AddModelError("", CoreProgram.Callerlocalizer["DeleteFailed"]); } }
/// <summary> /// 进行登录 /// </summary> /// <param name="OutsidePris">外部传递的页面权限</param> /// <returns>登录用户的信息</returns> public LoginUserInfo DoLogin(bool ignorePris = false) { //根据用户名和密码查询用户 var user = DC.Set <MyUser>() .Include(x => x.UserRoles).Include(x => x.UserGroups) .Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid) .SingleOrDefault(); //如果没有找到则输出错误 if (user == null) { MSD.AddModelError("", "登录失败"); return(null); } var roleIDs = user.UserRoles.Select(x => x.RoleId).ToList(); var groupIDs = user.UserGroups.Select(x => x.GroupId).ToList(); var sDictionary = new Dictionary <string, object>(); sDictionary.Add("CompanyId", user.CompanyId); //查找登录用户的数据权限 var dpris = DC.Set <DataPrivilege>() .Where(x => x.UserId == user.ID || (x.GroupId != null && groupIDs.Contains(x.GroupId.Value))) .ToList(); //查找登录用户的公司信息 var company = DC.Set <Company>().Where(x => x.ID == user.CompanyId).SingleOrDefault(); if (company != null) { sDictionary.Add("CompanyCode", company.CompanyCode); } //生成并返回登录用户信息 LoginUserInfo rv = new LoginUserInfo { Id = user.ID, ITCode = user.ITCode, Name = user.Name, PhotoId = user.PhotoId, Roles = DC.Set <FrameworkRole>().Where(x => user.UserRoles.Select(y => y.RoleId).Contains(x.ID)).ToList(), Groups = DC.Set <FrameworkGroup>().Where(x => user.UserGroups.Select(y => y.GroupId).Contains(x.ID)).ToList(), DataPrivileges = dpris, Attributes = sDictionary }; if (ignorePris == false) { //查找登录用户的页面权限 var pris = DC.Set <FunctionPrivilege>() .Where(x => x.UserId == user.ID || (x.RoleId != null && roleIDs.Contains(x.RoleId.Value))) .ToList(); rv.FunctionPrivileges = pris; } return(rv); }
/// <summary> /// 验证数据,默认验证重复数据。子类如需要其他自定义验证,则重载这个函数 /// </summary> /// <returns>验证结果</returns> public override void Validate() { if (ByPassBaseValidation == false) { base.Validate(); //如果msd是BasicMSD,则认为他是手动创建的,也就是说并没有走asp.net core默认的模型验证 //那么手动验证模型 if (KnifeVirgo?.MSD is BasicMSD) { var valContext = new ValidationContext(this.Entity); List <ValidationResult> error = new List <ValidationResult>(); if (!Validator.TryValidateObject(Entity, valContext, error, true)) { foreach (var item in error) { string key = item.MemberNames.FirstOrDefault(); if (MSD.Keys.Contains(key) == false) { MSD.AddModelError($"Entity.{key}", item.ErrorMessage); } } } var list = typeof(TModel).GetAllProperties().Where(x => x.PropertyType.IsListOf <TopBasePoco>()); foreach (var item in list) { var it = item.GetValue(Entity) as IEnumerable; if (it == null) { continue; } var contextset = false; foreach (var e in it) { if (contextset == false) { valContext = new ValidationContext(e); contextset = true; } if (!Validator.TryValidateObject(e, valContext, error, true)) { foreach (var err in error) { string key = err.MemberNames.FirstOrDefault(); if (MSD.Keys.Contains(key) == false) { MSD.AddModelError($"Entity.{item.Name}.{key}", err.ErrorMessage); } } } } } } //验证重复数据 ValidateDuplicateData(); } }
/// <summary> /// 物理删除,对于普通的TopBasePoco和Delete操作相同,对于PersistPoco则进行真正的删除。子类如有自定义操作应重载本函数 /// </summary> public virtual void DoRealDelete() { try { List <Guid> fileids = new List <Guid>(); var pros = typeof(TModel).GetProperties(); //如果包含附件,则先删除附件 var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBasePoco).IsAssignableFrom(x.PropertyType)).ToList(); foreach (var f in fa) { if (f.GetValue(Entity) is FileAttachment file) { fileids.Add(file.ID); } f.SetValue(Entity, null); } var fas = pros.Where(x => typeof(IEnumerable <ISubFile>).IsAssignableFrom(x.PropertyType)).ToList(); foreach (var f in fas) { var subs = f.GetValue(Entity) as IEnumerable <ISubFile>; if (subs != null) { foreach (var sub in subs) { fileids.Add(sub.FileId); } f.SetValue(Entity, null); } } if (typeof(TModel) != typeof(FileAttachment)) { foreach (var pro in pros) { if (pro.PropertyType.GetTypeInfo().IsSubclassOf(typeof(TopBasePoco))) { pro.SetValue(Entity, null); } } } DC.DeleteEntity(Entity); DC.SaveChanges(); foreach (var item in fileids) { FileAttachmentVM ofa = new FileAttachmentVM(); ofa.CopyContext(this); ofa.SetEntityById(item); ofa.DoDelete(); } } catch (Exception) { MSD.AddModelError("", Program._localizer["DeleteFailed"]); } }
public bool DoRecPop() { if (Location == null || Location == Guid.Empty) { MSD.AddModelError("NullLocation", "请选择上架货位"); return(false); } if (RecQty > (Entity.OrderQty - Entity.RecQty)) { MSD.AddModelError("QtyOver", "实收数量不能大于剩余可收货数量"); return(false); } var loc = DC.Set <area_location>().AsNoTracking().Where(r => r.ID == Location.Value).FirstOrDefault(); if (!loc.isMix.Value) { var invs = DC.Set <inventory>().Where(r => r.LocationID == Location.Value); var InInvs = DC.Set <inventoryIn>().Include("OrderPop.ContractPop").Where(r => invs.Select(x => x.ID).Contains(r.InvID)); List <Guid> pops = InInvs.Select(r => r.OrderPop.ContractPop.PopID).ToList(); pops.Add(Entity.ContractPop.PopID); if (pops.Distinct().Count() > 1) { MSD.AddModelError("LocNotMix", "货位不可混放,但当前货位已经有其他货品了"); return(false); } } inventory inv = new inventory { ID = Guid.NewGuid(), LocationID = Location.Value, Stock = RecQty, PutUser = LoginUserInfo.ITCode + " | " + LoginUserInfo.Name, PutTime = DateTime.Now }; inventoryIn InvIn = new inventoryIn { CreateBy = LoginUserInfo.ITCode, CreateTime = DateTime.Now, InvID = inv.ID, OrderPopID = Entity.ID, InQty = RecQty }; DC.AddEntity(inv); DC.AddEntity(InvIn); var OrderPop = DC.Set <order_pop>().Where(r => r.ID == Entity.ID).FirstOrDefault(); OrderPop.Status = OrderPop.RecQty + RecQty == OrderPop.OrderQty ? RecStatus.FINISH : RecStatus.ING; OrderPop.RecQty += RecQty; OrderPop.RecTime = DateTime.Now; OrderPop.RecUser = LoginUserInfo.ITCode + " | " + LoginUserInfo.Name; DC.UpdateEntity(OrderPop); return(DC.SaveChanges() > 0 ? true : false); }
public override void Validate() { if (Entity.IsInside == true && Entity.FolderOnly == false) { var modules = KnifeVirgo.GlobaInfo.AllModule; var test = DC.Set <FrameworkMenu>().Where(x => x.ClassName == this.SelectedModule && (x.MethodName == null || x.MethodName == "Index") && x.ID != Entity.ID).FirstOrDefault(); if (test != null) { MSD.AddModelError(" error", Localizer["ModuleHasSet"]); } } base.Validate(); }
public override void Validate() { if (Entity.IsInside == true && Entity.FolderOnly == false) { var modules = GlobalServices.GetRequiredService <GlobalData>().AllModule; var test = DC.Set <FrameworkMenu>().Where(x => x.ClassName == this.SelectedModule && (x.MethodName == null || x.MethodName == "Index") && x.ID != Entity.ID).FirstOrDefault(); if (test != null) { MSD.AddModelError(" error", Program._localizer["ModuleHasSet"]); } } base.Validate(); }
public override void Validate() { if (Entity.IsInside == true && Entity.FolderOnly == false) { var modules = Wtm.GlobaInfo.AllModule; var test = DC.Set <FrameworkMenu>().Where(x => x.ClassName == this.SelectedModule && string.IsNullOrEmpty(x.MethodName) && x.ID != Entity.ID).FirstOrDefault(); if (test != null) { MSD.AddModelError(" error", Localizer["_Admin.ModuleHasSet"]); } } base.Validate(); }
public override void Validate() { if (Entity.IsInside == true && Entity.FolderOnly == false) { var modules = GlobalServices.GetRequiredService <GlobalData>().AllModule; var test = DC.Set <FrameworkMenu>().Where(x => x.ClassName == this.SelectedModule && string.IsNullOrEmpty(x.MethodName) && x.ID != Entity.ID).FirstOrDefault(); if (test != null) { MSD.AddModelError(" error", "该模块已经配置过了"); } } base.Validate(); }
public override void Validate() { List <ValidationResult> rv = new List <ValidationResult>(); if (DC.Set <FrameworkUser>().Where(x => x.ITCode == LoginUserInfo.ITCode && x.Password == Utils.GetMD5String(OldPassword)).SingleOrDefault() == null) { MSD.AddModelError("OldPassword", Localizer["Login.OldPasswrodWrong"]); } if (NewPassword != NewPasswordComfirm) { MSD.AddModelError("NewPasswordComfirm", Localizer["Login.PasswordNotSame"]); } }
public override void DoDelete() { try { if (Entity.SaveFileMode == SaveFileModeEnum.Local && !string.IsNullOrEmpty(Entity.Path)) { Utils.DeleteFile(Entity.Path); } DC.Database.ExecuteSqlCommand(new RawSqlString($"delete from {DC.GetTableName<FileAttachment>()} where ID='{Entity.ID}'")); } catch (DbUpdateException) { MSD.AddModelError("", "数据被使用,无法删除"); } }
public override void Validate() { var modules = GlobalServices.GetRequiredService <GlobalData>().AllModule; var mainAction = modules.Where(x => x.FullName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName == "Index").SingleOrDefault(); if (mainAction != null) { var test = DC.Set <FrameworkMenu>().Where(x => x.Url == mainAction.Url && x.ID != Entity.ID).FirstOrDefault(); if (test != null) { MSD.AddModelError(" error", "该模块已经配置过了"); } } base.Validate(); }
/// <summary> /// 自定义验证函数,验证原密码是否正确,并验证两次新密码是否输入一致 /// </summary> /// <returns>验证结果</returns> public override void Validate() { List <ValidationResult> rv = new List <ValidationResult>(); //检查原密码是否正确,如不正确则输出错误 if (DC.Set <FrameworkUserBase>().Where(x => x.ITCode == LoginUserInfo.ITCode && x.Password == Utils.GetMD5String(OldPassword)).SingleOrDefault() == null) { MSD.AddModelError("OldPassword", "当前密码错误"); } //检查两次新密码是否输入一致,如不一致则输出错误 if (NewPassword != NewPasswordComfirm) { MSD.AddModelError("NewPasswordComfirm", "两次新密码输入不一致"); } }
/// <summary> /// 物理删除,对于普通的TopBasePoco和Delete操作相同,对于PersistPoco则进行真正的删除。子类如有自定义操作应重载本函数 /// </summary> public virtual void DoRealDelete() { try { List <Guid> fileids = new List <Guid>(); var pros = typeof(TModel).GetProperties(); //如果包含附件,则先删除附件 var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBasePoco).IsAssignableFrom(x.PropertyType)).ToList(); foreach (var f in fa) { if (f.GetValue(Entity) is FileAttachment file) { fileids.Add(file.ID); } f.SetValue(Entity, null); } var fas = pros.Where(x => typeof(IEnumerable <ISubFile>).IsAssignableFrom(x.PropertyType)).ToList(); foreach (var f in fas) { var subs = f.GetValue(Entity) as IEnumerable <ISubFile>; foreach (var sub in subs) { fileids.Add(sub.FileId); } f.SetValue(Entity, null); } using (var newdc = DC.ReCreate()) { TModel m = new TModel(); m.SetPropertyValue("ID", Entity.GetID()); newdc.Set <TModel>().Attach(m); newdc.DeleteEntity(m); newdc.SaveChanges(); } foreach (var item in fileids) { FileAttachmentVM ofa = new FileAttachmentVM(); ofa.CopyContext(this); ofa.SetEntityById(item); ofa.DoDelete(); } } catch (Exception e) { MSD.AddModelError("", "数据使用中,无法删除"); } }
/// <summary> /// 进行登录 /// </summary> /// <param name="ignorePris">外部传递的页面权限</param> /// <returns>登录用户的信息</returns> public LoginUserInfo DoLogin(bool ignorePris = false) { //根据用户名和密码查询用户 var user = DC.Set <FrameworkUserBase>() .Include(x => x.UserRoles).Include(x => x.UserGroups) .Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid) .SingleOrDefault(); //如果没有找到则输出错误 if (user == null) { MSD.AddModelError("", "登录失败"); return(null); } var roleIDs = user.UserRoles.Select(x => x.RoleId).ToList(); var groupIDs = user.UserGroups.Select(x => x.GroupId).ToList(); //查找登录用户的数据权限 var dpris = DC.Set <DataPrivilege>().AsNoTracking() .Where(x => x.UserId == user.ID || (x.GroupId != null && groupIDs.Contains(x.GroupId.Value))) .Distinct() .ToList(); ProcessTreeDp(dpris); //生成并返回登录用户信息 LoginUserInfo rv = new LoginUserInfo { Id = user.ID, ITCode = user.ITCode, Name = user.Name, PhotoId = user.PhotoId, Roles = DC.Set <FrameworkRole>().Where(x => roleIDs.Contains(x.ID)).ToList(), Groups = DC.Set <FrameworkGroup>().Where(x => groupIDs.Contains(x.ID)).ToList(), DataPrivileges = dpris }; if (ignorePris == false) { //查找登录用户的页面权限 var pris = DC.Set <FunctionPrivilege>().AsNoTracking() .Where(x => x.UserId == user.ID || (x.RoleId != null && roleIDs.Contains(x.RoleId.Value))) .Distinct() .ToList(); rv.FunctionPrivileges = pris; } return(rv); }
public override void DoDelete() { try { if (Entity.SaveFileMode == SaveFileModeEnum.Local && !string.IsNullOrEmpty(Entity.Path)) { Utils.DeleteFile(Entity.Path); } FileAttachment del = new FileAttachment { ID = Entity.ID }; DC.Set <FileAttachment>().Attach(del); DC.Set <FileAttachment>().Remove(del); DC.SaveChanges(); } catch (DbUpdateException) { MSD.AddModelError("", Program._localizer["DataCannotDelete"]); } }
public override void Validate() { if (Entity.IsInside == true && Entity.FolderOnly == false) { if (string.IsNullOrEmpty(SelectedModule) == true) { MSD.AddModelError("SelectedModule", Localizer["Validate.{0}required", Localizer["_Admin.Module"]]); } else { var modules = Wtm.GlobaInfo.AllModule; var test = DC.Set <FrameworkMenu>().Where(x => x.Url != null && x.Url.ToLower() == this.Entity.Url.ToLower() && x.ID != Entity.ID).FirstOrDefault(); if (test != null) { MSD.AddModelError(" error", Localizer["_Admin.ModuleHasSet"]); } } } base.Validate(); }
public override void DoAdd() { Entity.UserID = LoginUserInfo.Id; Entity.User = DC.Set <user>().Where(r => r.ID == LoginUserInfo.Id).FirstOrDefault(); int UsedQty = DC.Set <inventoryOut>() .Where(r => r.Inv.Location.Area.DCID == Entity.User.DCID) .Where(r => r.sp.PopID == Entity.PopID).Sum(r => r.sp.AlcQty); int Stock = DC.Set <inventoryIn>() .Where(r => r.Inv.Location.Area.DCID == Entity.User.DCID) .Where(r => r.OrderPop.ContractPop.PopID == Entity.PopID) .Sum(r => r.Inv.Stock); if ((Stock - UsedQty) < Entity.OrderQty) { MSD.AddModelError("OverQty", "最大货订量不可超过" + (Stock - UsedQty).ToString() + "个"); return; } Entity.EnableQty = Stock - UsedQty; base.DoAdd(); }
public LoginUserInfo DoLogin(bool ignorePris = false) { var user = DC.Set <FrameworkUserBase>() .Include(x => x.UserRoles).Include(x => x.UserGroups) .Where(x => x.ITCode.ToLower() == ITCode.ToLower() && x.Password == Utils.GetMD5String(Password) && x.IsValid) .SingleOrDefault(); if (user == null) { MSD.AddModelError("", Localizer["LoginFail"]); return(null); } var roleIDs = user.UserRoles.Select(x => x.RoleId).ToList(); var groupIDs = user.UserGroups.Select(x => x.GroupId).ToList(); var dpris = DC.Set <DataPrivilege>() .Where(x => x.UserId == user.ID || (x.GroupId != null && groupIDs.Contains(x.GroupId.Value))) .Distinct() .ToList(); ProcessTreeDp(dpris); LoginUserInfo rv = new LoginUserInfo { Id = user.ID, ITCode = user.ITCode, Name = user.Name, PhotoId = user.PhotoId, Roles = DC.Set <FrameworkRole>().Where(x => user.UserRoles.Select(y => y.RoleId).Contains(x.ID)).ToList(), Groups = DC.Set <FrameworkGroup>().Where(x => user.UserGroups.Select(y => y.GroupId).Contains(x.ID)).ToList(), DataPrivileges = dpris }; if (ignorePris == false) { var pris = DC.Set <FunctionPrivilege>() .Where(x => x.UserId == user.ID || (x.RoleId != null && roleIDs.Contains(x.RoleId.Value))) .Distinct() .ToList(); rv.FunctionPrivileges = pris; } return(rv); }