Iwaneq / EventsDemo

Demo C# Events project for portfolio.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C#_Events_Demo

EventsDemo

Demo project that shows usage of C# Events made for portfolio.

image

How it works

We have two forms - one, main, that represents our Account, and one that represents some kind of shop. If you buy something from shop, you will send data from form, to AccountModel class, where ProductModel will be validated. Next, AccountModel will raise events:

  • If it's valid - TransactionApprovedEvent, wich will start simulation of buying
  • If it's not valid - ProductValidationErrorEvent, wich will show error messages in both forms
  • And UpdateProcessInfoEvent if transaction was approved, to show precentage progress info

image

image

What I used?

To write that project I used C#, with .NET Framework and WinForms. There are some async methods and... events of course ;pp

Some examples of code snippets from project:

private async Task SimulateBuying()
{
    for (int i = 0; i < 10; i++)
    {
        UpdateProcessInfoEvent?.Invoke(this, $"Buying process - {i * 10}%");
        await Task.Delay(500);
    }
    UpdateProcessInfoEvent?.Invoke(this, $"Buying process have been completed!");
}
private void Account_ProductValidationErrorEvent(object sender, string e)
{ 
    errorMessage.Text = e;
    errorMessage.Visible = true;

    buyButton.Enabled = true;
}

About

Demo C# Events project for portfolio.


Languages

Language:C# 100.0%