Exemplo n.º 1
0
        public void TestOneToManySelfReferenced()         // Hierarchy
        {
            ProductType pt1 = new ProductType();

            pt1.Code = ProductType1;
            pt1.Name = ProductType1;
            Assert.IsNull(pt1.EntityRegistry);
            pt1.Save();
            Assert.IsNotNull(pt1.EntityRegistry, "Registry was not created");
            Assert.AreEqual(pt1.GetType().FullName, pt1.EntityRegistry.EntityType.FullName, "Invalid entity type");

            ProductType pt11 = new ProductType();

            pt11.Code   = ProductSubtype11;
            pt11.Parent = pt1;
            pt11.Save();
            Assert.IsNotNull(pt11.EntityRegistry);

            Assert.IsNull(pt1.ProductSubtypes);
            pt1.Refresh();
            Assert.IsNotNull(pt1.ProductSubtypes);

            pt1.ProductSubtypes.Remove(pt11);
            Assert.AreEqual(0, pt1.ProductSubtypes.Count);
            pt1.Save();
            pt11.Delete();
            pt1.Refresh();
            Assert.AreEqual(0, pt1.ProductSubtypes.Count);

            pt1.Delete();

            Assert.IsNull(ProductType.GetByCode(ProductSubtype11));
            Assert.IsNull(ProductType.GetByCode(ProductType1));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Delete([FromUri] int id, [FromBody] int modifiedBy)
        {
            ProductType producttype = new ProductType();

            producttype.ID         = id;
            producttype.Modifiedby = modifiedBy;
            return(Request.CreateResponse(HttpStatusCode.OK, producttype.Delete()));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns>是否成功</returns>
        public override void Delete()
        {
            if (!m_Loaded)
            {
                throw new AppException("尚未初始化");
            }
            bool result = (ProductType.Delete(ProductTypeId) == 1);

            //更新缓存
            if (result && CachedEntityCommander.IsTypeRegistered(typeof(ProductTypeInfo)))
            {
                ResetCache();
            }
            if (!result)
            {
                throw new AppException("删除失败,数据可能被删除");
            }
        }
Exemplo n.º 4
0
        public void TestObjectLifecycle()
        {
            Environment.Log.Info("TestObjectLifecycle");

            ProductType prodType1 = new ProductType();

            prodType1.Code = ProductTypeCode;
            prodType1.Name = "Keyboard";

            Product product1 = new Product();

            product1.RefCode = ProductRef;
            product1.Caption = ProductCaption;
            //product1.Id = 21;

            UnitOfWork uow = new UnitOfWork();

            uow.Save(prodType1);
            uow.Save(product1);
            uow.Commit();

            Assert.IsTrue(prodType1.Id > 0, "ProdType was not saved");
            Assert.IsTrue(product1.Id > 0, "Product was not saved");
            Environment.Log.InfoFormat("2: prodType1.Id: {0}", prodType1.Id);
            Environment.Log.InfoFormat("2: product1.Id: {0}", product1.Id);
            Assert.IsFalse(product1.TypeId.HasValue, "Relation was set");

            product1.TypeId = prodType1.Id;
            product1.Save(true);

            Product product2 = Product.GetById(product1.Id);

            Assert.AreEqual(prodType1.Id, product2.TypeId, "Relation was not set");

            product2.Delete(true);
            Assert.IsNull(Product.GetById(product1.Id), "Product was not deleted");

            prodType1.Delete(true);
            Assert.IsNull(ProductType.GetById(prodType1.Id), "Product type was not deleted");
        }
Exemplo n.º 5
0
 protected override void Page_PreRender(object sender, System.EventArgs e)
 {
     try
         {
             base.Page_PreRender(sender, e);
             Util_CheckAccess();
             mvViews.SetActiveView(vwViewAddEdit);
             switch (this._PageAction)
             {
                 case "addthumbnail":
                     Display_AddThumbnail();
                     break;
                 case "addattribute":
                 case "editattribute":
                     Display_ProductAttribute();
                     break;
                 case "viewproducttype":
                     Display_ViewProductType();
                     break;
                 case "addproducttype":
                     if (Page.IsPostBack)
                     {
                         Process_AddProductType();
                     }
                     else
                     {
                         Display_AddProductType();
                     }
                     break;
                 case "editproducttype":
                     if (Page.IsPostBack)
                     {
                         Process_EditProductType();
                     }
                     else
                     {
                         Display_EditProductType();
                     }
                     break;
                 case "deleteproducttype":
                     _ProductType = new ProductType(m_refContentApi.RequestInformationRef);
                     _ProductType.Delete(Convert.ToInt64(Request.QueryString["id"]));
                     Response.Redirect(_PageName + "?action=viewallproducttypes", false);
                     break;
                 default: // "viewallproducttypes"
                     mvViews.SetActiveView(vwViewAll);
                     if (Page.IsPostBack == false)
                     {
                         Display_ViewAll();
                     }
                     break;
             }
         }
         catch (Exception ex)
         {
             Utilities.ShowError(ex.Message);
         }
 }
Exemplo n.º 6
0
 public static void DelProductType(int productTypeId)
 {
     ProductType.Delete(productTypeId);
 }