Preshen99 / EasyGames

Post-Interview Assessment
0 stars 0 forks source link

Dynamic Balance #3

Closed Preshen99 closed 1 year ago

Preshen99 commented 1 year ago

Problem: Trying to update the ClientBalance in the Client DB was the hardest issue to try and resolve, currently not resolved either.

Issues Faced:

  1. Added a change to a single field in a db table that holds both foreign and primary keys, returns validation issues
  2. Using the same method as an edit method returns the same validation issue when parsing SaveChanges() method

Solutions Tested:

  1. Summing value by grouping in Client ID's
  2. Saving sum in variable and updating specific record in table with the variable value
  3. Checking db.Clients where ClientID is the same as id parsed through transaction creation
  4. Creating variable of sum of selected value from db.transactions.amount
  5. Using the following methods to try and parse value into the db table: db.clients.append, db.entry(client).state, db.savechanges() : standalone
  6. Using the Transactions: Create, Edit fields to append data into table
  7. Using a sperate method: Sum() to run before going to Index() to append data

Solution:

  1. Still in the process of finding it...
Preshen99 commented 1 year ago

Issue Solved!

Create Transaction Create Add _[Bind(Include = "table_columns")] to Action Result Parameter Create and Save Transaction first with db.Add and db.SaveChanges()_ Create the variables for the following:

  1. Temp Variable for finding records with association to ClientID
  2. Client ID
  3. Client Name
  4. Client Surname
  5. Client Balance
  6. Amount: For amount of current Transaction
  7. New Balance: Adding Amount to old Client Balance

Update and Save Client Table with the new data: db.Entry(client).State = EntityState.Modified and db.SaveChanges()

Edit Transaction Edit Add _[Bind(Include = "table_columns")]_ to Action Result Parameter Create Variable for the Transaction Amount prior to being edited: decimal preAmount NOTE: Variable create before checking ModelState. This has not been tested within the ModelState. Create Variable for the following:

  1. Transaction Amount Post Edit
  2. Difference in Amount between Pre and Post Transaction Amounts (Make sure Post is Subtracted from Pre Value)
  3. Temp Variable for finding records with association to ClientID
  4. Client ID
  5. Client Name
  6. Client Surname
  7. Client Balance

Create an IF Statement to check if Transaction Amounts are the same. Else Subtract Calculated Amount (No.2) from Client Balance Update and Save Client Table with the new data: db.Entry(client).State = EntityState.Modified and db.SaveChanges()

Delete Transaction Delete Add _[Bind(Include = "table_columns")]_ to Action Result Parameter Create the variables for the following:

  1. Temp Variable for finding records with association to ClientID
  2. Client ID
  3. Client Name
  4. Client Surname
  5. Client Balance
  6. Amount: From Transaction being Deleted
  7. New Balance: Subtract Amount from Client Balance

Update Client Table, Delete Transaction, Save Changes: db.Entry(client).State = EntityState.Modified , db.table_object.Remove(table_variable) , and db.SaveChanges()