Git Product home page Git Product logo

expense-manager's Introduction

Hi ๐Ÿ‘‹, I'm Santosh Kumar!

Passionate Developer from India

My Website - Here

  • ๐Ÿ”ญ Iโ€™m currently working on Gaming community website : GamersDash

  • ๐Ÿ’ฌ Ask me about C#, react, javascript, html, css

  • ๐Ÿ“ซ How to reach me : [email protected]

  • โšก Fun fact I love watching anime

Connect with me:

santosh kumar metikoti santosh-kumar

Languages and Tools:

arduino bootstrap css3 html5 javascript jest nodejs photoshop postman react reactnative redux

ย santosh-kumar-metikoti

santosh-kumar-metikoti

expense-manager's People

Contributors

santosh-kumar-metikoti avatar

Watchers

 avatar  avatar

expense-manager's Issues

Create one class per file

Create one class per file. This will allow for easy navigation. Currently you have put 2 classes in the Dropdownlist.cs file. This should instead of split into multiple files based on the classes they contain.

Do not abbreviate anything

I see that there are a bunch of abbreviations that you have used - Accid for AccountId, AccName for AccountName and Acclist for AccountList.

You write code so that someone else might be able to read it

Abbreviations are usually done when we as the programmer assumes something. But this assumption might not be totally obvious to the person reading your code.

As a programmer, one of the strongest skills you can develop is to name your variables properly -- your future self and your co-workers will find it very easy to understand your code.


Please change this wherever required.

Avoid using explicit names for dapper parameters when the parameter name and the substitution name are the same

Consider this query that you have written:

var query = connection.Execute(@"INSERT INTO transaction(account_id,amount,date,note)
                        SELECT a.account_id,@amount, @date, @note
                        FROM account AS a
                        WHERE a.account_name=@account", new { amount = amount, date = date, note=note, account=account});

Here, your substitutions are amount, date, note and account. For which the query parameters are of the same name. In such a case C# allows you to use the variable name directly instead of specifying it again in the anonymous class

So you can write this as

var query = connection.Execute(@"...", new { amount, date, note, account })

Read more about Anonymous classes here. They will be used widely in production code.

Use a single connection and command for AllTransactionsList

In HomeController.AllTransactionsList, I see that you have used multiple connections for making the different queries. Accordingly you have used multiple readers, and multiple command objects.

All this can be done with a single connection, reader and command object called sequentially one after another.

Use Verbatim strings for multiline strings

Currently multiline strings are being separated by closing one line and using the + operator to concatenate. When we are writing queries that are long, this option will become hard to maintain.

C# has an easier way to do this using the Verbatim Literal - @. Read about it here and use it instead of concatenation.

Use Prepared Statements

Using string.Format is definitely one way of doing substitution in SQL queries, but such an operation is still open to SQL Injection. The right way to do something like this that is protected from SQL Injection is to use "prepared statements".

Here is some documentation of how to do it with Npgsql. Please change all queries to use prepared statements instead of string.Format

Use a gitignore

There are a lot of unnecessary files being committed into the repository. Use a proper .gitignore file and refresh the repository so that only the code is committed.

Choose to return a strongly typed object instead of returning a data table or a data set

I see here: https://github.com/santosh-kumar-metikoti/Expense-Manager/blob/main/WebApplication4/Controllers/HomeController.cs#L37 and in other places that you have chosen to return a data set or a data table.

While this is OK, a better approach would be to return a model that is strongly typed instead. For example, in the Index() action of the controller, you want to return a list of transactions, so I would choose to do something like this:

public class TransactionsViewModel
{
  public List<Transaction> Transactions {get; set;}
}

public class Transaction
{
  public string Account { get; set; }
  // other fields
}

and populate Transactions accordingly based on what you retrieve from the Data Set.

The advantage with that is that the contract between your action and your view is a strict contract at this time. This means that any change on either side will throw compiler errors. Currently you are using: https://github.com/santosh-kumar-metikoti/Expense-Manager/blob/main/WebApplication4/Views/Home/Index.cshtml#L45-L53 a string in order to retrieve information from each row (@row["account"]) - this is error prone because if someone misspells the word account then we will only know at runtime instead of at compile time.

In the case of using a model, this would look like:

<td>@Model.Account</td>

Which is checked at compile time โœ”๏ธ


Please change all your actions to return Models instead of returning Data Table / Data Set

Note

There will be an additional looping through the data set / table in order to populate the list, but we will deal with that shortly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.