Пример #1
0
        public async Task <Result> PostAsync([FromBody] CategoryRequest request)
        {
            var session = App.HttpContext.Items["Session"] as Session;

            if (string.IsNullOrWhiteSpace(request.Name))
            {
                return(Result.Complete());
            }
            var category = new Category(request.Name, request.Icon, request.Type, session.Id);
            await _categoryRep.InsertNowAsync(category);

            return(Result.Complete());
        }
Пример #2
0
        public async Task <Result> PutAsync([FromBody] CategoryRequest request)
        {
            var session = App.HttpContext.Items["Session"] as Session;
            var cat     = await _categoryRep.AsQueryable()
                          .FirstOrDefaultAsync(e => e.CreateMemberId == session.Id && e.Id == request.Id);

            if (cat == null)
            {
                return(Result.Complete("Not Found"));
            }
            cat.SetName(request.Name);
            await _categoryRep.SaveNowAsync();

            return(Result.Complete());
        }
Пример #3
0
        public async Task <Result> DeleteAsync([FromBody] CategoryRequest request)
        {
            var session = App.HttpContext.Items["Session"] as Session;
            var cat     = await _categoryRep.AsQueryable()
                          .FirstOrDefaultAsync(e => e.CreateMemberId == session.Id && e.Id == request.Id);

            if (cat == null)
            {
                return(Result.Complete("Not Found"));
            }
            var hasTransaction = await _transcationRep.AsQueryable().AnyAsync(e => e.CategoryId == request.Id);

            if (hasTransaction)
            {
                return(Result.Fail(nameof(BusinessViolationStatusCodes.RuleViolated), "该分类下有记账,不能删除哦"));
            }
            await _categoryRep.DeleteNowAsync(cat);

            return(Result.Complete("删除成功"));
        }