codeprada's Profile User Rating: *****

Reputation: 962 Master
Active Posts:
2,395 (1.26 per day)
15-February 11
Profile Views:
Last Active:
User is offline Apr 29 2016 04:16 AM

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Favorite Gaming Platform:
Your Car:
Who Cares
Dream Kudos:
Expert In:

Latest Visitors

Icon   codeprada has not set their status

Posts I've Made

  1. In Topic: c# wpf listview binding

    Posted 27 Apr 2016


    Why not utilize the SelectedItem of ListView?

    <ListView SelectedItem="{Binding CurrentItem}" ItemsSource="{Binding Items}" ..... >
    //backend code - using generic type for example purposes
    public ObservableCollection<T> Items { get; set; };
    public T CurrentItem { get; set; } //this item will hold the currently selected item

    If you wish to change the selected item in any way then you simply need to alter/modify the CurrentItem property. There would be no need to create an entirely new object.
    CurrentItem.Status += 5; //alter property however you like
  2. In Topic: Sub / Nested View and Controllers?

    Posted 26 Apr 2016

    Regardless if the entities are different they should be in the same context because both entities are related to each other.

    You don't want to turn Resource into a string type because they will vastly limit your application and also you'll have to do a complete redesign if you needed to add another parameter to Resource apart from it's name.

    public class MyApplicationDbContext : DbContext //Notice it's one DbContext
    	public DbSet<Agent> Agents { get; set; }
    	public DbSet<Resource> Resources { get; set; }
    public class Resource 
    	/* Properties Here */	
    public class Agent
    	/* Properties Here */

    I'd suggest you check out a few tutorials on Entity Framework to get an understanding of it works. Have a look at this one -> Introduction to Entity Framework Code First
  3. In Topic: Sub / Nested View and Controllers?

    Posted 26 Apr 2016


    Firstly if the project requires Entity Framework then you should install it. You should be able to restore NuGet packages. Try building the project. By default Visual Studio should download any missing NuGet packages.
    N.B. That tutorial requires Entity Framework.

    From what you're explaining here it seems as though Agent and Resource have a one to many relationship (one agent can have many resources but a resource can only have one agent). Your DbContext needs to be altered to support such. I've never used two contexts with the intent to create a relationship spanning across the two. I can already see that this will complicate your application if it's possible it will work.

    Have a look at this
    public class Project
    	public int Id { get; set; }
    	public string Name { get; set;}
    	public int CoderId { get; set; }
    	[ForeignKey("CoderId")] //links project to coder
    	public Coder Coder { get; set; } //let's just say that each project can have a single coder
    public class Coder 
    	public int Id { get; set; }
    	public string Username { get; set; }
    	public ICollection<Project> Projects { get; set; }
    public class OrganizationDbContext: DbContext
    	public DbSet<Project> Projects { get; set; }
    	public DbSet<Coder> Coders { get; set; }

    Now is how you'll create a coder and a project with the foreign key relationship intact.
    using (var context = new OrganizationDbContext())
    	var coder = context.Coders.Add(new Coder()
    		Username = "randomguy" // Id is generate automatically since it's the primary key
    	context.SaveChanges(); // save changes to get the primary key for coder for later use
    	context.Projects.Add(new Project()
    		Name = "Hack The World, Idk",
    		CoderId = coder.Id; // this is important. Without a valid primary key then EF will give you an error

    Notice I'm using a single DbContext in my sample code. Now if I wanted to add a list of projects to a coder (similar to what you want to do in terms of your resources and agent) I'll only need to set the CoderId property of a project.
  4. In Topic: Non static class contains self static reference

    Posted 24 Apr 2016


    You're actually only instantiating a single instance of GuestRepository. The only line that instantiates GuestRepository is
    private static GuestRepository repository = new GuestRepository();

    No matter how many times you may call GuestRepository.GetRepository(); you'll receive the same instance unless you explicitly create a new instance. This means that r2 and r1 reference the same object. Try this:
    Make a change to r2 and a different change to r1 and then print out the values to the screen and compare the results.

    For learning purposes here's another way to approach the singleton methodology.
    public class GuestRepository
    	private static GuestRepository _instance; //stores an instance of GuestRepository that can only be instantiated internally
    	public static GuestRepository Instance //this could be a method as well
    			//if _instance is null then instantiate it
    			return _instance ?? (_instance = new GuestRepository()); //returns a single instance of GuestRepository
    	//The constructor must be private so that GuestRepository cannot be instantiated from the outside
    	private GuestRepository()
    		//constructor code here
    	 * Other code ... public non-static methods and so forth
  5. In Topic: Transfer money between accounts & unit test

    Posted 20 Apr 2016


    To perform unit tests you must control the inputs to the method you want to test. It appears as though this method is apart of a class. Here's a simple unit test you can learn from.

    public class Calculator
    	/// <summary>
    	/// Method that divides a by b (a/B)/>/>/>
    	/// </summary>
    	/// <param name="a">a</param>
    	/// <param name="b">b</param>
    	/// <returns>Quotient</returns>
    	public double Divide(double a, double B)/>/>/>
    		if(b == 0)
    			throw new DivideByZeroException();
    		return a / b;
    //NUnit Test
    [ExpectedException(typeof(DivideByZeroException))] // let's the unit test runner know that an exception should be thrown
    public void Divide_Calculator_ThrowsException()
    	var calculator = new Calculator();
    	calculator.Divide(5, 0); //this line will throw an exception. This is what we want
    	// The unit test expects an exception to be thrown
    	// If an exception is not thrown then the test fails
    	// A unit test has only one of two outcomes if it completes and that's pass or fail

    Apply the same logic to your code now. Instantiate your class and invoke the TransferFund method.

My Information

Member Title:
Changed Man With Different Priorities
25 years old
February 13, 1991
My girlfriend,
Staying fit,
Football (Soccer),
Years Programming:
Programming Languages:


Contact Information

Website URL:
Website URL


Page 1 of 1
  1. Photo

    jesicalbaby Icon

    16 Sep 2013 - 14:40
    My name is Miss jesical,
    i saw your profile today
    and,i fill more interest to contact you ,
    i will like you to please send me
    an email via ([email protected])
    for me to send you my picture
    [email protected]
  2. Photo

    defiance Icon

    22 Feb 2012 - 14:47
    codeprada when you have time please read your priv mail :)
  3. Photo

    Jstall Icon

    31 Jan 2012 - 06:12
    Congrats on the promotion! Very very well deserved dude.
  4. Photo

    smohd Icon

    31 Jan 2012 - 03:59
    Welcome to the club! Now its my time to welcome you :)
  5. Photo

    smohd Icon

    30 Oct 2011 - 12:52
    Thanks mate, Looks cool... I missed my experts club ;)
    But you seem to be busy these days.
  6. Photo

    RudiVisser Icon

    05 Sep 2011 - 04:32
    Thanks :)
  7. Photo

    RudiVisser Icon

    05 Aug 2011 - 10:11
    Thanking you - Once I've finished off the 2x CMS Tutorials + got time to spend on more daily articles I think it will be even better! Just can't keep updating my signature with every single one :D
  8. Photo

    smohd Icon

    03 Jul 2011 - 09:37
  9. Photo

    smohd Icon

    20 Jun 2011 - 14:43
    I see it now, nice work :)
  10. Photo

    smohd Icon

    20 Jun 2011 - 11:49
    Hi, but everytime I see you online helping, why they remove it from you? Did they mention any reason? or just system error?
  11. Photo

    smohd Icon

    20 Jun 2011 - 11:17
    Hey, what happens to expert badge?
  12. Photo

    codeprada Icon

    16 Jun 2011 - 03:36
    Thanks, so the link's been doing it's job :)
  13. Photo

    Ace26 Icon

    16 Jun 2011 - 01:53
    Hey there, howdy? I like one of your signature links that says hell is real. Are you a believer in Jesus Christ as your Lord and personal saviour?
    If yes then I'd say keep up the good work and stay strong in the faith, my brother in the Lord.
    Nice to meet a fellow christian geek.
  14. Photo

    Vip3rousmango Icon

    13 Apr 2011 - 12:12
    Thanks for the rep! :)
Page 1 of 1