public async Task <ActionResult> CreateLoan([FromBody] CreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var  dateTime = DateTime.Now;
            Loan loan     = new Loan
            {
                idclient          = model.idclient,
                capital           = model.capital,
                interest_rate     = model.interest_rate,
                period            = model.period,
                interest_to_pay   = model.interest_to_pay,
                amount_to_finance = model.amount_to_finance,
                fee        = model.fee,
                created_dt = dateTime,
                condicion  = true
            };

            _context.Loans.Add(loan);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Esempio n. 2
0
        public async Task <ActionResult> Create([FromBody] CreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var     dateTime = DateTime.Now;
            Payment payment  = new Payment
            {
                idloan     = model.idloan,
                amount     = model.amount,
                created_dt = dateTime,
                condicion  = true
            };

            _context.Payments.Add(payment);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
            return(Ok());
        }
        public async Task <IActionResult> ActualizeClient([FromBody] ActualizeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (model.idclient < 0)
            {
                return(BadRequest());
            }

            var client = await _context.Clients.FirstOrDefaultAsync(c => c.idclient == model.idclient);

            if (client == null)
            {
                return(NotFound());
            }

            client.name         = model.name;
            client.address      = model.address;
            client.phone_number = model.phone_number;
            client.email        = model.email;
            client.credit_limit = model.credit_limit;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(Ok());
        }
        public async Task <ActionResult> Create([FromBody] CreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var email = model.email.ToLower();

            if (await _context.Users.AnyAsync(u => u.email == email))
            {
                return(BadRequest("The email already exists."));
            }

            CreatePasswordHash(model.password, out byte[] passwordHash, out byte[] passwordSalt);

            User user = new User
            {
                idrole        = model.idrole,
                nombre        = model.nombre,
                email         = model.email.ToLower(),
                condicion     = true,
                password_hash = passwordHash,
                password_salt = passwordSalt
            };

            _context.Users.Add(user);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }

            return(Ok());
        }