public ApiMessage GetAgencyResources() { this.IniRequest(); ApiMessage message = new ApiMessage(); AgentAdminMenagement agentMgtMgr = new AgentAdminMenagement(User.Identity.Name); int agencyId = 0; int.TryParse(request["agencyId"],out agencyId); if(agencyId>0) { List<BResource> rs = agentMgtMgr.FindAgentResources(agencyId); message.Status = "OK"; message.Item = rs; }else { ResourceManagement resourceMgr = new ResourceManagement(agentMgtMgr.CurrentLoginUser); int total = 0; List<BResource> rs = resourceMgr.FindResources(0, null, 0, out total); message.Status = "OK"; message.Item = rs; } return message; }
static void test() { ResourceManagement rmgt = new ResourceManagement(3); int total; List<BResource> resources = rmgt.FindResources(2,"xx",0,out total); }
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); }
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); }
public ActionResult UpdateResourceTaocan(ResourceTaocanModel model) { bool ret = false; resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<BResource> resources = resourceMgt.FindResources(model.ResoucedId, null, 0, out total); if (resources == null || resources.Count == 0) { ViewBag.Message = "资源信息丢失"; return View("Error"); } BResource resource = resources[0]; if (ModelState.IsValid) { KMBit.DAL.Resource_taocan taocan = null; if(model.Id>0) { int total = 0; List<BResourceTaocan> ts = resourceMgt.FindResourceTaocans(model.Id, 0, 0, out total); if (total == 1) { taocan = ts[0].Taocan; } }else { taocan = new DAL.Resource_taocan(); taocan.CreatedBy = User.Identity.GetUserId<int>(); taocan.Created_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); taocan.Quantity = model.Quantity; taocan.Resource_id = model.ResoucedId; } taocan.Serial = model.Serial; taocan.Area_id = model.Province != null ? (int)model.Province : 0; taocan.City_id = model.City!=null ?(int)model.City:0; taocan.NumberProvinceId = model.NumberProvince != null ? (int)model.NumberProvince : 0; taocan.NumberCityId = model.NumberCity != null ? (int)model.NumberCity : 0; taocan.Enabled = model.Enabled; taocan.Purchase_price = model.PurchasePrice; taocan.EnableDiscount = model.EnabledDiscount; taocan.Resource_Discount = model.Discount; taocan.Sale_price = model.SalePrice; taocan.Sp_id = model.SP != null ? (int)model.SP : 0; taocan.UpdatedBy = User.Identity.GetUserId<int>(); taocan.Updated_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); try { if (model.Id <= 0) { ret = resourceMgt.CreateResourceTaocan(taocan); } else { ret = resourceMgt.UpdateResourceTaocan(taocan); } } catch(KMBitException kex) { KMLogger.GetLogger().Error(kex); ViewBag.Message = kex.Message; return View("Error"); } catch(Exception ex) { KMLogger.GetLogger().Fatal(ex); ViewBag.Message = "未知错误,请联系系统管理员"; return View("Error"); } if (ret) { return Redirect("/Admin/ViewResourceTaoCan?resourceId=" + model.ResoucedId); } else { ViewBag.Message = "未知错误,请联系系统管理员"; return View("Error"); } }else { var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); ViewBag.Message = "资源套餐创建失败"; return View("Error"); } List<KMBit.DAL.Area> provinces = null; List<KMBit.DAL.Sp> sps = null; provinces = resourceMgt.GetAreas(0); sps = resourceMgt.GetSps(); ViewBag.Resource = resource; ViewBag.Provinces = new SelectList(provinces, "Id", "Name"); ViewBag.Cities = new SelectList(resourceMgt.GetAreas(model.Province != null ? (int)model.Province : 0), "Id", "Name"); ViewBag.SPs = new SelectList(sps, "Id", "Name"); return View("CreateResourceTaocan",model); }
public ActionResult ViewResourceTaoCan(int? resourceId) { int id = resourceId??0; resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<BResource> resources = resourceMgt.FindResources(id, null, 0,out total); if (resources == null || resources.Count == 0) { return View("Error"); } int pageSize = 50; int requestPage = 1; int.TryParse(Request["page"], out requestPage); requestPage = requestPage == 0 ? 1 : requestPage; List<BResourceTaocan> resourceTaocans = resourceMgt.FindResourceTaocans(0, id, 0, out total, requestPage, pageSize,false); PageItemsResult<BResourceTaocan> result = new PageItemsResult<BResourceTaocan>() { CurrentPage = requestPage, Items = resourceTaocans, PageSize = resourceTaocans.Count, TotalRecords = total }; result.EnablePaging = false; KMBit.Grids.KMGrid<BResourceTaocan> grid = new Grids.KMGrid<BResourceTaocan>(result); ViewBag.Resource = resources[0]; return View(grid); }
public ActionResult CreateResourceTaocan(int? resourceId) { if(resourceId==null) { ViewBag.Message = "资源信息丢失"; return View("Error"); } int id = (int)resourceId; ResourceTaocanModel mode = new ResourceTaocanModel() { ResoucedId=id,EnabledDiscount=true}; if (id <= 0) { ViewBag.Message = "资源信息丢失"; return View("Error"); } resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<BResource> resources = resourceMgt.FindResources(id, null, 0, out total); if(resources == null || resources.Count==0) { ViewBag.Message = "资源信息丢失"; return View("Error"); } BResource resource = resources[0]; List<KMBit.DAL.Area> provinces = null; List<KMBit.DAL.Sp> sps = null; provinces = resourceMgt.GetAreas(0); sps = resourceMgt.GetSps(); ViewBag.Provinces = new SelectList(provinces, "Id", "Name"); ViewBag.Cities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name"); ViewBag.NCities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name"); ViewBag.SPs = new SelectList(sps, "Id", "Name"); ViewBag.Resource = resource; mode.Enabled = true; mode.EnabledDiscount = true; return View(mode); }
public ActionResult Resources() { int pageSize = 20; int requestPage = 1; int.TryParse(Request["page"], out requestPage); requestPage = requestPage == 0 ? 1 : requestPage; resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); if(!resourceMgt.CurrentLoginUser.Permission.VIEW_RESOURCE) { ViewBag.Message = "没有权限查看资源"; return View("Error"); } ViewBag.LoginUser = resourceMgt.CurrentLoginUser; var resources = resourceMgt.FindResources(0, null, 0,out total,requestPage,pageSize,true); PageItemsResult<BResource> result = new PageItemsResult<BResource>() { CurrentPage = requestPage, Items = resources, PageSize = pageSize, TotalRecords = total }; KMBit.Grids.KMGrid<BResource> grid = new Grids.KMGrid<BResource>(result); return View(grid); }
public ActionResult UpdateResource(ResourceModel model) { resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<KMBit.DAL.Area> provinces = null; List<KMBit.DAL.Sp> sps = null; if (ModelState.IsValid) { DAL.Resource resource = null; if (model.Id > 0) { List<BResource> resources = resourceMgt.FindResources((int)model.Id, null, 0, out total); if (resources == null) { ViewBag.Message = "试图编辑的资源不存在"; return View("Error"); } BResource bresouce = resources[0]; resource = bresouce.Resource; } else { resource = new DAL.Resource(); resource.Name = model.Name; resource.CreatedBy = User.Identity.GetUserId<int>(); resource.Created_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); } resource.Address = model.Address; resource.City_Id = model.City; resource.Contact = model.Contact; resource.Description = model.Description; resource.Email = model.Email; resource.Enabled = model.Enabled; resource.Province_Id = model.Province; resource.SP_Id = model.SP; resource.UpdatedBy = User.Identity.GetUserId<int>(); resource.Updated_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); try { bool result = false; if (resource.Id <= 0) { result = resourceMgt.CreateResource(resource); } else { result = resourceMgt.UpdateResource(resource); } if (result) { return RedirectToAction("Resources"); } } catch (KMBitException ex) { ViewBag.Exception = ex; } catch (Exception nex) { ViewBag.ErrMsg = nex.Message; } finally { } } 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; } provinces = resourceMgt.GetAreas(0); sps = resourceMgt.GetSps(); ViewBag.Provinces = new SelectList(provinces, "Id", "Name"); ViewBag.Cities = new SelectList(resourceMgt.GetAreas(model.Province), "Id", "Name"); ViewBag.SPs = new SelectList(sps, "Id", "Name"); return View("CreateResource",model); }
public ActionResult EditResource(int resourceId) { resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); if (resourceId <= 0) { ViewBag.Message = "资源编号不正确"; return View("Error"); } List<BResource> resources = resourceMgt.FindResources(resourceId, null, 0,out total); if (resources == null) { ViewBag.Message = "试图编辑的资源不存在"; return View("Error"); } BResource resouce = resources[0]; ResourceModel model = new ResourceModel() { Address = resouce.Resource.Address, City = (int)resouce.Resource.City_Id, Contact = resouce.Resource.Contact, Description = resouce.Resource.Description, Email = resouce.Resource.Email, Enabled = resouce.Resource.Enabled, Id = resouce.Resource.Id, Name = resouce.Resource.Name, Province = resouce.Resource.Province_Id, SP = resouce.Resource.SP_Id }; List<KMBit.DAL.Area> provinces = null; List<KMBit.DAL.Sp> sps = null; provinces = resourceMgt.GetAreas(0); sps = resourceMgt.GetSps(); ViewBag.Provinces = new SelectList(provinces, "Id", "Name"); ViewBag.Cities = new SelectList(resourceMgt.GetAreas(model.Province), "Id", "Name"); ViewBag.SPs = new SelectList(sps, "Id", "Name"); return View("CreateResource", model); }
public ActionResult ChargeOrders(OrderSearchModel searchModel) { OrderManagement orderMgt = new OrderManagement(User.Identity.GetUserId<int>()); agentAdminMgt = new AgentAdminMenagement(orderMgt.CurrentLoginUser); resourceMgt = new ResourceManagement(orderMgt.CurrentLoginUser); if (!orderMgt.CurrentLoginUser.Permission.CHARGE_HISTORY) { ViewBag.Message = "没有权限查看流量充值记录"; return View("Error"); } int pageSize = 40; DateTime sDate = DateTime.MinValue; DateTime eDate = DateTime.MinValue; if(!string.IsNullOrEmpty(searchModel.StartTime)) { DateTime.TryParse(searchModel.StartTime, out sDate); } if (!string.IsNullOrEmpty(searchModel.EndTime)) { DateTime.TryParse(searchModel.EndTime, out eDate); } long sintDate = sDate!=DateTime.MinValue?DateTimeUtil.ConvertDateTimeToInt(sDate):0; long eintDate= eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0; int page = 1; if(Request["page"]!=null) { int.TryParse(Request["page"],out page); } searchModel.Page = page; List<BOrder> orders = orderMgt.FindOrders(searchModel.OrderId!=null?(int)searchModel.OrderId:0, searchModel.AgencyId!=null?(int)searchModel.AgencyId:0, searchModel.ResourceId!=null?(int)searchModel.ResourceId:0, searchModel.ResourceTaocanId!=null?(int)searchModel.ResourceTaocanId:0, searchModel.RuoteId!=null?(int)searchModel.RuoteId:0, searchModel.SPName, searchModel.MobileNumber, searchModel.Status, sintDate, eintDate, out total, pageSize, searchModel.Page, true); PageItemsResult<BOrder> result = new PageItemsResult<BOrder>() { CurrentPage = searchModel.Page, Items = orders, PageSize = pageSize, TotalRecords = total,EnablePaging=true }; KMBit.Grids.KMGrid<BOrder> grid = new Grids.KMGrid<BOrder>(result); BigOrderSearchModel model = new BigOrderSearchModel() { SearchModel = searchModel, OrderGrid = grid }; List<KMBit.Beans.BUser> agencies = agentAdminMgt.FindAgencies(0, null, null, 0, 0, out total, 0, 0, false,null); List<BResource> resources = new List<BResource>(); if(searchModel.AgencyId!=null) { resources = agentAdminMgt.FindAgentResources((int)searchModel.AgencyId); }else { resources = resourceMgt.FindResources(0,null,0,out total); } ViewBag.Agencies = new SelectList((from a in agencies select a.User).ToList<Users>(),"Id","Name"); ViewBag.Resources = new SelectList((from r in resources select r.Resource).ToList<Resource>(), "Id", "Name"); List<BResourceTaocan> taocans = new List<BResourceTaocan>(); if(searchModel.ResourceId!=null) { if(searchModel.AgencyId==null) { taocans = resourceMgt.FindResourceTaocans((int)searchModel.ResourceId, 0, false); } else { taocans = agentAdminMgt.FindAgencyResourceTaocans((int)searchModel.AgencyId, (int)searchModel.ResourceId); } } ViewBag.Taocans = new SelectList((from t in taocans select new { Id=t.Taocan.Id,Name=t.Taocan2.Name}), "Id", "Name"); ViewBag.StatusList = new SelectList((from s in StaticDictionary.GetChargeStatusList() select new { Id=s.Id,Name=s.Value}),"Id","Name"); return View(model); }