Ejemplo n.º 1
0
        public MethodResult Work(int citizenID, int companyID)
        {
            var result = new MethodResult();

            using (var t = transactionScopeProvider.CreateTransactionScope())
            {
                var company  = companyRepository.GetById(companyID);
                var citizen  = citizenRepository.First(c => c.ID == citizenID);
                var employee = company.CompanyEmployees.First(e => e.CitizenID == citizen.ID);


                produceProduct(company, citizen);
                updateCitizenAfterWork(company, citizen);
                result.Merge(payCashForWork(company, citizen, employee));


                if ((citizen.DayWorkedRow % 30) == 0)
                {
                    citizenService.ReceiveHardWorker(citizen);
                }
                var transaction = System.Transactions.Transaction.Current;

                if (transaction.TransactionInformation.Status == System.Transactions.TransactionStatus.Aborted)
                {
                    throw new UserReadableException("You cannot work");
                }

                company.InformedAboutNotEnoughSalaryToday = false;
                company.InformedAboutNotEnoughRawToday    = false;

                companyRepository.SaveChanges();

                t.Complete();
            }

            return(result);
        }