public void Del() { if (CheckAjax()) { if (CheckRight()) { if (IsPost) { M.ProductBrand brand = new M.ProductBrand() { Id = int.Parse(Request["Id"]) }; DataStatus status; DataSource.Begin(); try { if (M.ProductBrandMapping.DelByBrandId(DataSource, brand.Id) != DataStatus.Success) { throw new Exception(); } if (brand.Delete(DataSource) != DataStatus.Success) { throw new Exception(); } DataSource.Commit(); status = DataStatus.Success; } catch (Exception) { DataSource.Rollback(); status = DataStatus.Failed; } SetResult(status, () => { WritePostLog("DEL"); }); } else { NotFound(); } } } }
protected override bool HasReferences(DataSource ds) { if (ExecuteCount <StoreCategory>(ds, P("ParentId", Id)) > 0) { return(true); } if (ProductBrand.GetCountByCategoryId(ds, Id) > 0) { return(true); } if (Product.GetCountByCategoryId(ds, Id) > 0) { return(true); } if (ProductAttribute.GetCountByCategoryId(ds, Id) > 0) { return(true); } if (OneProduct.GetCountByCategoryId(ds, Id) > 0) { return(true); } return(false); }
public void Add() { if (CheckAjax()) { if (CheckRight()) { if (IsPost) { M.ProductBrand brand = new M.ProductBrand() { Name = Request["Name"], FirstChar = Request["FirstChar"], //CategoryId = int.Parse(Request["CategoryId"]), Logo = Request["Logo"], Recommend = Types.GetBooleanFromString(Request["Recommend"]), SortNum = int.Parse(Request["SortNum"]), Approved = Types.GetBooleanFromString(Request["Approved"]) }; DataStatus status; DataSource.Begin(); try { string[] Categorys = Request["Categorys"].Split(','); if (Categorys.Length > 0) { for (int i = 0; i < Categorys.Length; i++) { M.ProductBrandMapping m = new M.ProductBrandMapping(); m.BrandId = brand.Id; m.CategoryId = int.Parse(Categorys[i]); if (M.ProductBrandMapping.Add(DataSource, m) != DataStatus.Success) { throw new Exception(); } } } if (brand.Insert(DataSource) != DataStatus.Success) { throw new Exception(); } DataSource.Commit(); status = DataStatus.Success; } catch (Exception) { DataSource.Rollback(); status = DataStatus.Failed; } SetResult(status, () => { WritePostLog("ADD"); }); } else { NotFound(); } } } }