private string SendBonus(string childName, FamilyMember adminMember, decimal amount)
        {
            var childMember = _familyService.GetMember(adminMember.User.FamilyID, childName, MemberType.Child);

            if (childMember == null)
            {
                return("Child not found");
            }

            var childBonus = new ChildBonus
            {
                ChildID       = childMember.Id,
                Date          = DateTime.UtcNow,
                ContributorID = adminMember.Id,
                Note          = "Bonus sent through SMS",
                Amount        = amount
            };

            try
            {
                _earningsService.SendBonus(childBonus, adminMember.Id);
                return("Bonus successfully sent to " + childName);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Пример #2
0
        public void SendBonus(ChildBonus bonus)
        {
            if (bonus == null)
            {
                throw new InvalidParameterException("Invalid parameters!");
            }

            if (_currentUserService.MemberType != MemberType.Admin && _currentUserService.MemberType != MemberType.Parent)
            {
                throw new UnauthorizedAccessException();
            }

            _earningsService.SendBonus(bonus);
        }
Пример #3
0
        /// <summary>
        /// Send bonus to the child
        /// </summary>
        /// <param name="bonus">The bonus.</param>
        public void SendBonus(ChildBonus bonus, int?familyMemberId = null)
        {
            var memberId = familyMemberId ?? _currentUserService.MemberID;

            // Gets current authenticated member
            var member = Repository.Table <FamilyMember>().Include(p => p.User).SingleOrDefault(p => p.Id == memberId);

            // Gets the admin id of the family if current member type is parent
            if (member.MemberType != MemberType.Admin)
            {
                member = Repository.Table <FamilyMember>().FirstOrDefault(m => m.User.FamilyID == member.User.FamilyID && m.MemberType == MemberType.Admin);
            }

            // Checks whether the member has linked thier bank account or not
            if (!_bankService.IsBankLinked(member.Id))
            {
                throw new InvalidOperationException("Bank is not linked or verified!");
            }

            try
            {
                // Tranfer amount to corepro account
                var transactionResult = _transactionService.Transfer(member.Id, bonus.Amount, PaymentType.Bonus, TransferType.ExternalToInetrnalAccount);

                // If transaction failure, skips the process
                if (!transactionResult.HasValue)
                {
                    throw new InvalidOperationException("Unable to process the transaction. Please contact bank or mail to us!");
                }

                // Insert bonus
                bonus.Date              = DateTime.UtcNow;
                bonus.ContributorID     = memberId;
                bonus.BankTransactionID = transactionResult.Value;
                Repository.Insert(bonus);

                // Sms receive bonus message to child
                var child = Repository.Table <FamilyMember>().Include(m => m.User).Include(m => m.User.Family).SingleOrDefault(p => p.Id == bonus.ChildID && !p.IsDeleted);
                if (child != null)
                {
                    if (!string.IsNullOrEmpty(child.PhoneNumber))
                    {
                        var message = string.Format(_appSettingsService.ChildHasPhoneReceiveBonusMessage,
                                                    child.Firstname, bonus.Amount, bonus.Contributor.Firstname);
                        _textMessageService.Send(child.PhoneNumber, message);
                    }
                    else
                    {
                        var admin = Repository.Table <FamilyMember>().SingleOrDefault(m => m.Id == memberId);
                        if (admin != null && !string.IsNullOrEmpty(admin.PhoneNumber))
                        {
                            var message = string.Format(_appSettingsService.ChildHasNoPhoneReceiveBonusMessage,
                                                        admin.Firstname, child.Firstname, bonus.Amount);
                            _textMessageService.Send(admin.PhoneNumber, message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _transactionService.SaveTransactionLog(memberId, ex.Message, bonus.Amount);
                throw new InvalidOperationException(ex.Message);
            }
        }