Example #1
0
        public void CreateOneWalletOperation(int personId, int walletId, int operationCategoryId, decimal balance, string description, DateTime?date)
        {
            CheckArgument.CheckForNull(description, nameof(description));

            Person person = this.UnitOfWork.PersonRepository.GetById(personId)
                            ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Wallet wallet = this.UnitOfWork.WalletRepository.GetById(walletId)
                            ?? throw new InvalidForeignKeyException(typeof(Wallet).Name);

            OperationCategory operationCategory = this.UnitOfWork.OperationCategoryRepository.GetById(operationCategoryId)
                                                  ?? throw new InvalidForeignKeyException(typeof(OperationCategory).Name);

            PersonWallet personWallet = this.UnitOfWork.PersonWalletRepository.GetPersonWalletByPersonAndWallet(personId, walletId)
                                        ?? throw new InvalidPropertyException(typeof(PersonWallet).Name);

            wallet.Balance = balanceCalculator.CountNewWalletBalance(wallet.Balance, balance, operationCategory.Type);
            this.UnitOfWork.WalletRepository.Update(wallet);

            OperationInfo operationInfo = new OperationInfo()
            {
                Balance = balance, Description = description, Date = date ?? DateTime.Now
            };

            this.UnitOfWork.OperationInfoRepository.Add(operationInfo);

            Operation operation = new Operation()
            {
                OperationCategoryID = operationCategory.ID, OperationInfoID = operationInfo.ID, PersonWalletID = personWallet.ID
            };

            this.GetRepository().Add(operation);
            this.UnitOfWork.SaveChanges();
        }
Example #2
0
        public PersonController(IPersonService personService, IPersonRepository personRepository, IMapper mapper)
        {
            CheckArgument.CheckForNull(personService, nameof(personService));
            CheckArgument.CheckForNull(personRepository, nameof(personRepository));
            CheckArgument.CheckForNull(mapper, nameof(mapper));

            this.personService    = personService;
            this.personRepository = personRepository;
            this.mapper           = mapper;
        }
        public FamilyController(IFamilyService familyService, IUnitOfWork unitOfWork, IMapper mapper)
        {
            CheckArgument.CheckForNull(familyService, nameof(familyService));
            CheckArgument.CheckForNull(unitOfWork, nameof(unitOfWork));
            CheckArgument.CheckForNull(mapper, nameof(mapper));

            this.familyService = familyService;
            this.unitOfWork    = unitOfWork;
            this.mapper        = mapper;
        }
        public void Update(int id, string name)
        {
            CheckArgument.CheckForNull(name, nameof(name));

            Family family = this.GetRepository().GetById(id)
                            ?? throw new InvalidPrimaryKeyException(typeof(Family).Name);

            family.Name = name;
            this.GetRepository().Update(family);
            this.UnitOfWork.SaveChanges();
        }
Example #5
0
        public void Rename(int id, string name)
        {
            CheckArgument.CheckForNull(name, nameof(name));

            Wallet wallet = this.GetRepository().GetById(id)
                            ?? throw new InvalidPrimaryKeyException(typeof(Wallet).Name);

            wallet.Name = name;

            this.GetRepository().Update(wallet);
            this.UnitOfWork.SaveChanges();
        }
        public void Create(string name, OperationType operationType)
        {
            CheckArgument.CheckForNull(name, nameof(name));

            OperationCategory operationCategory = new OperationCategory()
            {
                Name = name, Type = operationType
            };

            this.GetRepository().Add(operationCategory);
            this.UnitOfWork.SaveChanges();
        }
        public void Create(string name, string surname)
        {
            CheckArgument.CheckForNull(name, nameof(name));
            CheckArgument.CheckForNull(surname, nameof(surname));

            Person person = new Person()
            {
                Name = name, Surname = surname
            };

            this.GetRepository().Add(person);
            this.UnitOfWork.SaveChanges();
        }
Example #8
0
        public void CreateWalletByPersonId(int personId, string name, WalletType walletType, decimal balance = 0)
        {
            CheckArgument.CheckForNull(name, nameof(name));

            Person person = this.UnitOfWork.PersonRepository.GetById(personId)
                            ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Wallet wallet = new Wallet {
                Name = name, Type = walletType, Balance = balance
            };

            this.GetRepository().Add(wallet);

            PersonWallet personWallet = new PersonWallet {
                WalletID = wallet.ID, PersonID = personId, AccessModifier = AccessModifier.Manage
            };

            this.UnitOfWork.PersonWalletRepository.Add(personWallet);
            this.UnitOfWork.SaveChanges();
        }
        public void Create(int personId, string name)
        {
            CheckArgument.CheckForNull(name, nameof(name));

            Person person = this.UnitOfWork.PersonRepository.GetById(personId)
                            ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Family family = new Family()
            {
                Name = name
            };

            this.GetRepository().Add(family);

            PersonFamily personFamily = new PersonFamily {
                PersonID = personId, FamilyID = family.ID
            };

            this.UnitOfWork.PersonFamilyRepository.Add(personFamily);
            this.UnitOfWork.SaveChanges();
        }
