public async Task <IActionResult> PutCustomer(long id, Customer customer) { if (id != customer.CustomerId) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUnit(int id, Unit unit) { if (id != unit.UnitId) { return(BadRequest()); } _context.Entry(unit).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UnitExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBankInfo(int id, BankInfo bankInfo) { if (id != bankInfo.Id) { return(BadRequest()); } _context.Entry(bankInfo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BankInfoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutRole(long id, Role role) { if (id != role.Id) { return(BadRequest()); } _context.Entry(role).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutInventory(long id, Inventory inventory) { if (id != inventory.InventoryId) { return(BadRequest()); } _context.Entry(inventory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InventoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutFabricPurchaseItem(long id, FabricPurchaseItem fabricPurchaseItem) { if (id != fabricPurchaseItem.FabricPurchaseItemId) { return(BadRequest()); } _context.Entry(fabricPurchaseItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FabricPurchaseItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutTblAccount(long id, TblAccount tblAccount) { if (id != tblAccount.AccountId) { return(BadRequest()); } _context.Entry(tblAccount).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblAccountExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAccountTransaction(long id, AccountTransaction accountTransaction) { if (id != accountTransaction.AccountTransactionId) { return(BadRequest()); } _context.Entry(accountTransaction).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountTransactionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSaleContractItem(long id, SaleContractItem saleContractItem) { if (id != saleContractItem.SaleContractItemId) { return(BadRequest()); } _context.Entry(saleContractItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SaleContractItemExists(id)) { return(NotFound()); } else { throw; } } var allSaleContractItems = _context.SaleContractItems.Where(x => x.SaleContractId == saleContractItem.SaleContractId).ToList(); var saleContract = await _context.SaleContracts.FindAsync(saleContractItem.SaleContractId); saleContract.TotalAmount = 0; foreach (var item in allSaleContractItems) { saleContract.TotalAmount = saleContract.TotalAmount + item.Amount; } decimal?TotalFabric = 0; foreach (var item in allSaleContractItems) { TotalFabric = TotalFabric + item.Quantity; } saleContract.TotalFabric = TotalFabric.ToString(); _context.Entry(saleContract).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SaleContractItemExists(id)) { return(NotFound()); } else { throw; } } // Get Receivable and Add Credit Entry in Account var receivableExist = _context.Receivables.Where(x => x.CustomerId == saleContract.CustomerId).FirstOrDefault(); var payableExist = _context.Payables.Where(x => x.PayableName == saleContract.SaleContractNumber && x.IsActive == true).FirstOrDefault(); var tblAccountReceivable = _context.TblAccounts.Where(x => x.ReceivablesId == receivableExist.ReceivableId).FirstOrDefault(); var tblAccountSaleContractExist = _context.TblAccounts.Where(x => x.AccountCode == saleContract.SaleContractNumber && x.PayableId == payableExist.PayableId).FirstOrDefault(); // Add Double Entry of Receivable (DR) and Sale Contract Account (CR) => Update only Amount Debit and Credit var accountTransaction = _context.AccountTransactions.Where(x => x.AccountDebitId == tblAccountReceivable.AccountId && x.AccountCreditId == tblAccountSaleContractExist.AccountId && x.AccountCreditCode == tblAccountSaleContractExist.AccountCode).FirstOrDefault(); accountTransaction.AmountDebit = saleContract.TotalAmount; accountTransaction.AmountCredit = saleContract.TotalAmount; _context.Entry(accountTransaction).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SaleContractItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutFabricPurchase(long id, FabricPurchase fabricPurchase) { if (id != fabricPurchase.FabricPurchaseId) { return(BadRequest()); } _context.Entry(fabricPurchase).State = EntityState.Modified; try { await _context.SaveChangesAsync(); var payableExist = _context.Payables.Where(x => x.PayableId == fabricPurchase.Weaver && x.IsActive == true).FirstOrDefault(); if (payableExist != null) { var tblAccountPayableExist = _context.TblAccounts.Where(x => x.AccountCode == payableExist.PayableId.ToString() && x.AccountTitle == payableExist.PayableName && x.PayableId == payableExist.PayableId).FirstOrDefault(); if (tblAccountPayableExist != null) { var tblAccountSaleContractExist = _context.TblAccounts.Where(x => x.AccountCode == fabricPurchase.SaleContractNumber).FirstOrDefault(); // Edit Double Entry of Payable (CR) and Sale Contract Account (DR) var accountTransactionExist = _context.AccountTransactions.Where(x => x.AccountCreditCode == tblAccountPayableExist.AccountCode && x.AccountCreditId == tblAccountPayableExist.AccountId && x.Type == _context.TransactionTypes.Where(x => x.TransactionTypeName == "FabricPurchase").Select(x => x.TransactionTypeId).FirstOrDefault()).FirstOrDefault(); accountTransactionExist.Type = _context.TransactionTypes.Where(x => x.TransactionTypeName == "FabricPurchase").Select(x => x.TransactionTypeId).FirstOrDefault(); //accountTransactionExist.AccountDebitId = tblAccountSaleContractExist.AccountId; //accountTransactionExist.AccountCreditId = tblAccountPayableExist.AccountId; //accountTransactionExist.AccountDebitCode = tblAccountSaleContractExist.AccountCode; //accountTransactionExist.AccountCreditCode = tblAccountPayableExist.AccountCode; accountTransactionExist.Narration = "Fabric Purchase Contract Update"; accountTransactionExist.AmountDebit = fabricPurchase.QuantityInMeters * fabricPurchase.PerMeterRate; accountTransactionExist.AmountCredit = fabricPurchase.QuantityInMeters * fabricPurchase.PerMeterRate; //accountTransactionExist.SaleContractNumber = fabricPurchase.SaleContractNumber; accountTransactionExist.DateUpdated = DateTime.Now; accountTransactionExist.IsActive = true; _context.Entry(accountTransactionExist).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (Exception ex) { var x = 0; } } } } catch (DbUpdateConcurrencyException) { if (!FabricPurchaseExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSaleContractExpense(long id, SaleContractExpense saleContractExpense) { if (id != saleContractExpense.ExpenseId) { return(BadRequest()); } _context.Entry(saleContractExpense).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SaleContractExpenseExists(id)) { return(NotFound()); } else { throw; } } var saleContractAccountExist = _context.TblAccounts.Where(x => x.AccountCode == saleContractExpense.SaleContractNumber).FirstOrDefault(); var paymentSourceAccountExist = _context.TblAccounts.Where(x => x.AccountId == saleContractExpense.PaymentSourceAccountId).FirstOrDefault(); if (saleContractAccountExist != null) { var saleContractAccountTransactionExist = _context.AccountTransactions.Where(x => x.AccountDebitId == saleContractAccountExist.AccountId && x.AccountCreditId == paymentSourceAccountExist.AccountId).FirstOrDefault(); if (saleContractAccountTransactionExist != null) { saleContractAccountTransactionExist.Type = _context.TransactionTypes.Where(x => x.TransactionTypeName == "SaleContractExpense").Select(x => x.TransactionTypeId).FirstOrDefault(); saleContractAccountTransactionExist.AccountDebitId = saleContractAccountExist.AccountId; saleContractAccountTransactionExist.AccountCreditId = paymentSourceAccountExist.AccountId; saleContractAccountTransactionExist.AccountDebitCode = saleContractAccountExist.AccountCode; saleContractAccountTransactionExist.AccountCreditCode = paymentSourceAccountExist.AccountCode; saleContractAccountTransactionExist.Narration = saleContractExpense.Description; saleContractAccountTransactionExist.AmountDebit = saleContractExpense.Amount; saleContractAccountTransactionExist.AmountCredit = saleContractExpense.Amount; saleContractAccountTransactionExist.SaleContractNumber = saleContractExpense.SaleContractNumber; saleContractAccountTransactionExist.DateAdded = DateTime.Now; saleContractAccountTransactionExist.IsActive = true; _context.Entry(saleContractAccountTransactionExist).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (Exception ex) { var x = 0; } } else { // Add Double Entry of Sale Contract Account (DR) and Cash/Bank Account (CR) AccountTransaction accountTransaction = new AccountTransaction() { Type = _context.TransactionTypes.Where(x => x.TransactionTypeName == "SaleContractExpense").Select(x => x.TransactionTypeId).FirstOrDefault(), AccountDebitId = saleContractAccountExist.AccountId, AccountCreditId = paymentSourceAccountExist.AccountId, AccountDebitCode = saleContractAccountExist.AccountCode, AccountCreditCode = paymentSourceAccountExist.AccountCode, Narration = saleContractExpense.Description, AmountDebit = saleContractExpense.Amount, AmountCredit = saleContractExpense.Amount, SaleContractNumber = saleContractExpense.SaleContractNumber, DateAdded = DateTime.Now, IsActive = true }; _context.AccountTransactions.Add(accountTransaction); try { await _context.SaveChangesAsync(); } catch (Exception ex) { var x = 0; } } } return(NoContent()); }
public async Task <IActionResult> PutSaleContract(long id, SaleContract saleContract) { if (id != saleContract.SaleContractId) { return(BadRequest()); } _context.Entry(saleContract).State = EntityState.Modified; try { await _context.SaveChangesAsync(); var receivableExist = _context.Receivables.Where(x => x.CustomerId == saleContract.CustomerId && x.IsActive == true).FirstOrDefault(); var payableExist = _context.Payables.Where(x => x.PayableName == saleContract.SaleContractNumber && x.IsActive == true).FirstOrDefault(); if (receivableExist != null) { var tblAccountSaleContractExist = _context.TblAccounts.Where(x => x.AccountCode == saleContract.SaleContractNumber && x.PayableId == payableExist.PayableId).FirstOrDefault(); // Edit Sale Contract Account tblAccountSaleContractExist.AccountCode = saleContract.SaleContractNumber; tblAccountSaleContractExist.AccountDescription = saleContract.SaleContractNumber; tblAccountSaleContractExist.AccountTitle = saleContract.SaleContractNumber; tblAccountSaleContractExist.AccountTypeId = _context.AccountTypes.Where(x => x.AccountTypeName == "Liabilities").Select(x => x.AccountTypeId).FirstOrDefault(); tblAccountSaleContractExist.DateAdded = DateTime.Now; tblAccountSaleContractExist.IsActive = true; tblAccountSaleContractExist.PayableId = payableExist.PayableId; _context.Entry(tblAccountSaleContractExist).State = EntityState.Modified; await _context.SaveChangesAsync(); var tblAccountReceivable = _context.TblAccounts.Where(x => x.AccountCode == receivableExist.ReceivableId.ToString() && x.AccountTitle == receivableExist.ReceivableName && x.ReceivablesId == receivableExist.ReceivableId).FirstOrDefault(); // Edit Double Entry of Receivable (DR) and Sale Contract Account (CR) var accountTransactionExist = _context.AccountTransactions.Where(x => x.AccountCreditCode == tblAccountSaleContractExist.AccountCode && x.AccountCreditId == tblAccountSaleContractExist.AccountId && x.Type == _context.TransactionTypes.Where(x => x.TransactionTypeName == "SalesContract").Select(x => x.TransactionTypeId).FirstOrDefault()).FirstOrDefault(); accountTransactionExist.Type = _context.TransactionTypes.Where(x => x.TransactionTypeName == "SalesContract").Select(x => x.TransactionTypeId).FirstOrDefault(); accountTransactionExist.AccountDebitId = tblAccountReceivable.AccountId; accountTransactionExist.AccountCreditId = tblAccountSaleContractExist.AccountId; accountTransactionExist.AccountDebitCode = tblAccountReceivable.AccountCode; accountTransactionExist.AccountCreditCode = tblAccountSaleContractExist.AccountCode; accountTransactionExist.Narration = "Sale Contract Creation"; accountTransactionExist.AmountDebit = saleContract.TotalAmount; accountTransactionExist.AmountCredit = saleContract.TotalAmount; accountTransactionExist.SaleContractNumber = saleContract.SaleContractNumber; accountTransactionExist.DateUpdated = DateTime.Now; accountTransactionExist.IsActive = true; _context.Entry(accountTransactionExist).State = EntityState.Modified; await _context.SaveChangesAsync(); //AccountTransaction accountTransaction = new AccountTransaction() //{ // Type = _context.TransactionTypes.Where(x => x.TransactionTypeName == "SalesContract").Select(x => x.TransactionTypeId).FirstOrDefault(), // AccountDebitId = tblAccountReceivable.AccountId, // AccountCreditId = tblAccountSaleContract.AccountId, // AccountDebitCode = tblAccountReceivable.AccountCode, // AccountCreditCode = tblAccountSaleContract.AccountCode, // Narration = "Sale Contract Creation", // AmountDebit = saleContract.TotalAmount, // AmountCredit = saleContract.TotalAmount, // SaleContractNumber = saleContract.SaleContractNumber, // DateAdded = DateTime.Now, // IsActive = true //}; } } catch (DbUpdateConcurrencyException) { if (!SaleContractExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }