public ActionResult AddAgent(int agentID = 0) { LandlordAgent landlordAgent = new LandlordAgent(); landlordAgent.Type = Associations.GetLoginRole(LoginRole.Agent); if (agentID > 0) { LandlordAgentResponse landlordAgentResponse = ApiWrapper.Get<LandlordAgentResponse>("api/landlordagent/" + agentID); UserResponse userResponse = userResponse = ApiWrapper.Get<UserResponse>("api/user/getbykey/" + agentID); if (landlordAgentResponse != null && userResponse != null) { landlordAgent.LandlordAgentID = landlordAgentResponse.LandlordAgentID; landlordAgent.FirstName = landlordAgentResponse.FirstName; landlordAgent.PreferredName = landlordAgentResponse.PreferredName; landlordAgent.LastName = landlordAgentResponse.LastName; landlordAgent.IDNumber = landlordAgentResponse.IDNumber; landlordAgent.TelWork = landlordAgentResponse.TelWork; landlordAgent.TelMobile = landlordAgentResponse.TelMobile; landlordAgent.Email = landlordAgentResponse.Email; landlordAgent.UserKey = landlordAgentResponse.LandlordAgentID; landlordAgent.UserID = userResponse.UserID; landlordAgent.Username = userResponse.Username; landlordAgent.Type = userResponse.Type; } else return HttpNotFound(); } return View("Agent/Create", landlordAgent); }
public ActionResult AddUserAgent(LandlordAgent model) { CreateUserRequest request = new CreateUserRequest(); request.UserID = model.UserID; request.Username = model.Username; request.Type = model.Type; CreateLandlordAgentRequest agentRequest = new CreateLandlordAgentRequest(); agentRequest.LandlordAgentID = model.LandlordAgentID; agentRequest.TelWork = model.TelWork; agentRequest.TelMobile = model.TelMobile; agentRequest.Email = model.Email; agentRequest.FirstName = model.FirstName; agentRequest.LastName = model.LastName; agentRequest.IDNumber = model.IDNumber; agentRequest.UserKey = model.LandlordAgentID; var result = ApiWrapper.Post<LandlordAgentResponse>("api/landlordagent/add", agentRequest); request.UserKey = result.LandlordAgentID; var resultUser = ApiWrapper.Post<bool>("api/user/add", request); if (string.IsNullOrEmpty(Request.QueryString["returnurl"])) return Redirect("/user/list/ag"); else return Redirect(Request.QueryString["returnurl"]); }
public ActionResult ViewAgents() { List<UserResponse> users = new List<UserResponse>(); users = ApiWrapper.Get<List<UserResponse>>("api/user/list/agent"); List<LandlordAgentResponse> landlordAgents = new List<LandlordAgentResponse>(); landlordAgents = ApiWrapper.Get<List<LandlordAgentResponse>>("api/landlordagent/"); List<LandlordAgent> finalLandlordAgents = new List<LandlordAgent>(); foreach (LandlordAgentResponse agent in landlordAgents) { var user = users.Where(x => x.UserKey == agent.LandlordAgentID).FirstOrDefault(); if (user == null) continue; LandlordAgent finalAgent = new LandlordAgent(); finalAgent.LandlordAgentID = agent.LandlordAgentID; finalAgent.FirstName = agent.FirstName; finalAgent.PreferredName = agent.FirstName; finalAgent.LastName = agent.LastName; finalAgent.IDNumber = agent.IDNumber; finalAgent.TelWork = agent.TelWork; finalAgent.TelMobile = agent.TelMobile; finalAgent.Email = agent.Email; finalAgent.UserKey = agent.LandlordAgentID; finalAgent.UserID = user.UserID; finalAgent.Username = user.Username; finalAgent.Type = user.Type; finalLandlordAgents.Add(finalAgent); } return View("Agent/List", finalLandlordAgents); }