예제 #1
0
        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);
        }
예제 #2
0
        public ActionResult EditAgentRoute(CreateAgentRouteModel model)
        {
            if (agentAdminMgt == null)
                agentAdminMgt = new AgentAdminMenagement(User.Identity.GetUserId<int>());
            if (ModelState.IsValid)
            {
                if (agentAdminMgt.UpdateAgentRuote(model.Id, model.Discount, model.Enabled))
                {
                    return Redirect("/Admin/AgentRoutes?agencyId=" + model.AgencyId);
                }
                
            }else
            {
                string validationErrors = string.Join(",",
                    ModelState.Values.Where(E => E.Errors.Count > 0)
                    .SelectMany(E => E.Errors)
                    .Select(E => E.ErrorMessage)
                    .ToArray());

                ViewBag.ErrMsg = validationErrors;
            }

            List<BAgentRoute> routes = agentAdminMgt.FindRoutes(model.Id, 0, 0, 0, out total);
            if (routes == null || routes.Count == 0)
            {
                ViewBag.Message = string.Format("编号为 {0} 的路由不存在", model.Id);
                return View("Error");
            }
            BAgentRoute route = routes[0];
            List<BUser> users = agentAdminMgt.FindAgencies(route.Route.User_id, null, null, 0, 0, out total);
            if (users == null || users.Count == 0)
            {
                ViewBag.Message = string.Format("编号为 {0} 的代理商存在");
                return View("Error");
            }
            ViewBag.Agency = users[0];
            ViewBag.Ruote = route;
            return View("EditAgentRoute",model);
        }
예제 #3
0
        public ActionResult CreateAgentRoute(int 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;
            CreateAgentRouteModel model = new CreateAgentRouteModel() { Enabled = true, AgencyId = agency.User.Id,Id=0 };
            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>();
            //taocans = resourceMgt.FindResourceTaocans(0, 1, 0, out total);
            //ViewBag.ResourceTaocans = new SelectList((from t in taocans select new { Id = t.Taocan.Id, Name = t.City.Name + " " + t.SP.Name + " " + t.Taocan.Quantity }).ToList(), "Id", "Name");
            ViewBag.ResourceTaocans1 = taocans;
            return View("CreateAgentRoute",model);
        }
예제 #4
0
        public ActionResult EditAgentRoute(int routeId)
        {
            if (agentAdminMgt == null)
                agentAdminMgt = new AgentAdminMenagement(User.Identity.GetUserId<int>());

            List<BAgentRoute> routes = agentAdminMgt.FindRoutes(routeId, 0, 0, 0, out total);
            if(routes==null || routes.Count==0)
            {
                ViewBag.Message = string.Format("编号为 {0} 的路由不存在",routeId);
                return View("Error");
            }
            BAgentRoute route = routes[0];
            List<BUser> users = agentAdminMgt.FindAgencies(route.Route.User_id, null, null, 0, 0, out total);
            if (users == null || users.Count == 0)
            {
                ViewBag.Message = string.Format("编号为 {0} 的代理商存在");
                return View("Error");
            }

            BUser agency = users[0];
            CreateAgentRouteModel model = new CreateAgentRouteModel()
            {
                Id = route.Route.Id,
                AgencyId = route.Route.User_id,
                Discount = route.Route.Discount,
                Enabled = route.Route.Enabled,
                ResouceTaocans = new int[] { route.Route.Resource_taocan_id },
                ResourceId = route.Route.Resource_Id
            };

            ViewBag.Agency = agency;
            ViewBag.Ruote = route;
            return View("EditAgentRoute", model);
        }