Example #10
0
 public EntityServiceBase(IUnitOfWork unitOfWork)
 {
     CheckArgument.CheckForNull(unitOfWork, nameof(unitOfWork));
     this.unitOfWork = unitOfWork;
 }
Example #11
0
        public void CreateTransaction(int fromPersonId, int fromWalletId, int toPersonId, int toWalletId, decimal balance, string description, DateTime?date)
        {
            CheckArgument.CheckForNull(description, nameof(description));

            Person fromPerson = this.UnitOfWork.PersonRepository.GetById(fromPersonId)
                                ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Person toPerson = this.UnitOfWork.PersonRepository.GetById(toPersonId)
                              ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Wallet fromWallet = this.UnitOfWork.WalletRepository.GetById(fromWalletId)
                                ?? throw new InvalidForeignKeyException(typeof(Wallet).Name);

            Wallet toWallet = this.UnitOfWork.WalletRepository.GetById(toWalletId)
                              ?? throw new InvalidForeignKeyException(typeof(Wallet).Name);

            PersonWallet fromPersonWallet = this.UnitOfWork.PersonWalletRepository.GetPersonWalletByPersonAndWallet(fromPersonId, fromWalletId)
                                            ?? throw new InvalidPropertyException(typeof(PersonWallet).Name);

            PersonWallet toPersonWallet = this.UnitOfWork.PersonWalletRepository.GetPersonWalletByPersonAndWallet(toPersonId, toWalletId)
                                          ?? throw new InvalidPropertyException(typeof(PersonWallet).Name);

            OperationCategory fromOperationCategory = this.UnitOfWork.OperationCategoryRepository.GetOperationCategoryByTypeAndName(OperationType.Spending, typeof(Transaction).Name);

            if (fromOperationCategory == null)
            {
                fromOperationCategory = new OperationCategory()
                {
                    Type = OperationType.Spending, Name = typeof(Transaction).Name
                };
                this.UnitOfWork.OperationCategoryRepository.Add(fromOperationCategory);
            }

            OperationCategory toOperationCategory = this.UnitOfWork.OperationCategoryRepository.GetOperationCategoryByTypeAndName(OperationType.Earning, typeof(Transaction).Name);

            if (toOperationCategory == null)
            {
                toOperationCategory = new OperationCategory()
                {
                    Type = OperationType.Earning, Name = typeof(Transaction).Name
                };
                this.UnitOfWork.OperationCategoryRepository.Add(toOperationCategory);
            }

            fromWallet.Balance = balanceCalculator.CountNewWalletBalance(fromWallet.Balance, balance, fromOperationCategory.Type);
            this.UnitOfWork.WalletRepository.Update(fromWallet);

            toWallet.Balance = balanceCalculator.CountNewWalletBalance(toWallet.Balance, balance, toOperationCategory.Type);
            this.UnitOfWork.WalletRepository.Update(toWallet);

            OperationInfo operationInfo = new OperationInfo()
            {
                Balance = balance, Description = description, Date = date ?? DateTime.Now
            };

            this.UnitOfWork.OperationInfoRepository.Add(operationInfo);

            Transaction transaction = new Transaction();

            this.UnitOfWork.TransactionRepository.Add(transaction);

            Operation fromOperation = new Operation()
            {
                OperationCategoryID = fromOperationCategory.ID, OperationInfoID = operationInfo.ID, PersonWalletID = fromPersonWallet.ID, TransactionID = transaction.ID
            };

            this.GetRepository().Add(fromOperation);

            Operation toOperation = new Operation()
            {
                OperationCategoryID = toOperationCategory.ID, OperationInfoID = operationInfo.ID, PersonWalletID = toPersonWallet.ID, TransactionID = transaction.ID
            };

            this.GetRepository().Add(toOperation);
            this.UnitOfWork.SaveChanges();
        }
Example #12
0
 public OperationService(IUnitOfWork unitOfWork, IBalanceCalculator balanceCalculator)
     : base(unitOfWork)
 {
     CheckArgument.CheckForNull(balanceCalculator, nameof(balanceCalculator));
     this.balanceCalculator = balanceCalculator;
 }