public async Task <IActionResult> deleteCategory([FromBody] DeleteCategoryDto CategoryId)
        {
            string Resultmessage = string.Empty;

            try
            {
                Resultmessage = await _CategoryService.deleteCategory(CategoryId.CategoryId);

                if (Resultmessage == "")
                {
                    return(BadRequest(new GenericResultDto <string> {
                        Result = "Category exists with merchants."
                    }));
                }
            }

            catch (Exception err)
            {
                return(BadRequest(new GenericResultDto <string>
                {
                    Result = err.Message
                }));
            }
            return(Ok(new GenericResultDto <string> {
                Result = Resultmessage
            }));
        }
Exemple #2
0
        public async Task <HttpResponseMessage> DeleteCategory(DeleteCategoryDto category)
        {
            Response <Entities.Entities.Category> httpResponse = new Response <Entities.Entities.Category>();

            try
            {
                httpResponse.RequestState = true;
                httpResponse.ErrorState   = !await _categoryManager.DeleteCategory(category.Adapt <Entities.Entities.Category>());
            }
            catch (Exception ex)
            {
                httpResponse.ErrorState = true;
                httpResponse.ErrorList.Add(ex.Adapt <ApiException>());
            }
            return(httpResponse);
        }
        public async Task <ActionResult> DeleteCategory([FromBody] DeleteCategoryDto viewRequest)
        {
            if (!TryValidateModel(viewRequest))
            {
                return(BadRequest(ValidationHelper.GetModelErrors(ModelState)));
            }

            var request = this._mapper.Map <DeleteCategoryRequest>(viewRequest);

            request.UserName = HttpContext.User.Identity.Name;
            var command = new DeleteCategoryCommand
            {
                Data = request
            };

            return(await Go(command));
        }
        public async Task <HttpResponseMessage> DeleteCategory(DeleteCategoryDto category)
        {
            _logger.LogDebug("DeleteCategory init with", category);
            Response <Entities.Entities.Category> httpResponse = new Response <Entities.Entities.Category>();

            try
            {
                httpResponse.RequestState = true;
                httpResponse.ErrorState   = !await _categoryManager.DeleteCategory(category.Adapt <Entities.Entities.Category>());
            }
            catch (Exception ex)
            {
                _logger.LogError("DeleteCategory Error", ex);
                httpResponse.ErrorState = true;
                httpResponse.ErrorList.Add(ex.Adapt <ApiException>());
            }
            _logger.LogDebug("DeleteCategory end with", httpResponse);
            return(httpResponse);
        }
Exemple #5
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public PublicResult DeleteCategory(DeleteCategoryDto dto)
        {
            Category category = null;

            using (var client = DbFactory.CreateClient())
            {
                category = client.Queryable <Category>().InSingle(dto.Id);
                if (category == null)
                {
                    return(Error("找不到该条信息"));
                }

                client.UseTran(tran =>
                {
                    tran.Ado.ExecuteCommand(@"DELETE FROM tab_category WHERE path LIKE @path", new { path = $"{category.Path}.%" });
                    tran.Deleteable <Category>(dto.Id).ExecuteCommand();
                });
            }
            _distributedCache.Remove(CACHE_CATEGORY_ALL_KEY);
            _eventPublisher.EntityDeleted(category);
            return(Ok());
        }
Exemple #6
0
        public async Task DeleteCategory(DeleteCategoryDto input)
        {
            var ct = await GetCategoryById(input.Id);

            await _categoryRepository.DeleteAsync(ct);
        }