Exemplo n.º 1
0
        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();
                    }
                }
            }
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        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();
                    }
                }
            }
        }