Beispiel #1
0
        public Withdraw WithdrawMoney(int id)
        {
            var withdraw = new Withdraw();
            var employee = Get(id);

            if (employee != null)
            {
                if (!_fundAccountBusiness.AlreadyCashedOut(id))
                {
                    if (IsBirthDate(employee.BirthDate.GetValueOrDefault()))
                    {
                        var amount = CalculateAmount(employee.Id);

                        if (amount > 0)
                        {
                            amount = Math.Round(amount, 2, MidpointRounding.AwayFromZero);
                            _fundAccountBusiness.Insert(new FundAccount {
                                EmployeeId = employee.Id, Entry = -amount, EntryDate = DateTime.Today
                            });
                            withdraw.Amount = amount;
                        }
                        withdraw.Message = ValidationMessage.CalculatedAmount(amount);
                    }
                    else
                    {
                        withdraw.Message = ValidationMessage.NotBirthDay;
                    }
                }
                else
                {
                    withdraw.Message = ValidationMessage.AlreadyCashedOut;
                }
            }
            else
            {
                withdraw.Message = ValidationMessage.NotFound;
            }

            return(withdraw);
        }