Ejemplo n.º 1
0
        // GET: DepositAccount/Details/5
        public async Task <IActionResult> Details(int id)
        {
            DepositContract contract = await _context.DepositContracts.Include(c => c.Accounts).Include(c => c.User).FirstAsync(c => c.Id == id);

            DepositContractViewModel vm             = _mapper.Map <DepositContractViewModel>(contract);
            DepositAccount           account        = contract.Accounts.FirstOrDefault(a => !a.IsForPercents);
            DepositAccount           percentAccount = contract.Accounts.FirstOrDefault(a => a.IsForPercents);

            vm.DepositAmount  = account?.Credit.ToString("F");
            vm.DepositPercent = percentAccount?.Saldo.ToString("F");
            vm.UserName       = string.Format("{0} {1} {2}", contract.User.Surname, contract.User.FirstName, contract.User.SecondName);
            return(View(vm));
        }
Ejemplo n.º 2
0
        // GET: DepositAccount/Create
        public async Task <IActionResult> Create()
        {
            DepositContractViewModel vm       = new DepositContractViewModel();
            IEnumerable <Deposit>    deposits = await _context.Deposits.ToListAsync();

            var dep = new List <SelectListItem>();

            foreach (var item in deposits)
            {
                dep.Add(new SelectListItem()
                {
                    Selected = false, Text = string.Format("Name: {0}; Rate: {1}; Contract term: {2}", item.Name, item.Rate, item.Term), Value = item.Id.ToString()
                });
            }
            vm.Deposits = dep;
            IEnumerable <User> users = await _context.Users.ToListAsync();

            var usr = new List <SelectListItem>();

            foreach (var item in users)
            {
                usr.Add(new SelectListItem()
                {
                    Selected = false, Text = string.Concat(item.Surname, ' ', item.FirstName, ' ', item.SecondName), Value = item.Id.ToString()
                });
            }
            vm.Users = usr;
            var cur = new List <SelectListItem>();

            foreach (var item in Enum.GetNames(typeof(Currency)))
            {
                cur.Add(new SelectListItem()
                {
                    Selected = false, Text = item, Value = item
                });
            }
            vm.Currencies = cur;
            vm.BeginDate  = DateTime.Today.ToString("dd.MM.yyyy");
            vm.Number     = vm.GetHashCode().ToString("0000000000");
            return(View(vm));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(DepositContractViewModel vm)
        {
            try
            {
                DepositContract contract = _mapper.Map <DepositContract>(vm);
                Deposit         deposit  = _context.Deposits.Find(vm.DepositId);
                User            user     = await _context.Users.FindAsync(contract.UserId);

                int count = await _context.Accounts.Where(a => a.UserId == user.Id).CountAsync();

                contract.EndDate = contract.BeginDate.AddMonths(deposit.Term);
                await _context.DepositContracts.AddAsync(contract);

                await _context.SaveChangesAsync();

                Account cashRegisterAccount = await _context.Accounts.FirstOrDefaultAsync(a => a.Name == "cash");

                Account frbAccount = await _context.Accounts.FirstOrDefaultAsync(a => a.Name == "frb");

                decimal amount = decimal.Parse(vm.DepositAmount);
                cashRegisterAccount.Debet  += amount;
                cashRegisterAccount.Credit += amount;
                frbAccount.Credit          += amount;
                frbAccount.Saldo           += amount;
                DepositAccount account = new DepositAccount()
                {
                    IsActive          = false,
                    DepositContractId = contract.Id,
                    Credit            = amount,
                    Debet             = amount,
                    Saldo             = 0,
                    IsForPercents     = false,
                    UserId            = user.Id,
                    Number            = "3014" + user.Id.ToString("00000") + (count + 1).ToString("000") + '1',
                    Name = user.Surname + " " + user.FirstName + " " + user.SecondName
                };
                await _context.DepositAccounts.AddAsync(account);

                DepositAccount percentAccount = new DepositAccount()
                {
                    IsActive          = false,
                    DepositContractId = contract.Id,
                    Credit            = 0,
                    Debet             = 0,
                    Saldo             = 0,
                    IsForPercents     = true,
                    UserId            = user.Id,
                    Number            = "3470" + user.Id.ToString("00000") + (count + 2).ToString("000") + '2',
                    Name = user.Surname + " " + user.FirstName + " " + user.SecondName
                };
                await _context.DepositAccounts.AddAsync(percentAccount);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(vm));
            }
        }