public ActionResult CreateAgentRoute(CreateAgentRouteModel model) { int agencyId = model.AgencyId; if (agentAdminMgt == null) agentAdminMgt = new AgentAdminMenagement(User.Identity.GetUserId<int>()); resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<BUser> users = agentAdminMgt.FindAgencies((int)agencyId, null, null, 0, 0, out total); if (users == null || users.Count == 0) { ViewBag.Message = string.Format("编号为 {0} 的代理商存在"); return View("Error"); } BUser agency = users[0]; ViewBag.Agency = agency; if(ModelState.IsValid) { KMBit.DAL.Agent_route ruote; if(model.ResouceTaocans.Length>0) { foreach(int tId in model.ResouceTaocans) { ruote = new DAL.Agent_route() { CreatedBy = User.Identity.GetUserId<int>(), Create_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), Discount = model.Discount, Enabled = model.Enabled, Resource_Id = model.ResourceId, Resource_taocan_id = tId, User_id = model.AgencyId }; bool ret = agentAdminMgt.CreateRoute(ruote); } } return Redirect("/Admin/AgentRoutes?agencyId=" + model.AgencyId); } List<BResource> resources = resourceMgt.FindResources(0, null, 0, out total); ViewBag.Resources = new SelectList((from r in resources select r.Resource).ToList<KMBit.DAL.Resource>(), "Id", "Name"); List<BResourceTaocan> taocans = new List<BResourceTaocan>(); if(model.ResourceId>0) { taocans = resourceMgt.FindEnabledResourceTaocansForAgent(model.ResourceId,model.AgencyId); } ViewBag.ResourceTaocans1 = taocans; return View(model); }