public async Task <T> Add <T>(T entity) where T : BaseEntity
        {
            _context.Set <T>().Add(entity);
            await _context.SaveChangesAsync();

            return(entity);
        }
        public async Task <IActionResult> PutCustomers([FromRoute] long id, [FromBody] Customers customers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customers.id)
            {
                return(BadRequest());
            }

            _context.Entry(customers).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #3
0
        public async Task <Customer> Add(Customer customer)
        {
            _context.Add(customer); //Change Tracker : only change the state
            await _context.SaveChangesAsync();

            return(customer);
        }
        public async Task <IActionResult> addrec([FromBody] AddRecModel model)
        {
            Double parsedearn;
            float  parsedcurr, parsedind;
            bool   parse1, parse2, parse3;

            parse1 = Double.TryParse(model.earnings.ToString(), out parsedearn);
            parse2 = Single.TryParse(model.currency.ToString(), out parsedcurr);
            parse3 = Single.TryParse(model.index.ToString(), out parsedind);
            if (parse1 && parse2 && parse3)  //если все колонки имеют верные данные, добавляем запись
            {
                Record rec = new Record();
                rec.date     = DateTime.Now.Date;
                rec.earnings = parsedearn;
                rec.currency = parsedcurr;
                rec.index    = parsedind;
                _context.Records.Add(rec);
                await _context.SaveChangesAsync();
            }

            IndexViewModel inmodel = new IndexViewModel();

            inmodel.records = _context.Records.ToList();
            return(PartialView("table", inmodel));
        }
Exemple #5
0
        public async Task <IActionResult> AddTemplate(Template template)
        {
            if (ModelState.IsValid)
            {
                User   user   = null;
                string userId = HttpContext.Session.GetString("UserId");
                SessionHandler.GetUser(userId, out user);

                if (!_context.IsTemplateNameUnique(template.Name, user.Id))
                {
                    ViewBag.ErrName = "Template name must be unique.";
                    return(View(template));
                }

                template.UserId = user.Id;

                try
                {
                    _context.Add(template);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(TemplateList)));
                }
                catch
                {
                    return(Redirect("/Home/Error"));
                }
            }

            return(View(template));
        }
Exemple #6
0
        public async Task <IActionResult> Withdraw(int id, int amount)
        {
            try
            {
                Business business = new Business();
                business = await _context.Business.FirstOrDefaultAsync(c => c.accountNumber == id);

                var newBalance = (business.Balance - amount);
                business.Balance = newBalance;

                Transaction transaction = new Transaction();
                transaction.accountNumber = id;
                transaction.accountType   = "business";
                transaction.amount        = amount;
                transaction.date          = DateTime.Now;
                transaction.type          = "withdraw";

                _context.Update(business);
                await _context.SaveChangesAsync();


                //_context.Update(transaction);
                //await _context.SaveChangesAsync();
            }
            catch
            {
                ViewData["ErrorMessage"] = "There was a problem with your withdrawl please try again";
                return(View());
            }
            return(RedirectToAction(nameof(Business)));
        }
Exemple #7
0
 public async Task TestInitAsync()
 {
     _context.Add(user);
     temp.UserId = user.Id;
     _context.Add(temp);
     await _context.SaveChangesAsync();
 }
        public async Task <ActionResult> PutBankAccount(int id, BankAccount bankAccount)
        {
            if (id != bankAccount.BankAccountID)
            {
                return(BadRequest());
            }

            _context.Entry(bankAccount).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BankAccountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
        //PUT: api/Bank/1
        public async Task <ActionResult <Bank> > PutBank(int id, Bank bank)
        {
            if (bank.BankID != id)
            {
                return(BadRequest());
            }

            _context.Entry(bank).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.Banks.Any(e => e.BankID == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #10
0
        public async Task <IActionResult> Edit(int id, [Bind("AccountNumber,AccountName,Balance,AccountType,CreatedDate,EmailAddress")] Account account)
        {
            if (id != account.AccountNumber)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(account);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(account.AccountNumber))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
Exemple #11
0
        public async Task <IActionResult> PutCustomer(long id, Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public Task <int> Add(Account entity)
 {
     entity.Password    = CommonFunction.CreatePasswordHash(entity.Password, Conts.PASSWORD_SALT);
     entity.CreatedDate = DateTime.Now;
     _context.Add(entity);
     _context.Entry(entity).State = EntityState.Added;
     return(_context.SaveChangesAsync());
 }
        public async Task <Account> Add(Account account)
        {
            // كانت هون بدون الاكاونت بالسطر اللي ورا
            _context.Accounts.Add(account); //Change Tracker : only change the state
            await _context.SaveChangesAsync();

            return(account);
        }
        public async Task <IActionResult> Create([Bind("Id,accountNumber,numberOfMonth,accountType,amount,date,type")] Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transaction);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(transaction));
        }
Exemple #15
0
 public async Task TestInitAsync()
 {
     try
     {
         _context.Add(user);
         pay.UserId = user.Id;
         _context.Add(pay);
         await _context.SaveChangesAsync();
     }
     catch { }
 }
Exemple #16
0
        public async Task <ActionResult <LaaneType> > PostLåneType(LaaneType laaneType)
        {
            if (LåneTypeExists(laaneType.Id))
            {
                return(BadRequest());
            }
            _context.LaaneTyper.Add(laaneType);
            await _context.SaveChangesAsync();

            return(Ok());
        }
Exemple #17
0
        public async Task <IActionResult> Create([Bind("AccountNumber,EmailAddress,Balance,AccountType,CreatedDate")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
        public async Task <IActionResult> Create([Bind("Id,firstName,lastName,email,phoneNumber,address")] Customers customers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customers));
        }
Exemple #19
0
        public async Task <IActionResult> Create([Bind("type,accountNumber,InterestRate,Balance,createdAt")] Loan loan)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loan);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(loan));
        }
