public void AddAsync() { try { using (DDContext context = new DDContext()) { List <string> RoleNameList = context.Roles.Select(r => r.RoleName).ToList(); foreach (var item in RoleNameList.Distinct()) { context.Role.Add(new Role() { RoleName = item, CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), CreateMan = "超级管理员", CreateManId = "083452125733424957", IsEnable = true, }); context.SaveChanges(); } foreach (var item in context.Role.ToList()) { context.Database.ExecuteSqlCommand($"update roles set roleid={item.Id} where rolename='{item.RoleName}'"); context.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public NewErrorModel StockReduce([FromBody] List <GiftTable> giftTable) { try { using (DDContext context = new DDContext()) { foreach (var gift in giftTable) { Gift gifts = context.Gift.Find(Int32.Parse(gift.GiftNo)); gifts.Stock = (Int32.Parse(gifts.Stock) - Int32.Parse(gift.GiftCount)).ToString(); context.Entry <Gift>(gifts).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } context.SaveChanges(); return(new NewErrorModel() { error = new Error(0, "消减成功", "") { }, }); } } catch (Exception ex) { throw ex; } }
public NewErrorModel ChangeBom([FromBody] List <Purchase> listPurchase) { try { using (DDContext context = new DDContext()) { string TaskId = listPurchase[0].TaskId.ToString(); List <Purchase> purchases = context.Purchase.Where(t => t.TaskId == TaskId).ToList(); context.Purchase.RemoveRange(purchases); context.SaveChanges(); context.Purchase.AddRange(listPurchase); context.SaveChanges(); return(new NewErrorModel() { error = new Error(0, "更新成功!", "") { }, }); } } catch (Exception ex) { return(new NewErrorModel() { error = new Error(2, ex.Message, "") { }, }); } }
public NewErrorModel TableModify(CarTable carTable) { try { using (DDContext context = new DDContext()) { carTable.FactKilometre = carTable.UseKilometres; Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == carTable.TaskId && t.State == 0 && t.IsEnable == 1).FirstOrDefault(); if (tasks.NodeId == 4) { if (!string.IsNullOrEmpty(carTable.OccupyCarId) && !string.IsNullOrEmpty(carTable.FactKilometre)) { CarTable carTableOld = context.CarTable.Find(int.Parse(carTable.OccupyCarId)); carTableOld.FactKilometre = (float.Parse(carTableOld.FactKilometre) - float.Parse(carTable.FactKilometre)).ToString(); context.Entry <CarTable>(carTableOld).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } context.Entry <CarTable>(carTable).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(new NewErrorModel() { error = new Error(0, "修改成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public NewErrorModel Save(Tables tablle) { try { using (DDContext dataContext = new DDContext()) { if (tablle != null) { if (tablle.tableInfos == null || tablle.tableInfos.Count == 0) { return(new NewErrorModel() { error = new Error(1, "表参数格式有误!", "") { }, }); } else { //动态拼接创建表Sql SqlHelper sqlHelper = new SqlHelper(); string strSql = sqlHelper.CreateTable(tablle); int iResult = dataContext.Database.ExecuteSqlCommand(strSql); //记录执行Sql sqlHelper.SaveSqlExe(tablle, strSql, dataContext); dataContext.Tables.Add(tablle); dataContext.SaveChanges(); foreach (var item in tablle.tableInfos) { item.TableID = tablle.ID; } dataContext.TableInfo.AddRange(tablle.tableInfos); dataContext.SaveChanges(); } } else { return(new NewErrorModel() { error = new Error(1, "表参数格式有误!", "") { }, }); } } return(new NewErrorModel() { error = new Error(0, "保存成功!", "") { }, }); } catch (Exception) { throw; } }
public object TableSave(CarTable carTable) { try { using (DDContext context = new DDContext()) { context.CarTable.Add(carTable); context.SaveChanges(); Car car = context.Car.Find(Int32.Parse(carTable.CarId)); //只保留五条最新数据 if (!string.IsNullOrEmpty(car.UseTimes)) { if (car.UseTimes.Split(',').Length < 5) { car.UseTimes = car.UseTimes + "," + carTable.StartTime + "~" + carTable.EndTime; car.UseMan = car.UseMan + "," + carTable.DrivingMan; } else { car.UseTimes = car.UseTimes.Substring(car.UseTimes.IndexOf(','), car.UseTimes.Length - car.UseTimes.IndexOf(',')); car.UseMan = car.UseMan.Substring(car.UseMan.IndexOf(','), car.UseMan.Length - car.UseMan.IndexOf(',')); car.UseTimes = car.UseTimes + "," + carTable.StartTime + "~" + carTable.EndTime; car.UseMan = car.UseMan + "," + carTable.DrivingMan; } } else { car.UseTimes = carTable.StartTime + "-" + carTable.EndTime; car.UseMan = carTable.DrivingMan; } car.OccupyCarId = carTable.CarId; car.FinnalStartTime = carTable.StartTime; car.FinnalEndTime = carTable.EndTime; context.Entry <Car>(car).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(new ErrorModel() { errorCode = 0, errorMessage = "添加成功" }); } catch (Exception ex) { return(new ErrorModel() { errorCode = 1, errorMessage = ex.Message }); } }
public NewErrorModel Save(ProductionOrderTable productionOrderTable) { try { DDContext dDContext = new DDContext(); if (productionOrderTable.ProductionOrderDetails == null || productionOrderTable.ProductionOrderDetails.Count == 0) { return(new NewErrorModel() { error = new Error(1, "ProductionOrderDetail参数有误!", "") { }, }); } else { dDContext.ProductionOrderTable.Add(productionOrderTable); dDContext.ProductionOrderDetail.AddRange(productionOrderTable.ProductionOrderDetails); dDContext.SaveChanges(); } return(new NewErrorModel() { error = new Error(0, "保存成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public NewErrorModel ChangeRemark(ChangeRemark changeRemark) { try { using (DDContext context = new DDContext()) { Tasks tasks = context.Tasks.Find(Int32.Parse(changeRemark.Id)); tasks.Remark = changeRemark.Remark; context.Entry <Tasks>(tasks).State = EntityState.Modified; context.SaveChanges(); } return(new NewErrorModel() { error = new Error(0, "修改成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public object UpdatePDFState(string TaskId, string PDFState) { try { using (DDContext context = new DDContext()) { Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First(); tasks.PdfState = PDFState; context.Entry <Tasks>(tasks).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return(new ErrorModel() { errorCode = 0, errorMessage = "修改成功" }); } } catch (Exception ex) { return(new ErrorModel() { errorCode = 1, errorMessage = ex.Message }); } }
public Object TableSave([FromBody] List <Code> codeList) { try { using (DDContext context = new DDContext()) { foreach (var code in codeList) { context.Code.Add(code); } context.SaveChanges(); return(new ErrorModel { errorCode = 0, errorMessage = "保存成功" }); } } catch (Exception ex) { return(new ErrorModel() { errorCode = 1, errorMessage = ex.Message }); } }
public Object TableModify([FromBody] List <Code> codeList) { try { using (DDContext context = new DDContext()) { foreach (var code in codeList) { context.Entry <Code>(code).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(new ErrorModel { errorCode = 0, errorMessage = "保存成功" }); } } catch (Exception ex) { return(new ErrorModel() { errorCode = 1, errorMessage = ex.Message }); } }
public Object StockModify([FromBody] List <Gift> giftTable) { try { using (DDContext context = new DDContext()) { foreach (var gift in giftTable) { context.Entry <Gift>(gift).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(new NewErrorModel() { error = new Error(0, "修改成功", "") { }, }); } } catch (Exception ex) { throw ex; } }
public object InsertOffice(List <KisOffice> KisOffices) { try { using (DDContext context = new DDContext()) { //context.BulkInsert(KisOffices); //context.BulkSaveChanges(); foreach (var kis in KisOffices) { context.KisOffice.Add(kis); context.SaveChanges(); } } return(new NewErrorModel() { count = KisOffices.Count, data = KisOffices, error = new Error(0, "插入成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public string SavePurchaseTable([FromBody] List <PurchaseTable> purchaseTableList) { try { using (DDContext context = new DDContext()) { foreach (PurchaseTable purchaseTable in purchaseTableList) { context.PurchaseTable.Add(purchaseTable); context.SaveChanges(); } } return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 0, errorMessage = "保存成功" })); } catch (Exception ex) { return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 1, errorMessage = ex.Message })); } }
public string ModifyTable([FromBody] List <OfficeSuppliesPurchase> officeSuppliesPurchaseTableList) { try { using (DDContext context = new DDContext()) { foreach (OfficeSuppliesPurchase officeSuppliesPurchase in officeSuppliesPurchaseTableList) { context.Entry <OfficeSuppliesPurchase>(officeSuppliesPurchase).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 0, errorMessage = "修改成功" })); } catch (Exception ex) { return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 1, errorMessage = ex.Message })); } }
public NewErrorModel ModifyPurchaseTable([FromBody] List <PurchaseTable> purchaseTableList) { try { using (DDContext context = new DDContext()) { foreach (PurchaseTable purchaseTable in purchaseTableList) { context.Entry <PurchaseTable>(purchaseTable).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } return(new NewErrorModel() { error = new Error(0, "修改成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(2, ex.Message, "") { }, }); } }
public NewErrorModel Modify(ProductionOrderTable productionOrderTable) { try { DDContext dDContext = new DDContext(); dDContext.Entry <ProductionOrderTable>(productionOrderTable).State = System.Data.Entity.EntityState.Modified; if (productionOrderTable.ProductionOrderDetails != null && productionOrderTable.ProductionOrderDetails.Count > 0) { foreach (var item in productionOrderTable.ProductionOrderDetails) { dDContext.Entry <ProductionOrderDetail>(item).State = System.Data.Entity.EntityState.Modified; } } dDContext.SaveChanges(); return(new NewErrorModel() { error = new Error(0, "修改成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public object Add(Car car) { try { using (DDContext context = new DDContext()) { if (context.Roles.Where(r => r.RoleName.Contains("车辆管理员") && r.UserId == car.ApplyManId).ToList().Count > 0) { car.FinnalStartTime = DateTime.Now; car.FinnalEndTime = DateTime.Now; context.Car.Add(car); context.SaveChanges(); return(new ErrorModel() { errorCode = 0, errorMessage = "添加成功" }); } else { return(new ErrorModel() { errorCode = 1, errorMessage = "没有权限" }); } } } catch (Exception ex) { throw ex; } }
public object Modify(Car car) { try { using (DDContext context = new DDContext()) { if (context.Roles.Where(r => r.RoleName.Contains("车辆管理员") && r.UserId == car.ApplyManId).ToList().Count > 0 || context.Roles.Where(r => r.RoleName.Contains("超级管理员") && r.UserId == car.ApplyManId).ToList().Count > 0) { context.Entry <Car>(car).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return(new NewErrorModel() { error = new Error(0, "修改成功!", "") { }, }); } else { return(new NewErrorModel() { error = new Error(1, "用户没有权限进行操作!", "") { }, }); } } } catch (Exception ex) { throw ex; } }
public NewErrorModel SavePurchaseTable([FromBody] List <PurchaseTable> purchaseTableList) { try { using (DDContext context = new DDContext()) { foreach (PurchaseTable purchaseTable in purchaseTableList) { context.PurchaseTable.Add(purchaseTable); context.SaveChanges(); } } return(new NewErrorModel() { error = new Error(0, "保存成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(2, ex.Message, "") { }, }); } }
public NewErrorModel ProjectInfoModify(ProjectInfo projectInfo) { try { using (DDContext context = new DDContext()) { ProjectInfo projectInfoQuery = context.ProjectInfo.AsNoTracking().Where(p => p.ProjectId == projectInfo.ProjectId).FirstOrDefault(); if (projectInfoQuery.ProjectName != projectInfo.ProjectName) { //修改项目路径 projectInfo.FilePath = projectInfo.FilePath.Replace(projectInfoQuery.ProjectName, projectInfo.ProjectName); System.IO.Directory.Move(HttpContext.Current.Server.MapPath(projectInfoQuery.FilePath), HttpContext.Current.Server.MapPath(projectInfo.FilePath)); //projectInfoQuery = projectInfo; } context.Entry <ProjectInfo>(projectInfo).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(new NewErrorModel() { error = new Error(0, "修改成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public NewErrorModel CreatepProjectFiles() { DDContext dDContext = new DDContext(); List <ProjectInfo> projectInfoList = dDContext.ProjectInfo.ToList(); //矫正项目路径 foreach (var item in projectInfoList) { item.FilePath = $"\\UploadFile\\ProjectFile\\{item.CompanyName}\\{item.ProjectType}\\{item.ProjectSmallType}\\{item.ProjectName}\\"; dDContext.Entry <ProjectInfo>(item).State = System.Data.Entity.EntityState.Modified; } dDContext.SaveChanges(); List <ProjectInfo> projectInfoListNew = dDContext.ProjectInfo.ToList(); foreach (var item in projectInfoListNew) { AddProjectFile(item.FilePath); } return(new NewErrorModel() { error = new Error(0, "创建成功!", "") { }, }); }
public object DeleteById(int id) { try { EFHelper <NewsAndCases> eFHelper = new EFHelper <NewsAndCases>(); NewsAndCases newsAndCases = new NewsAndCases(); using (DDContext context = new DDContext()) { newsAndCases = context.NewsAndCases.Find(id); context.NewsAndCases.Remove(newsAndCases); context.SaveChanges(); } return(new NewErrorModel() { data = newsAndCases, error = new Error(0, "删除成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public object Add(Car car) { try { using (DDContext context = new DDContext()) { car.FinnalStartTime = DateTime.Now; car.FinnalEndTime = DateTime.Now; context.Car.Add(car); context.SaveChanges(); } return(new ErrorModel() { errorCode = 0, errorMessage = "添加成功" }); } catch (Exception ex) { return(new ErrorModel() { errorCode = 1, errorMessage = ex.Message }); } }
public string ProjectInfoModify(ProjectInfo projectInfo) { try { if (projectInfo != null) { using (DDContext context = new DDContext()) { context.Entry <ProjectInfo>(projectInfo).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 0, errorMessage = "修改成功" })); } else { return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 1, errorMessage = "参数未传递" })); } } catch (Exception ex) { return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 1, errorMessage = ex.Message })); } }
public object Delete(dynamic obj) { try { using (DDContext context = new DDContext()) { var Id = Convert.ToInt32(obj.Id); Car car = context.Car.Find(Id); context.Car.Remove(car); context.SaveChanges(); } return(new ErrorModel() { errorCode = 0, errorMessage = "删除成功" }); } catch (Exception ex) { return(new ErrorModel() { errorCode = 1, errorMessage = ex.Message }); } }
public string SaveTable([FromBody] List <OfficeSuppliesPurchase> officeSuppliesPurchaseTableList) { try { using (DDContext context = new DDContext()) { foreach (OfficeSuppliesPurchase officeSuppliesPurchase in officeSuppliesPurchaseTableList) { context.OfficeSuppliesPurchase.Add(officeSuppliesPurchase); context.SaveChanges(); } } return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 0, errorMessage = "保存成功" })); } catch (Exception ex) { return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 1, errorMessage = ex.Message })); } }
public NewErrorModel SaveTable([FromBody] List <OfficeSupplies> officeSuppliesTableList) { try { using (DDContext context = new DDContext()) { foreach (OfficeSupplies officeSupplies in officeSuppliesTableList) { context.OfficeSupplies.Add(officeSupplies); context.SaveChanges(); } } return(new NewErrorModel() { error = new Error(0, "保存成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public NewErrorModel LoadPurchase([FromBody] List <Purchase> listPurchase) { try { foreach (Purchase item in listPurchase) { using (DDContext context = new DDContext()) { context.Purchase.Add(item); context.SaveChanges(); } } return(new NewErrorModel() { error = new Error(0, "保存成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public NewErrorModel ModifyTable([FromBody] List <OfficeSupplies> officeSuppliesTableList) { try { using (DDContext context = new DDContext()) { foreach (OfficeSupplies officeSupplies in officeSuppliesTableList) { context.Entry <OfficeSupplies>(officeSupplies).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } return(new NewErrorModel() { error = new Error(0, "修改成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }