Пример #1
0
        public async Task AddBillAsync(AddBillModel model)
        {
            if (model.Amount < 0)
            {
                throw new InvalidOperationException("金额不能小于0");
            }
            var bill = model.CopyProperties <Bill>();

            _unitOfWork.RegisterAdd(bill);
            await _unitOfWork.CommitAsync();
        }
Пример #2
0
        public async Task AddBillCategoryAsync(AddBillCategoryModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                throw new InvalidOperationException("类型名称不能为空");
            }
            BillCategory billCategory = await _billCategoryRepository.FirstOrDefaultAsync(m => m.UserID.Equals(model.UserID) && m.Name.Equals(model.Name));

            if (billCategory != null)
            {
                throw new InvalidOperationException("该类型名称已存在");
            }
            billCategory       = model.CopyProperties <BillCategory>();
            billCategory.Index = _billCategoryRepository.GetMaxIndex() + 1;
            _unitOfWork.RegisterAdd(billCategory);
            await _unitOfWork.CommitAsync();
        }
Пример #3
0
        public async Task AddUserAsync(AddUserModel model)
        {
            if (string.IsNullOrEmpty(model.Account))
            {
                throw new InvalidOperationException("账号不能为空");
            }
            if (model.Account.Length > 50)
            {
                throw new InvalidOperationException("账号长度不能大于50");
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称不能为空");
            }
            if (model.Name.Length > 50)
            {
                throw new InvalidOperationException("名称长度不能大于50");
            }
            User userFromDB;

            if (!string.IsNullOrEmpty(model.Account))
            {
                userFromDB = await _userRepository.FirstOrDefaultAsync(m => m.Account == model.Account);

                if (userFromDB != null)
                {
                    throw new InvalidOperationException("账户已存在");
                }
            }
            userFromDB          = model.CopyProperties <User>();
            userFromDB.Password = GetEncodePassword(DefaultPassword);
            _unitOfWork.RegisterAdd(userFromDB);
            await _unitOfWork.CommitAsync();
        }