示例#1
0
        /// <summary>
        /// Transfer cash between two card and update their balance.
        /// Default transfer it is withdraw cash.
        /// </summary>
        /// <param name="amount"></param>
        /// <param name="secondCard"></param>
        /// <returns></returns>
        public bool TrunsferCash(decimal amount, string secondCard = Constants.ATM)
        {
            Card inCard  = _context.Cards.FirstOrDefault(x => x.CardId == secondCard);
            Card outCard = _context.Cards.FirstOrDefault(x => x.CardId == _cardsService.CurrentCardNumber);

            OperationsDetails inOperationDetails  = new OperationsDetails();
            OperationsDetails outOperationDetails = new OperationsDetails();

            Operations operation = new Operations()
            {
                Amount             = amount,
                InCard             = inCard,
                InId               = secondCard,
                OutCard            = outCard,
                OutId              = _cardsService.CurrentCardNumber,
                OperationDetailses = new List <OperationsDetails>()
                {
                    inOperationDetails,
                    outOperationDetails
                }
            };

            inOperationDetails.Operations     = operation;
            inOperationDetails.Amount         = amount;
            inOperationDetails.Balance        = inCard.Ballance + amount;
            inOperationDetails.OperationsType = _context.OperationsType.First(x => x.ID == 1);

            outOperationDetails.Operations     = operation;
            outOperationDetails.Amount         = amount;
            outOperationDetails.Balance        = outCard.Ballance - amount;
            outOperationDetails.OperationsType = _context.OperationsType.First(x => x.ID == 2);

            inCard.Ballance  += amount;
            outCard.Ballance -= amount;

            _context.Cards.Attach(inCard);
            _context.Cards.Attach(outCard);
            _context.Entry(inCard).State  = EntityState.Modified;
            _context.Entry(outCard).State = EntityState.Modified;

            try
            {
                _context.Operations.Add(operation);
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
        public void RecalculateBallance(string cardNo)
        {
            using (var ctx = new BankDbContext())
            {
                var card = ctx.Cards.SingleOrDefault(c => c.CardId == cardNo);

                ctx.Entry(card).Collection(c => c.InOperations).Load();
                ctx.Entry(card).Collection(c => c.OutOperations).Load();

                card.Ballance = card.InOperations.Sum(o => o.Amount) - card.OutOperations.Sum(o => o.Amount);

                ctx.SaveChanges();
            }
        }
        public override void Update(Client entity)
        {
            var client = entity ?? throw new ArgumentNullException(nameof(entity));
            var local  = _db.Set <Client>()
                         .Local
                         .FirstOrDefault(f => f.ClientId == entity.ClientId);

            if (local != null)
            {
                _db.Entry(local).State = EntityState.Detached;
            }
            _db.Entry(client).State = EntityState.Modified;
            _db.SaveChanges();
        }
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#5
0
        public async Task <IActionResult> PutBank([FromRoute] int id, [FromBody] Bank bank)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
示例#6
0
 public bool DeleteAccount(long id)
 {
     using (var db = new BankDbContext())
     {
         Account account = db.Account.FirstOrDefault(x => x.Id == id);
         account.Active          = false;
         db.Entry(account).State = EntityState.Modified;
         db.SaveChanges();
         return(true);
     }
 }
        public bool DeleteCustomer(long id)
        {
            using (var db = new BankDbContext())
            {
                var customer = db.Customer.FirstOrDefault(x => x.ID == id);

                customer.Active          = false;
                db.Entry(customer).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(true);
        }
示例#8
0
        public IHttpActionResult EditClient(int id, [FromBody] Client client)
        {
            if (client == null)
            {
                return(BadRequest());
            }

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

            _db.Entry(client);
            _db.SaveChanges();
            return(Ok());
        }
示例#9
0
 public ActionResult Edit([Bind(Include = "Id,Nom,Adresse,MatriculFiscal")] PersonneMorale personneMorale)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _db.Entry(personneMorale).State = EntityState.Modified;
             _db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(personneMorale));
     }
     catch (Exception)
     {
         return(RedirectToAction("Error"));
     }
 }
 public ActionResult Edit([Bind(Include = "OperationId,Type,Montant,Date,CompteId")] Operation operation)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _db.Entry(operation).State = EntityState.Modified;
             _db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.CompteId = new SelectList(_db.Comptes, "CompteId", "CompteId", operation.CompteId);
         return(View(operation));
     }
     catch (Exception)
     {
         return(RedirectToAction("Error"));
     }
 }
示例#11
0
 public ActionResult Edit(
     [Bind(Include = "Id,Nom,Adresse,Prénom,Cin,Profession,Telephone,Salaire")] PersonnePhysique personnePhysique)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _db.Entry(personnePhysique).State = EntityState.Modified;
             _db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(personnePhysique));
     }
     catch (Exception)
     {
         return(RedirectToAction("Error"));
     }
 }
 public ActionResult Edit([Bind(Include = "CompteId,ClientId,Type,SoldeBase,DateOuverture")] Compte compte)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _db.Entry(compte).State = EntityState.Modified;
             _db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.ClientId = new SelectList(_db.Clients, "Id", "Nom", compte.ClientId);
         return(View(compte));
     }
     catch (Exception)
     {
         return(RedirectToAction("Error"));
     }
 }
        //need updation
        public void UpdateCustomer(CustomerDTO customerDTO)
        {
            using (var db = new BankDbContext())
            {
                //TODO : Use Automapper here;

                var customer = db.Customer.FirstOrDefault(x => x.ID == customerDTO.ID);
                //  customer =  Mapper.Map<CustomerDTO,Customer>(customerDTO, MappingProfile.ConfigureMap);
                customer.City            = customerDTO.City;
                customer.AddressLine1    = customerDTO.AddressLine1;
                customer.AddressLine2    = customerDTO.AddressLine2;
                customer.State           = customerDTO.State;
                customer.SSNID           = customerDTO.SSNID;
                customer.Name            = customerDTO.Name;
                customer.DOB             = customerDTO.DOB;
                db.Entry(customer).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
 public ActionResult Edit(
     [Bind(Include = "CreditId,MontantCredit,Planification,PayementMonsuel,ClientId")] Credit credit)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _db.Entry(credit).State = EntityState.Modified;
             _db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.ClientId = new SelectList(_db.Clients, "Id", "Nom", credit.ClientId);
         return(View(credit));
     }
     catch (Exception)
     {
         return(RedirectToAction("Error"));
     }
 }
        public void Withdraw(long accountId, int amount, string comments = "Withdraw")
        {// use transactions
            using (var db = new BankDbContext())
            {
                var account = db.Account.FirstOrDefault(x => x.Id == accountId);

                account.Balance -= amount;
                var transaction = new Transaction()
                {
                    Balance         = account.Balance,
                    Withdraw        = amount,
                    TransactionType = "Cr",
                    Comments        = comments,
                    AccountID       = accountId,
                    TransactionDTTM = DateTime.Now
                };

                db.Entry(account).State = System.Data.Entity.EntityState.Modified;
                db.Transaction.Add(transaction);
                db.SaveChanges();
            }
        }
示例#16
0
 public void Update(Transaction entity)
 {
     db.Entry(entity).State = EntityState.Modified;
 }
示例#17
0
 public async Task UpdateAsync(T obj)
 {
     _context.Entry(obj).State = EntityState.Modified;
     await SaveAsync();
 }