Exemplo n.º 1
0
        public async Task <ApiResult <bool> > Delete(long id)
        {
            var output = new ApiResult <bool>();

            try
            {
                var item = await _repository.GetQuery(new Model.Repository.GetQuery.Input {
                    Id = id
                }).FirstOrDefaultAsync();

                if (item != null)
                {
                    _unitOfWork._dbContext.Content.Remove(item);
                    await _unitOfWork.SaveChanges();

                    await _fileManage.Delete(new File.Model.Manage.DeleteModel.Input
                    {
                        CategoryId = (long)Const.FileCategory.Content,
                        ItemId     = item.Id.ToString(),
                    });

                    output.Code = Const.ApiCodeEnum.Success;
                    output.Data = true;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
            }

            return(output);
        }
Exemplo n.º 2
0
        public async Task <ApiResult <bool> > Delete(long id)
        {
            var output = new ApiResult <bool>();

            try
            {
                var item = await _repository.ProductBrandGetQuery(id).FirstOrDefaultAsync();

                if (item == null)
                {
                    output.Msgs.Add(new MsgResult("general", "common.not_exists"));
                    return(output);
                }

                _unitOfWork._dbContext.ProductBrand.Remove(item);
                await _unitOfWork.SaveChanges();

                await _fileManage.Delete(new File.Model.Manage.DeleteModel.Input
                {
                    CategoryId = (long)Const.FileCategory.Brand,
                    ItemId     = item.Id.ToString(),
                });

                output.Code = Const.ApiCodeEnum.Success;
                output.Data = true;
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
            }

            return(output);
        }
Exemplo n.º 3
0
        public async Task <ApiResult <bool> > Delete(long id)
        {
            var output = new ApiResult <bool>();
            var item   = await _repository.CategoryGetQuery(id).FirstOrDefaultAsync();

            if (item == null)
            {
                output.Msgs.Add(new MsgResult("general", "common.not_exists"));
            }

            if (await _repository.CategoryGetQuery(new Model.Repository.CategoryGetQuery.Input {
                ParentId = id
            }).AnyAsync())
            {
                output.Msgs.Add(new MsgResult("general", "common.has_childrens"));
            }

            if (output.Msgs.Any())
            {
                return(output);
            }

            using (var transaction = await _unitOfWork.BeginTransactionAsync())
            {
                try
                {
                    await _tree.Delete <Models.ProductCategory>(new Common.Model.Tree.Delete.Input
                    {
                        Left        = item.Left,
                        Right       = item.Right,
                        OrderNumber = item.OrderNumber,
                        ParentId    = item.ParentId.Value
                    });

                    _unitOfWork._dbContext.ProductCategory.Remove(item);
                    await _unitOfWork.SaveChanges();

                    await _fileManage.Delete(new File.Model.Manage.DeleteModel.Input
                    {
                        CategoryId = (long)Const.FileCategory.Brand,
                        ItemId     = item.Id.ToString(),
                    });

                    transaction.Commit();
                    output.Code = Const.ApiCodeEnum.Success;
                    output.Data = true;
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    _logger.Error(ex, ex.Message);
                }
            }
            return(output);
        }