Beispiel #1
0
        public static async Task RemoveProductType(ProductTypeId id)
        {
            var connectionString      = ConnectivityService.GetConnectionString("TEMP");
            var context               = new SplurgeStopDbContext(connectionString);
            var repository            = new ProductTypeRepository(context);
            var unitOfWork            = new EfCoreUnitOfWork(context);
            var service               = new ProductTypeService(repository, unitOfWork);
            var productTypeController = new ProductTypeController(service);

            var updateCommand = new Commands.DeleteProductType
            {
                Id = id
            };

            await productTypeController.DeleteProductType(updateCommand);
        }
Beispiel #2
0
        public void TestMethod1()
        {
            //产品类型
            //新增
            ProductTypeSearchDTO searchdto = new ProductTypeSearchDTO();
            var searchdtostr = TransformHelper.ConvertDTOTOBase64JsonString(searchdto);

            testcontroller.GetProductTypeList(searchdtostr);
            ProductTypeOperateDTO adddto = new ProductTypeOperateDTO();

            adddto.ProductTypeName = "单元测试产品类型名称";
            var addresultstr = testcontroller.AddProductType(adddto).Content.ReadAsStringAsync().Result;
            var addresult    = JsonConvert.DeserializeObject <ResultDTO <object> >(addresultstr);
            var resultlist1  = JsonConvert.DeserializeObject <List <ProductTypeResultDTO> >(testcontroller.GetProductTypeList(searchdtostr).Content.ReadAsStringAsync().Result);
            var target       = resultlist1.Where(m => m.ProductTypeName == "单元测试产品类型名称").FirstOrDefault();

            Assert.IsNotNull(target);

            //修改
            adddto.ProductTypeID   = target.ProductTypeID;
            adddto.ProductTypeName = "修改单元测试产品类型名称";
            var updateresultstr = testcontroller.UpdateProductType(adddto).Content.ReadAsStringAsync().Result;
            var updateresult    = JsonConvert.DeserializeObject <ResultDTO <object> >(updateresultstr);

            var resultlist2str = testcontroller.GetProductTypeList(searchdtostr).Content.ReadAsStringAsync().Result;
            var resultlist2    = JsonConvert.DeserializeObject <List <ProductTypeResultDTO> >(resultlist2str);

            target = resultlist2.Where(m => m.ProductTypeName == "修改单元测试产品类型名称").FirstOrDefault();
            Assert.IsNotNull(target);

            //删除
            ProductTypeSearchDTO deletedto = new ProductTypeSearchDTO();

            deletedto.ProductTypeID = target.ProductTypeID;
            var deletedtostr    = TransformHelper.ConvertDTOTOBase64JsonString(deletedto);
            var deleteresultstr = testcontroller.DeleteProductType(deletedtostr).Content.ReadAsStringAsync().Result;
            var deleteresult    = JsonConvert.DeserializeObject <ResultDTO <object> >(deleteresultstr);
            var resultlist3str  = testcontroller.GetProductTypeList(searchdtostr).Content.ReadAsStringAsync().Result;
            var resultlist3     = JsonConvert.DeserializeObject <List <ProductTypeResultDTO> >(resultlist3str);

            target = resultlist3.Where(m => m.ProductTypeID == target.ProductTypeID).FirstOrDefault();
            Assert.IsNull(target);
        }
        private void DeleteBtn_Click(object sender, EventArgs e)
        {
            Button currentButton = (Button)sender;
            int    selectedIndex = 0;

            int.TryParse(currentButton.ID.Substring(0, currentButton.ID.Length - 3), out selectedIndex);
            int proTypeID = 0;

            proTypeID = int.Parse(((Label)ProductTypeTable.Rows[selectedIndex].Cells[1].Controls[0]).Text);

            Response response = ProductTypeController.DeleteProductType(proTypeID);

            if (response.successStatus)
            {
                Response.Redirect(Request.RawUrl);
            }
            else
            {
                ErrorLabel.Visible = true;
                ErrorLabel.Text    = response.message;
            }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                Response.Redirect("UpdateProductType.aspx?id=" + index);
            }

            if (e.CommandName == "Delete_Type")
            {
                int      index   = Convert.ToInt32(e.CommandArgument);
                Response respond = ProductTypeController.DeleteProductType(index);
                if (respond.successStatus == false)
                {
                    alert.Text = respond.message;
                }
                else
                {
                    Response.Redirect("ViewProductType.aspx");
                }
            }
        }