public Task EditUserTpl(EditVUserTplDto input) { var editItem = _utplRepository.Single(x => x.Id == input.UserTplId); editItem.TplIds = input.TplIds; // 插入样品权限 UpdateUserTplSpecimen(input.SpecimenList, input.Id); return(_utplRepository.UpdateAsync(editItem)); }
public List <EditVUserTplDto> SearchUserTpls(string input) { List <V_UserTpl> userTplList = new List <V_UserTpl>(); if (string.IsNullOrEmpty(input)) { userTplList = this._repository.GetAll().ToList(); } else { userTplList = this._repository.GetAll().Where(x => x.UserName.Contains(input) || x.Name.Contains(input)).ToList(); } List <EditVUserTplDto> retList = new List <EditVUserTplDto>(); if (userTplList.Count() > 0) { string tplIds = string.Empty; foreach (var item in userTplList) { if (!string.IsNullOrEmpty(item.TplIds)) { tplIds += "," + item.TplIds; } } List <Template> tplList = new List <Template>(); // 获取所有用户的化验模板 if (!string.IsNullOrEmpty(tplIds)) { string[] tplIdStrList = tplIds.Split(',', StringSplitOptions.RemoveEmptyEntries); int[] tplIdIntList = Array.ConvertAll <string, int>(tplIdStrList, s => int.Parse(s)); tplList = _tplRepository.GetAll().Where(x => tplIdIntList.Contains(x.Id)).ToList(); } // 获取用户模板样品表中的数据 var userIdArray = userTplList.Select(x => x.Id).ToArray(); var userSpecimenList = _uTplSpecimenRepository.GetAll().Where(x => userIdArray.Contains(x.UserId)); foreach (var data in userTplList) { EditVUserTplDto tempVUserTpl = new EditVUserTplDto(); // 生成单个用户的化验模板 if (tplList.Count() > 0 && !string.IsNullOrEmpty(data.TplIds)) { string[] tempStrList = data.TplIds.Split(',', StringSplitOptions.RemoveEmptyEntries); int[] tempIntList = Array.ConvertAll <string, int>(tempStrList, s => int.Parse(s)); var tempTplList = tplList.Where(x => tempIntList.Contains(x.Id)).ToList(); string tplNames = string.Empty; List <TplDto> uTplList = new List <TplDto>(); foreach (var tpl in tempTplList) { uTplList.Add(new TplDto() { Id = tpl.Id, TplName = tpl.TplName + "-" + tpl.OrgName }); tplNames += tpl.TplName + ","; } tempVUserTpl.TplNames = tplNames.TrimEnd(','); tempVUserTpl.TplList = uTplList; } // 生成单个用户的样品信息 var specimenList = userSpecimenList.Where(x => x.UserId == data.Id && !x.IsDeleted).ToList(); List <TplSpecimenDto> specList = new List <TplSpecimenDto>(); if (specimenList.Count > 0) { foreach (var spec in specimenList) { string[] specArray = spec.SpecimenIds.Split(",", StringSplitOptions.RemoveEmptyEntries); List <int> specIdArray = Array.ConvertAll <string, int>(specArray, x => int.Parse(x)).ToList(); TplSpecimenDto tempSpec = new TplSpecimenDto() { TplId = spec.TplId, SpecimenIds = specIdArray }; specList.Add(tempSpec); } } //其它信息 tempVUserTpl.Id = data.Id; tempVUserTpl.UserName = data.UserName; tempVUserTpl.Name = data.Name; tempVUserTpl.Lx = data.Lx; tempVUserTpl.IsDeleted = data.IsDeleted; tempVUserTpl.UserTplId = data.UserTplId; tempVUserTpl.TplIds = data.TplIds; tempVUserTpl.SpecimenList = specList; retList.Add(tempVUserTpl); } } return(retList); }