Exemple #20
0
        public async Task <IActionResult> Create([Bind("PosId,PosName,Salary,Responsibilities,Requirements")] Positions positions)
        {
            if (ModelState.IsValid)
            {
                _context.Add(positions);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(positions));
        }
        public async Task <ActionResult> Create([Bind(Include = "ID,Name,URL,OrderDetailsPath,UpdateOrderStatusPath,OrderSummaryPath,Description")] Acquirer acquirer)
        {
            if (ModelState.IsValid)
            {
                db.Acquirers.Add(acquirer);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(acquirer));
        }
        public async Task <IActionResult> PostBankItem(Client item)
        {
            if (!ModelState.IsValid)

            {
                return(ValidationProblem(ModelState));
            }
            _context.Clients.Add(item);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }
Exemple #23
0
        public async Task <ActionResult> Create([Bind(Include = "ID,PaymentCardNumber,Code,Blocked,SecureCard")] PaymentCard paymentCard)
        {
            if (ModelState.IsValid)
            {
                db.PaymentCards.Add(paymentCard);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(paymentCard));
        }
Exemple #24
0
        public async Task <IActionResult> PostSavingItem(Saving item)
        {
            if (!ModelState.IsValid)

            {
                return(ValidationProblem(ModelState));
            }
            _context.Savings.Add(item);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        } // PUT: api/Todo/5
Exemple #25
0
        public async Task <IActionResult> Create([Bind("Id,accountNumber,numberOfMonth,accountType,amount,date,type,CustomerId")] Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transaction);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(DisplayRecord)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Id", transaction.CustomerId);
            return(View(transaction));
        }
        public async Task <IActionResult> Register(Kunde kunde)
        {
            //Sjekker om kundeId-en er i bruk eller om kunden har en bruker fra før
            if (KundeExists(kunde) || _context.Kunder.Any(k => k.Fornavn.Equals(kunde.Fornavn) && k.Etternavn.Equals(kunde.Etternavn)))
            {
                //Console.WriteLine("Kunden eksisterer " + kunde.Id);
                return(BadRequest());
            }
            _context.Add(kunde);
            await _context.SaveChangesAsync();

            return(Ok());
        }
Exemple #27
0
        public async Task <IActionResult> Create([Bind("Id,registerId,firstName,lastName")] Customers customers)
        {
            if (ModelState.IsValid)
            {
                var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                customers.registerId = userId;

                _context.Add(customers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(MyCustomer)));
            }
            return(View(customers));
        }
        public async Task <ActionResult> Insert(BankAccount accountToAdd)
        {
            _dbContext.BankAccount.Add(accountToAdd);
            try
            {
                await _dbContext.SaveChangesAsync(); //IMPORTANT ! COMMIT STATEMENT

                return(Ok());
            }

            catch (Exception e)
            {
                return(StatusCode(500));
            }
        }
        public async Task Handler(TransferCommand command)
        {
            if (command.Amount > 0)
            {
                var accountSender   = _context.Accounts.SingleOrDefault(x => x.AccountId == command.AccountId_Sender);
                var accountReciever = _context.Accounts.SingleOrDefault(x => x.AccountId == command.AccountId_Reciever);

                if (accountSender.Balance >= command.Amount)
                {
                    accountSender.Balance   -= command.Amount;
                    accountReciever.Balance += command.Amount;

                    var transactionCommand = new CreateTransferTransactionCommand()
                    {
                        Amount   = command.Amount,
                        Reciever = accountReciever,
                        Sender   = accountSender
                    };

                    var query = new CreateTransferTransactionHandler().Handler(transactionCommand);

                    await _context.SaveChangesAsync();
                }
                else
                {
                    throw new InsufficientFundsException();
                }
            }
            else
            {
                throw new NegativeAmountException();
            }
        }
Exemple #30
0
        public async Task <ActionResult> Post([FromBody] AddCreditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var exists = await _context.Customers.AnyAsync(x => x.Id == model.CustomerId);

            if (!exists)
            {
                return(NotFound("Customer not found"));
            }

            //TODO use mapper
            var credit = new Credit();

            credit.CustomerId     = model.CustomerId;
            credit.CreditDate     = DateTime.UtcNow;
            credit.Amount         = model.Amount;
            credit.OriginalAmount = model.Amount;
            credit.CreditTerm     = model.CreditTerm;

            _context.Credits.Add(credit);
            await _context.SaveChangesAsync();

            return(StatusCode(201, credit.Id));
        }