Beispiel #1
0
        public void CreateAndDeleteDepartment()
        {
            // Идеально Имеет место создавать тестовую бд перед выполнением, а
            // мы сдеаем два теста в одном, но так делать нельзя с идеологической точки зрения, да и не только!!!
            // они НЕ ДОЛЖНЫ зависить друг от друга и проверять каждый должен конкретный свой аспект

            CatalogDepartmentDTO dto = new CatalogDepartmentDTO
            {
                Name          = "Else one more",
                EmployeeCount = 5,
            };
            Task <IBaseDTO> t = _service.Add("departments", dto);

            t.Wait();
            var newDto = t.Result as CatalogDepartmentDTO;

            Assert.IsNotNull(newDto, "Создание");

            Task <bool> t2 = _service.Delete("departments", newDto.Id);

            t2.Wait();
            bool result = t2.Result;

            Assert.IsTrue(result, "Удаление");
        }
        private async void mi_delete_Click(object sender, RoutedEventArgs e)
        {
            CatalogModel model = this.TreeModel.GetCurrentSelect();

            if (model != null)
            {
                if (model.ParentId == null)
                {
                    MessageBox.Show("不允许删除根目录", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                if (MessageBox.Show($"将要删除目录<{model.Name}>,确认操作吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) == MessageBoxResult.Yes)
                {
                    Catalog catalog = ObjectMapper.Map <CatalogModel, Catalog>(model);
                    try
                    {
                        await CatalogService.Delete(catalog);

                        this.TreeModel.RemoveModel(model);
                        CatalogModel parentModel = this.TreeModel.GetModelById(model.ParentId);
                        parentModel.IsSelected = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Beispiel #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            CatalogEntry catalogEntry = _catalogService.TryGet(id);

            if (catalogEntry != null)
            {
                _catalogService.Delete(catalogEntry);
            }
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult Delete(int id)
        {
            int cnt = _catalogService.Delete(id);

            if (cnt > 0)
            {
                TempData["Message"] = string.Format("{0},{1}", "success", "刪除成功");
            }
            else
            {
                TempData["Message"] = string.Format("{0},{1}", "warning", "刪除失敗");
            }

            return(RedirectToAction("Index"));
        }
        public IActionResult Delete(int id)
        {
            UserService userService = new UserService();

            var user = userService.GetById(Int32.Parse(HttpContext.User.Claims.First().Value));

            if (user.isAdmin)
            {
                if (catalogService.Delete(id))
                {
                    return(Ok());
                }
            }
            else
            {
                if (catalogService.FakeDelete(id))
                {
                    return(Ok());
                }
            }

            return(BadRequest());
        }