public Status GetAllEnvironmentInfo() { EFHelper <TTransportationEnvironmentInfo> eFHelper = new EFHelper <TTransportationEnvironmentInfo>(); var result = eFHelper.getList(a => true).ToList(); return(result.Count > 0 ? new TransportationEnvironmentInfoStatus(true) { EnvironmentInfos = result } : new Status(false)); }
public Status EnvironmentInfoPages(int pagesize, int pageindex) { EFHelper <TTransportationEnvironmentInfo> eFHelper = new EFHelper <TTransportationEnvironmentInfo>(); var result = eFHelper.getListByPage(a => true, a => a.Id, pagesize, pageindex); return(result != null ? new PageStatus <TTransportationEnvironmentInfo>(true) { PageList = result } : new Status(false)); }
public void ConstructSMSMessagesTest() { var mockContext = new Mock <SMSDb>(); // create an empty history var smsHistoryList = new List <SMSHistory>(); var mockSMSHistorySet = EFHelper.GetQueryableMockDbSet(smsHistoryList); mockContext.Setup(c => c.SMSHistoryRecords).Returns(mockSMSHistorySet.Object); // Setup TemplateFields var mockTemplateFieldSet = EFHelper.GetQueryableMockDbSet(FixtureGenerator.CreateTemplateFields()); mockContext.Setup(c => c.TemplateFields).Returns(mockTemplateFieldSet.Object); mockContext.Setup(m => m.Set <TemplateField>()).Returns(mockTemplateFieldSet.Object); // Set the template var template = new Template(); template.Id = 100; template.Description = "MyTemplate"; template.Name = "MyTemplate"; template.Text = Resources.mockTemplateString; var templateList = new List <Template>() { template }; var mockTemplateSet = EFHelper.GetQueryableMockDbSet(templateList); // I have to use object[] mockTemplateSet.Setup(m => m.Find(It.IsAny <object[]>())).Returns <object[]>(ids => templateList.FirstOrDefault(d => d.Id == (int)ids[0])); //I need to set the Set<Template> Template // because the line dbSet = DbContext.Set<T>(); on the Generic repository fails mockContext.Setup(m => m.Set <Template>()).Returns(mockTemplateSet.Object); mockContext.Setup(c => c.Templates).Returns(mockTemplateSet.Object); var mockICurrentUserService = new Mock <ICurrentUserService>(); mockICurrentUserService.Setup(p => p.GetCurrentUser()).Returns("TestUser"); // Mocking up dbFactory var mockdbFactory = new Mock <DbFactory <SMSDb> >(); mockdbFactory.Setup(m => m.DBContext).Returns(mockContext.Object); IUnitOfWork <SMSDb> UoW = new UnitOfWork <SMSDb>(mockdbFactory.Object, mockICurrentUserService.Object); var target = new SMSServices(UoW); var result = target.ConstructSMSMessages(FixtureGenerator.CreateSMSRecepients(), templateList.First().Id); Assert.IsNotNull(result); }
/// <summary> /// 创建发货单, /// </summary> /// <param name="entity">shipping</param> /// <param name="saleOrderModels">销售单</param> /// <param name="userId">操作人</param> /// <returns></returns> public ShippingOrderModel CreateBySaleOrder(OPC_ShippingSale entity, List <OPC_Sale> saleOrderModels, int userId, string shippingRemark) { return(Func(db => { using (var trans = new TransactionScope()) { entity = EFHelper.Insert(db, entity); if (!String.IsNullOrWhiteSpace(shippingRemark)) { var remark = new OPC_ShippingSaleComment { Content = shippingRemark, CreateDate = DateTime.Now, CreateUser = userId, ShippingCode = String.Empty, ShippingSaleId = entity.Id, UpdateDate = DateTime.Now, UpdateUser = userId, }; EFHelper.Insert(db, remark); } foreach (var saleEntity in saleOrderModels) { //var saleEntity = EFHelper.Find<OPC_Sale>(db, sale.Id); if (saleEntity == null) { throw new SalesOrderException("参数saleordermodels为空"); } //判断必须是入库状态才能生成发货单 if (saleEntity.Status != (int)Domain.Enums.EnumSaleOrderStatus.ShipInStorage) { throw new SalesOrderException(String.Format("请检查销售单状态{0},必须是{1},才能生成发货单。", saleEntity.Status.ToString(), Intime.OPC.Domain.Enums.EnumSaleOrderStatus.ShipInStorage.GetDescription())); } saleEntity.ShippingSaleId = entity.Id; saleEntity.UpdatedUser = userId; saleEntity.UpdatedDate = DateTime.Now; saleEntity.ShippingRemark = shippingRemark ?? String.Empty; saleEntity.Status = entity.ShippingStatus ?? (int)Domain.Enums.EnumSaleOrderStatus.PrintInvoice; saleEntity.ShippingStatus = entity.ShippingStatus ?? (int)Domain.Enums.EnumSaleOrderStatus.PrintInvoice; EFHelper.UpdateEntityFields(db, saleEntity, new List <string> { "Status", "ShippingStatus", "ShippingSaleId", "UpdatedUser", "UpdatedDate", "ShippingRemark" }); } trans.Complete(); } return GetItemModel(entity.Id); })); }
public Status ProductionBaseInfoSearchLikePage(string likeword, int pagesize, int pageindex) { this._logger.LogWarning("The server execute ProductionBaseInfoSearchLikePage --" + DateTime.Now.ToString()); EFHelper <TProductionBaseInfo> eFHelper = new EFHelper <TProductionBaseInfo>(); var result = eFHelper.getListByPage(a => a.Name.Contains(likeword), a => a.Id, pagesize, pageindex); return(result != null ? new PageStatus <TProductionBaseInfo>(true) { PageList = result } : new Status(false)); }
public Store Insert(Store entity) { CheckEntity(entity); using (var db = new YintaiHZhouContext()) { var rst = EFHelper.Insert(db, entity); return(rst); } }
public static List <Article> GetData(BlogSystemContext dataBaseContext, PageInfoViewModel pageInfo, string searchMessage, Guid?articleTypeGuid = null, Guid?articleLabelGuid = null, bool getArticleType = true, bool getArticleLabels = true, bool getText = true) { var efHelper = new EFHelper(dataBaseContext); IQueryable <Article> q; if (articleLabelGuid.HasValue) { q = dataBaseContext.ArticleLabelArticles.Where( o => o.ArticleLabelGuid == articleLabelGuid).Select(o => o.Article); } else { q = dataBaseContext.Articles; } IQueryable <ArticleLabelArticle> m = dataBaseContext.ArticleLabelArticles; m = m.Include(o => o.Article) .Include(o => o.ArticleLabel); q = q.Include(o => o.ArticleType); if (articleTypeGuid.HasValue) { var selectedArticleTypeGuids = ArticleType.GetVirtualTree(dataBaseContext, articleTypeGuid.Value); q = q.Join(selectedArticleTypeGuids, l => l.ArticleType, r => r, (l, r) => l); } // 表单搜索 var searchText = searchMessage?.Trim(); if (!string.IsNullOrEmpty(searchText)) { q = q.Where(o => o.Name.Contains(searchText)); } if (pageInfo != null) { // 在添加条件之后,排序和分页之前获取总记录数 pageInfo.RecordCount = q.Count(); // 排列和数据库分页 q = efHelper.SortAndPage(q, pageInfo); } var articles = q.ToList(); articles.ForEach(o => o.ArticleLabelArticles = m.Where(p => p.Article == o).ToList()); return(articles); }
public Status GetAllStaffs() { this._logger.LogWarning("The server excute GetAllStaffs --" + DateTime.Now.ToString()); EFHelper <TTransportCompanyStaff> eFHelper = new EFHelper <TTransportCompanyStaff>(); var result = eFHelper.getList(a => true).ToList(); return(result.Count > 0 ? new TransportCompanyStaffStatus(true) { Staffs = result } : new Status(false)); }
public Status WareHouseInfoSearchNamePage(string warehousename, int pagesize, int pageindex) { this._logger.LogWarning("The server execute WareHouseInfoPage --" + DateTime.Now.ToString()); EFHelper <TWarehouseInfo> eFHelper = new EFHelper <TWarehouseInfo>(); var result = eFHelper.getListByPage(a => a.Name == warehousename, a => a.Id, pagesize, pageindex); return(result != null ? new PageStatus <TWarehouseInfo>(true) { PageList = result } : new Status(false)); }
public Status StaffSearchPage(string keyword, int pagesize, int pageindex) { this._logger.LogWarning("The server excute StaffSearchPage --" + DateTime.Now.ToString()); EFHelper <TProductionBaseStaff> eFHelper = new EFHelper <TProductionBaseStaff>(); var result = eFHelper.getListByPage(a => a.ProductionBaseName == keyword, a => a.Id, pagesize, pageindex); return(result != null ? new PageStatus <TProductionBaseStaff>(true) { PageList = result } : new Status(false)); }
public Status GetAllProductInfo() { this._logger.LogWarning("The server excute GetAllProductInfo --" + DateTime.Now.ToString()); EFHelper <TProductNumInfo> eFHelper = new EFHelper <TProductNumInfo>(); var result = eFHelper.getList(a => true).ToList(); return(result.Count > 0 ? new ProductNumInfoStatus(true) { Products = result } : new Status(false)); }
public Status ProductInfoBaseSearchPages(int pagesize, int pageindex, string productionbase) { this._logger.LogWarning("The server excute ProductInfoSearchPages --" + DateTime.Now.ToString()); EFHelper <TProductNumInfo> eFHelper = new EFHelper <TProductNumInfo>(); var result = eFHelper.getListByPage(a => a.ProductionBase == productionbase, a => a.Id, pagesize, pageindex); return(result != null ? new PageStatus <TProductNumInfo>(true) { PageList = result } : new Status(false)); }
public Status CompanyInfoSearchNamePage(int pagesize, int pageindex, string keyword) { this._logger.LogWarning("The server excute CompanyInfoSearchNamePage --" + DateTime.Now.ToString()); EFHelper <TTransportationCompanyInfo> eFHelper = new EFHelper <TTransportationCompanyInfo>(); var result = eFHelper.getListByPage(a => a.Name == keyword, a => a.Id, pagesize, pageindex); return(result != null ? new PageStatus <TTransportationCompanyInfo>(true) { PageList = result } : new Status(false)); }
public Status GetWareHouseInfo() { this._logger.LogWarning("The server execute GetWareHouseInfo --" + DateTime.Now.ToString()); EFHelper <TWarehouseInfo> eFHelper = new EFHelper <TWarehouseInfo>(); var result = eFHelper.getList(a => true).ToList(); return(result.Count > 0 ? new WarehouseInfoStatus(true) { Warehouses = result } : new Status(false)); }
public Status UserIdBySearch(int id) { this._logger.LogWarning("The server execute UserIdBySearch --" + DateTime.Now.ToString()); EFHelper <TProductNumInfo> eFHelper = new EFHelper <TProductNumInfo>(); var result = eFHelper.getList(a => a.Id == id).ToList(); return(result.Count > 0 ? new ProductNumInfoStatus(true) { Products = result } : new Status(false)); }
public Status UserIdBySearch(int id) { this._logger.LogWarning("The server execute UserIdBySearch --" + DateTime.Now.ToString()); EFHelper <TTransportCompanyStaff> eFHelper = new EFHelper <TTransportCompanyStaff>(); var result = eFHelper.getList(a => a.Id == id).ToList(); return(result.Count > 0 ? new TransportCompanyStaffStatus(true) { Staffs = result } : new Status(false)); }
/// <summary> /// 审核通过申请 /// </summary> /// <param name="NoticeID">通知ID</param> /// <returns></returns> public Stream PassNotice(string[] NoticeID) { Notice Pass = new Notice(); List <string> result = new List <string>(); foreach (var id in NoticeID) { try { using (var db = new EFDbContext()) { var query = db.Notices.Where(n => n.NoticeID == id); //合法性检查 if (query.Count() == 0) { result.Add(string.Format("编号 {0} 审核失败:未找到此通知!", id)); } if (query.Single().NoticeStatus == 3) { result.Add(string.Format("编号 {0} 审核失败:此通知已失效!", id)); } if (query.Single().NoticeStatus == 2) { result.Add(string.Format("编号 {0} 审核失败:此通知已被拒绝!", id)); } if (query.Single().NoticeStatus == 1) { result.Add(string.Format("编号 {0} 审核失败:此通知已通过审核,无需重复操作!", id)); } //修改通知状态为已通过审核,并记录审核时间 Pass = query.Single(); Pass.NoticeStatus = 1; //通过申请 Pass.CheckTime = DateTime.Now; //记录审核通过的时间 //提交数据库修改 EFHelper.Update <Notice>(Pass); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } result.Add(string.Format("编号 {0} 审核失败:" + ex.Message, id)); } } return(ResponseHelper.Success(result)); }
public void SetApproved(ApplyApprovedRequest request) { var item = GetItem(request.ApplyId); if (item == null) { throw new OpcException(String.Format("申请单{0}未找到", request.ApplyId)); } using (var ts = new TransactionScope()) { using (var db = GetYintaiHZhouContext()) { var approved = request.Approved == 1; var stdField = new List <string> { "Approved", "ApprovedDate", "ApprovedBy", "UpdateDate", "UpdateUser", "Status" }; item.Approved = approved; item.ApprovedDate = DateTime.Now; item.ApprovedBy = request.CurrentUserId; item.UpdateDate = DateTime.Now; item.UpdateUser = request.CurrentUserId ?? 0; item.Status = approved ? InviteCodeRequestStatus.Approved.AsId() : InviteCodeRequestStatus.Reject.AsId(); if (!approved) { item.RejectReason = request.Reason; stdField.Add("RejectReason"); } EFHelper.UpdateEntityFields(db, item, stdField, false); if (approved) { //init InitializeAssociateTables(db, item, request.CurrentUserId ?? 0); } db.SaveChanges(); } ts.Complete(); } }
public NewErrorModel Modify(TechnicalSupport technicalSupport) { try { EFHelper <TechnicalSupport> eFHelper = new EFHelper <TechnicalSupport>(); eFHelper.Modify(technicalSupport); technicalSupport.IsCreateProject = false; if (technicalSupport.IsCreateProject) { using (DDContext context = new DDContext()) { ProjectInfo projectInfo = new ProjectInfo(); projectInfo.ProjectName = technicalSupport.ProjectName; projectInfo.CreateTime = DateTime.Now.ToString("yyyy-dd-mm HH:mm:ss"); projectInfo.IsEnable = true; projectInfo.ProjectState = technicalSupport.ProjectState; projectInfo.DeptName = technicalSupport.DeptName; projectInfo.StartTime = technicalSupport.StartTime; projectInfo.EndTime = technicalSupport.EndTime; projectInfo.CompanyName = technicalSupport.CompanyName; //建立项目文件夹及其子文件 string path = string.Format("\\UploadFile\\ProjectFile\\{0}\\{1}\\{2}", projectInfo.CompanyName, technicalSupport.ProjectType, technicalSupport.ProjectName); projectInfo.FilePath = path; projectInfo.ResponsibleMan = technicalSupport.ResponsibleMan; projectInfo.ResponsibleManId = technicalSupport.ResponsibleManId; projectInfo.TeamMembers = technicalSupport.TeamMembers; projectInfo.TeamMembersId = technicalSupport.TeamMembersId; context.ProjectInfo.Add(projectInfo); context.SaveChanges(); path = System.Web.Hosting.HostingEnvironment.MapPath(path); FileHelper.CreateDirectory(path); } } return(new NewErrorModel() { data = "", error = new Error(0, "修改成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public override int SaveChanges() { try { EFHelper.ApplyAuditRules(this); var saved = base.SaveChanges(); return(saved); } catch (DbUpdateException) { throw; } }
public List <Store> GetPagedList(PagerRequest request, out int totalCount, StoreFilter filter) { var query = Filter(filter); var order = OrderBy(filter.SortOrder ?? StoreSortOrder.Default); using (var db = new YintaiHZhouContext()) { int t; var rst = EFHelper.GetPaged(db, query, out t, request.PageIndex, request.PageSize, order).ToList(); totalCount = t; return(rst); } }
/// <summary> /// 审核拒绝申请 /// </summary> /// <param name="NoticeID">通知ID</param> /// <param name="Remarks">审核备注(可以为空)</param> /// <returns></returns> public Stream RefuseNotice(string NoticeID, string Remarks) { Notice Pass = new Notice(); try { using (var db = new EFDbContext()) { var query = db.Notices.Where(n => n.NoticeID == NoticeID); //合法性检查 if (query.Count() == 0) { return(ResponseHelper.Failure("未找到此通知!")); } if (query.Single().NoticeStatus == 3) { return(ResponseHelper.Failure("此通知已失效!")); } if (query.Single().NoticeStatus == 2) { return(ResponseHelper.Failure("此通知已被拒绝,无需重复操作!")); } if (query.Single().NoticeStatus == 1) { return(ResponseHelper.Failure("此通知已通过审核!")); } //修改通知状态为拒绝并记录审核时间和备注 Pass = query.Single(); Pass.NoticeStatus = 2; //拒绝申请 Pass.CheckTime = DateTime.Now; //记录审核拒绝的时间 Pass.Remarks = Remarks; //记录审核备注 //提交数据库修改 EFHelper.Update <Notice>(Pass); return(ResponseHelper.Success(new List <string>() { "经审核,拒绝发布申请!" })); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } return(ResponseHelper.Failure(ex.Message)); } }
public object ModifyTable([FromBody] Receiving ReceivingList) { try { EFHelper <Receiving> eFHelper = new EFHelper <Receiving>(); Receiving QuaryReceiving = eFHelper.GetListBy(t => t.Id == ReceivingList.Id).First(); QuaryReceiving.Leadership = ReceivingList.Leadership; QuaryReceiving.MainIdea = ReceivingList.MainIdea; QuaryReceiving.Suggestion = ReceivingList.Suggestion; QuaryReceiving.Leadership = ReceivingList.Leadership; if (!string.IsNullOrEmpty(ReceivingList.Review)) { if (string.IsNullOrEmpty(QuaryReceiving.Review)) { QuaryReceiving.Review += ReceivingList.Review; } else { QuaryReceiving.Review += "~" + ReceivingList.Review; } } if (!string.IsNullOrEmpty(ReceivingList.HandleImplementation)) { if (string.IsNullOrEmpty(QuaryReceiving.HandleImplementation)) { QuaryReceiving.HandleImplementation += ReceivingList.HandleImplementation; } else { QuaryReceiving.HandleImplementation += "~" + ReceivingList.HandleImplementation; } } eFHelper.Modify(QuaryReceiving); return(new NewErrorModel() { error = new Error(0, "修改成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public Status GetAllStaff() { this._logger.LogWarning("The server excute GetAllStaff --" + DateTime.Now.ToString()); EFHelper <TProductionBaseStaff> eFHelper = new EFHelper <TProductionBaseStaff>(); var result = eFHelper.getList(a => true).ToList(); return(result.Count > 0 ? new ProductionBaseStaffStatus(true) { Staffs = result } : new ProductionBaseStaffStatus(false) { Staffs = null }); }
public Status PlantInfoPages(int pagesize, int pageindex) { this._logger.LogWarning("The server execute PlantInfoPages --" + DateTime.Now.ToString()); EFHelper <TPlantInfo> eFHelper = new EFHelper <TPlantInfo>(); var result = eFHelper.getListByPage(a => true, a => a.Id, pagesize, pageindex); return(result != null ? new PageStatus <TPlantInfo>(true) { PageList = result } : new PageStatus <TPlantInfo>(false) { PageList = null }); }
public Status UseNameSearchLikePage(int pagesize, int pageindex, string likeword) { this._logger.LogWarning("The server execute UseNameSearchLikePage --" + DateTime.Now.ToString()); EFHelper <TPlantInfo> eFHelper = new EFHelper <TPlantInfo>(); var result = eFHelper.getListByPage(a => a.SeedSource.Contains(likeword), a => a.Id, pagesize, pageindex); return(result != null ? new PageStatus <TPlantInfo>(true) { PageList = result } : new PageStatus <TPlantInfo>(false) { PageList = null }); }
/// <summary> /// /// </summary> /// <param name="db"></param> /// <param name="status"></param> /// <param name="shippingId"></param> /// <param name="userId"></param> private static void SyncStatus(DbContext db, int?status, int shippingId, int userId, OPC_ShippingSale entity) { if (status != null) { var sales = EFHelper.Get <OPC_Sale>(db, v => v.ShippingSaleId == shippingId).ToList(); if (sales.Count == 0) { throw new SaleOrderNotFoundException(String.Format("没有找到发货单id:{0},对应的销售单", shippingId)); } foreach (var s in sales) { //重置状态的 不应大于 打印快递单 //已经发货就不能重新至状态了 if (s.ShippingStatus > (int)Intime.OPC.Domain.Enums.EnumSaleOrderStatus.PrintExpress) { throw new SalesOrderException(String.Format("销售单no:{0},状态{1}、发货单状态是{2},不能再恢复发货单状态{3},或请与管理员联系", s.SaleOrderNo, s.Status, s.ShippingStatus, status)); } s.ShippingStatus = status.Value; s.Status = status.Value; s.UpdatedDate = DateTime.Now; s.UpdatedUser = userId; var fieldList = new List <string> { "Status", "ShippingStatus", "UpdatedDate", "UpdatedUser" }; if (entity != null) { s.ShipViaId = entity.ShipViaId; s.ShippingFee = entity.ShippingFee; s.ShippingCode = entity.ShippingCode; fieldList.AddRange(new List <string> { "ShipViaId", "ShippingFee", "ShippingCode" }); } EFHelper.UpdateEntityFields(db, s, fieldList); } } }
public ActionResult AddTeacherAndStudent() { using (MyDbContext ctx = new MyDbContext()) { Teacher t1 = new Teacher(); t1.Name = "ZhangT"; t1.Students = new List <Student>(); Teacher t2 = new Teacher(); t2.Name = "WangT"; t2.Students = new List <Student>(); Class c1 = new Class(); c1.Name = "Java"; Class c2 = new Class(); c2.Name = "C#"; Student s1 = new Student(); s1.Name = "tom"; s1.Teachers = new List <Teacher>(); s1.Class = c1; Student s2 = new Student(); s2.Name = "jerry"; s2.Teachers = new List <Teacher>(); s2.Class = c2; t1.Students.Add(s1); t1.Students.Add(s2); t2.Students.Add(s2); ctx.Teachers.Add(t1); ctx.Teachers.Add(t2); ctx.Classes.Add(c1); ctx.Classes.Add(c2); ctx.Students.Add(s1); ctx.Students.Add(s2); try { ctx.SaveChanges(); } catch (DbEntityValidationException ex) { EFHelper.LogEFConfigError(ex); } } return(Content("ok")); }
public NewErrorModel Add(Contract contract) { try { using (DDContext context = new DDContext()) { if (context.Roles.Where(r => r.RoleName == "合同管理员" && r.UserId == contract.ApplyManId).ToList().Count > 0) { EFHelper <Contract> eFHelper = new EFHelper <Contract>(); if (eFHelper.Add(contract) == 1) { return(new NewErrorModel() { error = new Error(0, "保存成功!", "") { }, }); } else { return(new NewErrorModel() { error = new Error(1, "保存失败!", "") { }, }); } } else { return(new NewErrorModel() { error = new Error(1, "用户没有权限!", "") { }, }); } } } catch (Exception ex) { return(new NewErrorModel() { error = new Error(2, ex.Message, "") { }, }); } }
public Stream GetAllLocators() { try { return(ResponseHelper.Success(EFHelper.GetAll <Locator>())); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } return(ResponseHelper.Failure(ex.Message)); } }