Thanks. will definitely do some research on Web API.
Web API Is Really easy to use, here is a simple example of a method we use in one of our apps in C# ( I have removed our custom error-handling)
Something to note if you've used MVC you will be familiar with but if not the _userRepository interface has been injected into the class
Code:
[Route("GetUser/{tenantId:int}/{tenantName}/{userName}")]
[HttpGet]
public Result<User> GetUser(int tenantId, string tenantName, string userName)
{
Result<User> result = new Result<User>();
try
{
result = _userRepository.GetUser(tenantId, tenantName, userName);
}
catch (Exception ex)
{
}
return result;
}
In this particular app we are using Entity framework so the data call looks like this -
Code:
public Result<User> GetUser(int tenantId, string tenantName, string userName)
{
var result = new Result<User>();
try
{
using (WebBundleDbEntities webBundleContext = Common.GetConnection(tenantId))
{
var userDetails = webBundleContext.csp_web_GetUserFromSystemName(userName).FirstOrDefault();
if (userDetails != null)
{
var data = new User()
{
Id = userDetails.ID,
Name = userDetails.Name,
SystemName = userDetails.System_Name,
TenantId = tenantId,
TenantName = tenantName
};
result.Data = data;
result.IsSuccess = true;
}
else
result.Message = Resource.msgUserDoesNotExist;
}
}
catch (Exception ex)
{
}
return result;
}
We are using a Model called User which is just a class with properties in it and then a class called Result which encapsulates all our return objects and allows us to return some other information alongside the data such as if the call was successful and any error messages
Code:
public class Result<TEntity>
{
public Result()
{
IsSuccess = false;
Message = string.Empty;
Count = 0;
}
public bool IsSuccess { get; set; }
public string Message { get; set; }
public TEntity Data { get; set; }
public int Count { get; set; }
public Exception Exception { get; set; }
}