Exemplo n.º 1
0
        public async Task <JsonResult> Create(BillWithAccount vm)
        {
            try
            {
                if (vm.FrequencyId > 0)
                {
                    vm.Frequency = (FrequencyEnum)vm.FrequencyId;
                }


                var bill        = MapToBill(vm);
                var billCreated = false;
                if (vm.AccountId != 0)
                {
                    billCreated = await _billService.CreateBillAsync(bill);

                    return(Json(!billCreated ? "Error" : "Success"));
                }


                var account = MapToAccount(vm);
                _accountService.CreateAccount(account);
                bill.AccountId = account.Id;

                billCreated = await _billService.CreateBillAsync(bill);

                return(Json(!billCreated ? "Error" : "Success"));
            }
            catch (Exception e)
            {
                Logger.Instance.Error(e);
                return(Json("Error"));
            }
        }
Exemplo n.º 2
0
        private Account MapToAccount(BillWithAccount vm)
        {
            var account = new Account();

            account.Name    = vm.AccountName;
            account.Balance = vm.AccountBalance;
            account.PaycheckContribution = vm.AccountPaycheckContribution;


            return(account);
        }
Exemplo n.º 3
0
        // TODO: move to service layer
        private Bill MapToBill(BillWithAccount vm)
        {
            var bill = new Bill();

            bill.Name             = vm.Name;
            bill.AmountDue        = vm.AmountDue;
            bill.PaymentFrequency = vm.Frequency;
            bill.DueDate          = vm.DueDate;
            if (vm.AccountId != null)
            {
                bill.AccountId = (int)vm.AccountId;
            }


            return(bill);
        }