Agent Client relationship

I am trying to develop an application where one user (called Agent) after registering with the website can create many clients. I am using MVC5 and ASP.NET Identity. What I want to know is that when Agent is working with a particular client, do I need to store the Client id in session or every time I send the id in query string or something like that to identify the current client on which the agent is working on. I Would really appreciate if someone can guide me in right direction.

SAMPLE CLASSES ARE LIKE THIS

public class Agent
{
  public int UserId{get; set;}
  public ICollection<Client> Clients{get; set;}

  public virtual ApplicationUser User{get; set;}
}

public class Client
{
  public int ClientId{get; set;}
  public string Name{get; set}
  public Address Address{get; set;}
  public Something1 Something1{get; set;}
  public Something2 Something2{get; set;}
  so on....

  public int UserId{get; set;}
  public virtual Agent Agent{get; set;}
}

public class Address
{
  public int ClientId{get; set;}
  public string Line1{get; set}
  public string Line2{get; set}
  public string PostCode{get; set}


  public virtual Client Client{get; set;}
}

Answers


Per REST-guidelines, the client is a resource and should be identified by the URL. For example, /clients/{clientId} for details, /clients/{clientId}/edit to modify, /clients/{clientId}/delete to delete, etc.

Your action would take clientId as a param and then use that to look up the appropriate client. For the user-level permissions, you would simply integrate the user that owns the client object into the query. For example:

var userId = User.Identity.GetUserId();
var client = db.Clients.SingleOrDefault(m => m.UserId == userId && m.ClientId == clientId);
if (client == null)
{
    return new HttpNotFoundResult();
}

// whatever

Need Your Help

How do I receive a json object and files in a multiparty form?

node.js multipartform-data formidable node.js-connect

I'm trying to build an angularJS page that posts a username, password and a profile pic. I'm using a custom fileUpload directive and then then sending both fields and files as a multipart form requ...

Creating A window using x library programming for C programming

c xlib

I am trying to create a window using X11/Xlib in C. My main goal is to make a GUI interface for my program that is below. (Note: I already have attempted to code for the window but it keeps saying ...