public Stream Refuse(string VisitorID, string InviterID) { if (string.IsNullOrEmpty(VisitorID) || string.IsNullOrEmpty(VisitorID)) { return(ResponseHelper.Failure("VisitorID或InviterID信息不完全!")); } try { var groups = EFHelper.GetAll <Group>().Where(t => t.VisitorID == VisitorID); if (groups.Count() == 0) { return(ResponseHelper.Failure("该游客没有邀请记录!")); } var query = groups.Where(t => t.InviterID == InviterID); if (query.Count() == 0) { return(ResponseHelper.Failure("没有该条邀请记录!")); } EFHelper.Delete(query.Single()); return(ResponseHelper.Success(null)); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } return(ResponseHelper.Failure(ex.Message)); } }
public Status DeleteStaff(TTransportCompanyStaff staff) { EFHelper <TTransportCompanyStaff> eFHelper = new EFHelper <TTransportCompanyStaff>(); int result = eFHelper.Delete(staff); return(result > 0 ? new Status(true) : new Status(false)); }
public Stream DeleteCards(string CardID) { try { if (EFHelper.Delete(new Card() { CardID = CardID })) { return(ResponseHelper.Success(null)); } else { return(ResponseHelper.Failure("删除失败!")); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } return(ResponseHelper.Failure(ex.Message)); } }
public Status DeleteEnvironment(TTransportationEnvironmentInfo info) { EFHelper <TTransportationEnvironmentInfo> eFHelper = new EFHelper <TTransportationEnvironmentInfo>(); int result = eFHelper.Delete(info); return(result > 0 ? new Status(true) : new Status(false)); }
public Stream Exit(string VisitorID) { if (string.IsNullOrEmpty(VisitorID)) { return(ResponseHelper.Failure("游客ID不能为空!")); } try { var group = EFHelper.GetAll <Group>().Where(t => t.VisitorID == VisitorID && t.InviteeState == 1); if (group.Count() == 0) { return(ResponseHelper.Failure("没有该游客的组队信息!")); } EFHelper.Delete(group.Single()); return(ResponseHelper.Success(null)); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } return(ResponseHelper.Failure(ex.Message)); } }
public Status DeleteWaterQuality(TWaterQualityInfo waterQualityInfo) { this._logger.LogWarning("The server execute DeleteWaterQuality --" + DateTime.Now.ToString()); EFHelper <TWaterQualityInfo> eFHelper = new EFHelper <TWaterQualityInfo>(); int result = eFHelper.Delete(waterQualityInfo); return(result > 0 ? new Status(true) : new Status(false)); }
public Status DeleteStaff(TProductionBaseStaff productionBaseStaff) { this._logger.LogWarning("The server excute DeleteStaff --" + DateTime.Now.ToString()); EFHelper <TProductionBaseStaff> eFHelper = new EFHelper <TProductionBaseStaff>(); int result = eFHelper.Delete(productionBaseStaff); return(result > 0 ? new Status(true) : new Status(false)); }
public Status DeletePlantInfo(TPlantInfo plantInfo) { this._logger.LogWarning("The server execute DeletePlantInfo --" + DateTime.Now.ToString()); EFHelper <TPlantInfo> eFHelper = new EFHelper <TPlantInfo>(); int result = eFHelper.Delete(plantInfo); return(result > 0 ? new Status(true) : new Status(false)); }
public Status DeleteCompanyInfo(TTransportationCompanyInfo transportationCompanyInfo) { this._logger.LogWarning("The server excute DeleteCompanyInfo --" + DateTime.Now.ToString()); EFHelper <TTransportationCompanyInfo> eFHelper = new EFHelper <TTransportationCompanyInfo>(); int result = eFHelper.Delete(transportationCompanyInfo); return(result > 0 ? new Status(true) : new Status(false)); }
public int DeleteCategoryById(string categoryId) { int effect = 0; effect += EFHelper.Delete <pub_CategoryEntity>(x => x.CategoryId == categoryId); effect += EFHelper.Delete <pub_SubCategoryEntity>(x => x.CategoryId == categoryId); return(effect); }
public Status DeleteProduct(TProductNumInfo product) { this._logger.LogWarning("The server excute DeleteProduct --" + DateTime.Now.ToString()); EFHelper <TProductNumInfo> eFHelper = new EFHelper <TProductNumInfo>(); int result = eFHelper.Delete(product); return(result > 0 ? new Status(true) : new Status(false)); }
public Status DeletexCookBook(TCookBook cookBook) { this._logger.LogWarning("The server execute DeleteCookBook Fuction --" + DateTime.Now.ToString()); try { EFHelper <TCookBook> eFHelper = new EFHelper <TCookBook>(); int result = eFHelper.Delete(cookBook); if (result > 0) { Status status = new Status { StatusCode = 200, Message = "删除成功", ReturnTime = DateTime.Now, }; return(status); } else { Status status = new Status { StatusCode = 0, Message = "删除失败", ReturnTime = DateTime.Now, }; return(status); } } catch (Exception ex) { this._logger.LogWarning("the DeleteCookBook Function Exception message:" + ex.Message); Status status = new Status { StatusCode = 0, Message = "删除失败", ReturnTime = DateTime.Now, }; return(status); } }
/// <summary> /// 关系处理 /// </summary> /// <param name="c"></param> /// <param name="entity"></param> private void Relationship(DbContext c, Brand entity, List <int> Suppliers, List <int> Sections) { if (Suppliers != null) { var list = Suppliers.Select(v => new Supplier_Brand() { Supplier_Id = v, Brand_Id = entity.Id }); EFHelper.Delete <Supplier_Brand>(c, v => v.Brand_Id == entity.Id); c.Set <Supplier_Brand>().AddOrUpdate(v => new { v.Supplier_Id, v.Brand_Id }, list.ToArray()); c.SaveChanges(); } else { //删除 关系 EFHelper.Delete <Supplier_Brand>(c, v => v.Brand_Id == entity.Id); } if (Sections != null) { var list = Sections.Select(v => new IMS_SectionBrand() { SectionId = v, BrandId = entity.Id }); EFHelper.Delete <IMS_SectionBrand>(c, v => v.BrandId == entity.Id); c.Set <IMS_SectionBrand>().AddOrUpdate(v => new { v.SectionId, v.BrandId }, list.ToArray()); c.SaveChanges(); //EFHelper.InsertOrUpdate(c, list.ToArray()); } else { EFHelper.Delete <IMS_SectionBrand>(c, v => v.BrandId == entity.Id); } }
public Status DeleteNutritionInfo(int id) { this._logger.LogWarning("The server execute UpdateNutritionInfo Fuction --" + DateTime.Now.ToString()); EFHelper <TNutrientInformation> eFHelper = new EFHelper <TNutrientInformation>(); try { TNutrientInformation result = eFHelper.getList(a => a.Id == id).FirstOrDefault(); if (result == null) { this._logger.LogWarning("This object is null "); throw new Exception(); } else { eFHelper.Delete(result); CookBookStatus status = new CookBookStatus() { StatusCode = 200, Message = "删除成功", ReturnTime = DateTime.Now }; return(status); } } catch (Exception ex) { this._logger.LogWarning("The server execute DeleteNutritionInfo Fuction --" + ex.Message + DateTime.Now.ToString()); CookBookStatus status = new CookBookStatus() { StatusCode = 0, Message = "删除失败", ReturnTime = DateTime.Now }; return(status); } }
/// <summary> /// 关系处理 /// </summary> /// <param name="c"></param> /// <param name="entity"></param> private void Relationship(DbContext c, Section entity, List <int> brandids) { EFHelper.Delete <IMS_SectionBrand>(c, v => v.SectionId == entity.Id); if (brandids != null) { var list = brandids.Select(v => new IMS_SectionBrand() { SectionId = entity.Id, BrandId = v }); c.Set <IMS_SectionBrand>().AddOrUpdate(v => new { v.BrandId, v.SectionId } , list.ToArray()); c.SaveChanges(); //EFHelper.InsertOrUpdate(c, list.ToArray()); } }
//删除订单 public int Delete(OrderItems id) { var de = Od.Delete(id); return(de); }
public int DeleteSubCategoryById(int id) { return(EFHelper.Delete <pub_SubCategoryEntity>(x => x.Id == id)); }
static void Main(string[] args) { using (Homework10Context homework10Context = new Homework10Context()) { homework10Context.Database.Log = c => Console.WriteLine(c); #region 批量操作演示 EFHelper efHelper = new EFHelper(homework10Context); efHelper.Update <Company>(new Company { Name = "yy", CreateTime = DateTime.Now, CreatorId = 1 }, c => c.Id == 1); efHelper.Delete <Company>(c => c.Id > 50 && c.Name.StartsWith("测试")); #endregion var companySet = homework10Context.Company; #region 增 在Comanpy对象中演示 { var company1 = new Company() { Name = "测试增加", CreateTime = DateTime.Now, CreatorId = 1 }; companySet.Add(company1); homework10Context.SaveChanges(); var company2 = new Company() { Name = "测试增加22", CreateTime = DateTime.Now, CreatorId = 2 }; } #endregion #region 改 在Comanpy对象中演示 { #region 修改方法1 { var company1 = companySet.Find(2); if (company1 != null) { company1.Name = "演示修改方法1"; } homework10Context.SaveChanges(); } #endregion #region 修改方法2 { var company1 = new Company() { Name = "演示修改方法2", CreateTime = DateTime.Now, CreatorId = 1, Id = 3 }; homework10Context.Set <Company>().Attach(company1); homework10Context.Entry(company1).State = EntityState.Modified; homework10Context.SaveChanges(); } #endregion #region 修改方法3 { var company1 = companySet.Where(c => c.Id == 2001).FirstOrDefault(); if (company1 != null) { company1.Name = "测试修改2023"; // homework10Context.Set<Company>().Attach(company1); 对DbSet内部数据集修改无需Attach方法 homework10Context.SaveChanges(); } } #endregion } #endregion #region 在Comanpy对象中演示 { #region 除方法1 { var company1 = companySet.Find(4); if (company1 != null) { companySet.Remove(company1); homework10Context.SaveChanges(); } } #endregion #region 除方法2 { var company1 = companySet.Where(c => c.Id == 5).FirstOrDefault(); if (company1 != null) { homework10Context.Entry(company1).State = EntityState.Deleted; homework10Context.SaveChanges(); } } #endregion #region 除方法3 { var company1 = companySet.Where(c => c.Id == 6).FirstOrDefault(); if (company1 != null) { homework10Context.Set <Company>().Attach(company1); homework10Context.Set <Company>().Remove(company1); } homework10Context.SaveChanges(); } #endregion } #endregion #region 查 在Comanpy对象中演示 // var companys = companySet.Where(c => c.Id > 1000); Show(companySet); #endregion } Console.ReadLine(); }
public void DeleteTest() { Assert.AreEqual(EFHelper.Delete <pub_CategoryEntity>(x => x.CategoryName == "随笔"), 1); }
public int DeleteArticleById(int id) { return(EFHelper.Delete <ArticleEntity>(x => x.Id == id)); }
public override void Update(OpcSupplierInfo entity) { Action(c => { using (var trans = new TransactionScope()) { Supplier_Brand[] supplier_brands = null; if (entity.Brands != null && entity.Brands.Count() != 0) { supplier_brands = entity.Brands.Select(v => new Supplier_Brand() { Brand_Id = v.Id, Supplier_Id = entity.Id }).ToArray(); entity.Brands = null; } EFHelper.Update(c, entity); if (supplier_brands == null) { //del EFHelper.Delete <Supplier_Brand>(c, v => v.Supplier_Id == entity.Id); } else { var list = EFHelper.Get <Supplier_Brand>(c, v => v.Supplier_Id == entity.Id).ToList(); if (list.Count == 0) { EFHelper.Inserts <Supplier_Brand>(c, supplier_brands); } else { //1 加的 2 删的 var l_b = list.Select(v => v.Brand_Id); var s_b = supplier_brands.Select(v => v.Brand_Id); var b = s_b.Except(l_b).ToArray(); //新增的, var a = l_b.Except(s_b).ToArray(); //剔除的 if (b.Length > 0) { foreach (var i in b) { EFHelper.Insert <Supplier_Brand>(c, new Supplier_Brand { Brand_Id = i, Supplier_Id = entity.Id }); } } if (a.Length > 0) { foreach (var i in a) { EFHelper.Delete <Supplier_Brand>(c, v => v.Supplier_Id == entity.Id && v.Brand_Id == i); } } } } trans.Complete(); } }); }
public void TestDelete() { var iResult = _EFHelper.Delete <Company>(5); // Assert.AreEqual(iResult, 1); }