/// <summary> /// 模擬預設資料 /// </summary> /// <returns></returns> protected override IdbDao GetDao() { ///預設dao查詢資料 IList <SelectStudentDaoResModel> daoStudentSelectItem = new List <SelectStudentDaoResModel>(); daoStudentSelectItem.Add(new SelectStudentDaoResModel() { id = new Guid(), studentId = "G121550397", studentName = "吳小欣", studentSex = "1", studentBirth = new DateTime(1888, 3, 3), studentAddr = "宜蘭縣" }); IModelResult <IList <SelectStudentDaoResModel> > daoStudentSelectModel = new ModelResult <IList <SelectStudentDaoResModel> >() { ResultData = daoStudentSelectItem }; IdbDao idbDao = Substitute.For <IdbDao>(); idbDao.StudentSelect(this.selectStudentModel).Returns(daoStudentSelectModel); return(idbDao); }
public IModelResult <IndexVM> SelectStudent(IndexVM vm = null) { IModelResult <IndexVM> modelResult; try { doEventLog($"查詢資料:input=>{JsonConvert.SerializeObject(vm)}"); doLog($"查詢資料:input=>{JsonConvert.SerializeObject(vm)}"); selectStudentModel = null; if (vm != null) { selectStudentModel = AutoMapper.Mapper.Map <SelectStudentDaoReqModel>(vm); } dao = GetDao(); IModelResult <IList <SelectStudentDaoResModel> > dbResult = dao.StudentSelect(selectStudentModel); if (dbResult.IsOk) { modelResult = new ModelResult <IndexVM>(); if (dbResult.ResultData.Any()) { modelResult.ResultData = new IndexVM(); modelResult.ResultData.lstStudentInfo = dbResult.ResultData.Select(x => { IndexStudentItem item = AutoMapper.Mapper.Map <IndexStudentItem>(x); return(item); }).ToList(); } else { modelResult.ResultData = new IndexVM(); } } else { modelResult = new ModelResult <IndexVM>(dbResult.ErrorCode.Value) { SystemMessage = dbResult.SystemMessage }; } doEventLog($"查詢結果:input=>{JsonConvert.SerializeObject(vm)},result=>{JsonConvert.SerializeObject(modelResult)}"); doLog($"查詢結果:input=>{JsonConvert.SerializeObject(vm)},result=>{JsonConvert.SerializeObject(modelResult)}"); } catch (Exception ex) { modelResult = new ModelResult <IndexVM>(SystemCodes.Codes.ApplicationError01) { SystemMessage = ex.Message }; } return(modelResult); }
/// <summary> /// 查詢案件(修改用) /// </summary> /// <param name="vm"></param> /// <returns></returns> public IModelResult <SelectEditVM> SelectStudent(string gid) { IModelResult <SelectEditVM> modelResult; try { doEventLog($"查詢資料:input=>{gid}"); doLog($"查詢資料:input=>{gid}"); dao = GetDao(); IModelResult <IList <SelectStudentDaoResModel> > dbResult = dao.StudentSelect(); if (dbResult.IsOk) { modelResult = new ModelResult <SelectEditVM>(); if (dbResult.ResultData.Any()) { IList <SelectStudentDaoResModel> lstDBResult = dbResult.ResultData.Where(x => x.id.ToString().Equals(gid)).ToList(); if (lstDBResult.Any()) { SelectEditVM model = AutoMapper.Mapper.Map <SelectEditVM>(lstDBResult.First()); modelResult.ResultData = model; } else { modelResult = new ModelResult <SelectEditVM>(SystemCodes.Codes.ApplicationError01) { SystemMessage = $"查詢錯誤,無此識別碼{gid}" }; } } } else { modelResult = new ModelResult <SelectEditVM>(dbResult.ErrorCode.Value) { SystemMessage = dbResult.SystemMessage }; } doEventLog($"查詢結果:input=>{gid},result=>{JsonConvert.SerializeObject(modelResult)}"); doLog($"查詢結果:input=>{gid},result=>{JsonConvert.SerializeObject(modelResult)}"); } catch (Exception ex) { modelResult = new ModelResult <SelectEditVM>(SystemCodes.Codes.ApplicationError01) { SystemMessage = ex.Message }; } return(modelResult); }