Reputation: 199
I am new to C# and I am trying to learn by solving issues . I have a method called StatusController.Check()
that method will return an enum called EnumStatus and an integer called VehicleIdentifier
.
That method works fine, I now call that method in a different class and want to know how can I get the return value of EnumStatus and VehicleIdentifier in the HomeController.Main()
ActionResult
so that I can put it into 2 separate variables .
namespace MyHome.Controllers
{
public class HomeController
{
public ActionResult Main()
{
var getStatus = new StatusController();
getStatus.Check("V2Yq7");
// How can I get the return value of the Check method
// It will return an Enum of type string and an Integer called
// VehicleIdentifier
// I would like to put that values inside the variables below .
var EnumStatus = "";
var VehicleIdentifier = ;
}
}
}
namespace BTree.Controllers
{
public class StatusController : AllStatusController
{
[HttpPost]
public Models.StatusCheck Check(string uniqueID)
{
var statusRepository = new Repository.StatusRepository<StatusModel>();
var myModel = statusRepository.GetStatus(uniqueID);
if (myModel.CurrentStatus == EnumStatus.Sold)
{
var VehicleRepository = new VehicleRepository();
var getVehicle = VehicleRepository.GetVehicle(myModel.MakeID, myModel.IDType);
return new Models.StatusCheck
{
EnumStatus = EnumStatus.Sold,
VehicleIdentifier = getVehicle(Make, uniqueID)
};
}
else
{
return new Models.StatusCheck { EnumStatus = myModel.EnumStatus };
}
}
}
}
Upvotes: 0
Views: 96
Reputation: 19
try to create a class..
project >> Add Class
//set your class to public here
public class yourclassname
{
public static string getStatus
{
get;
set;
}
public static string vehicleIdentifier
{
get;
set;
}
}
And then just simply save the status to your class to hold the values...
yourclassname.getStatus = EnumStatus.Sold; //if it is sold
yourclassname.vehicleIdentifier = getVehicle(Make, uniqueID);
to get or use the values just simply call them
var status = yourclassname.getStatus;
var vehicleIdent = yourclassname.vehicleIdentifier;
Hopee it helps..
Upvotes: 1
Reputation: 33815
You simply assign the result to another variable and then reference that variable instance's properties:
var getStatus = new StatusController();
var statusResult = getStatus.Check("V2Yq7");
var EnumStatus = statusResult.EnumStatus;
var VehicleIdentifier = statusResult.VehicleIdentifier;
Upvotes: 1