コード例 #1
0
        public ActionResult AddDues(BusinessDuesViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                if (viewModel.AmountPaid == null && viewModel.AmountDue == null)
                {
                    TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel
                    {
                        Message     = "Enter an amount due.",
                        MessageType = GenericMessages.danger
                    };
                    return(RedirectToAction("UpdateDues", "AdminBusiness", new { id = viewModel.BusinessId }));
                }

                var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty;
                var admin          = MembershipService.Get(loggedOnUserId);
                var settings       = SettingsService.GetSettings();
                var business       = _businessService.Get(viewModel.BusinessId);

                var newBusinessBalance = new BusinessBalance()
                {
                    AmountDue  = viewModel.AmountDue,
                    AmountPaid = viewModel.AmountPaid,
                    DueDate    = viewModel.DueDate,
                    PaidDate   = viewModel.PaidDate
                };

                newBusinessBalance.Business = business;
                _businessService.AddBusinessBalance(newBusinessBalance);
                _businessService.AdminBusinessBalanceAdded(newBusinessBalance, admin);
                unitOfWork.Commit();
                TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel
                {
                    Message     = "Business Due Added.",
                    MessageType = GenericMessages.success
                };
                return(RedirectToAction("UpdateDues", "AdminBusiness", new { id = business.Id }));
            }
        }