void IAgentService.Create(Agent agent) { if ((this as IAgentService).GetAgents(agent.ActAs) .FirstOrDefault(o => o._enable && o.User.Equals(agent.User)) != null) { throw new InvalidOperationException(string.Format("不能为{0}设置重复的代理人{1}" , agent.ActAs.UserName , agent.User.UserName)); } _repository.Add(agent); }
public void Add(AgentDomainModel agentDomainModel) { var agentDataModel = new AgentDataModel() { Id = agentDomainModel.Id, Name = agentDomainModel.Name, Address = agentDomainModel.Address, City = agentDomainModel.City, State = agentDomainModel.State, ZipCode = agentDomainModel.ZipCode, Tier = agentDomainModel.Tier, Phone = new AgentDataModel.AgentPhone() { Primary = agentDomainModel.Phone.Primary, Mobile = agentDomainModel.Phone.Mobile } }; _agentRepository.Add(agentDataModel); }
public IActionResult Post(string values) { var model = new Agent(); JsonConvert.PopulateObject(values, model); var modelVM = new AgentVM(); JsonConvert.PopulateObject(values, modelVM); if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } var user = new ApplicationUser() { UserName = model.EMail, Email = model.EMail }; //IdentityResult result = await _accountManager.CreateAccountAsync(user, EnumApplicationRole.Agent); IdentityResult result = _accountManager.CreateAccountAsync(user, modelVM.RoleName != null ? modelVM.RoleName : nameof(EnumApplicationRole.Agent)).Result; if (result.Succeeded) { _accountManager.SendEmailConfirmationAsync(user, this.Request, this.Url).Wait(); model.ApplicationUserId = user.Id; _agentRepo.Add(model); return(_uow.Commit() ? Ok() : StatusCode(StatusCodes.Status500InternalServerError)); } else { _accountManager.AddModelStateErrors(this.ModelState, result); return(BadRequest(GetFullErrorMessage(this.ModelState))); } }
/// <summary> /// Seed method attempts to intsert the initial data into the database everytime when database is being updated after migration /// </summary> /// <param name="context">Database context on which seed method is being called (Not used in this scenario because repositories are used to insert the data)</param> protected override void Seed(RAMS.Data.DataContext context) { // Add users using (var applicationDbContext = new ApplicationDbContext()) { var userStore = new UserStore <ApplicationUser>(applicationDbContext); var userManager = new UserManager <ApplicationUser>(userStore); if (userManager.FindByName("john.doe") == null) { var users = GetUsers(); foreach (var user in users) { userManager.Create(user, "123RAMSApp!"); // Add user claims for each user if (user.UserName == "superuser") { userManager.AddClaim(user.Id, new Claim("FullName", "superuser")); userManager.AddClaim(user.Id, new Claim("Role", "Manager")); userManager.AddClaim(user.Id, new Claim("UserType", "Admin")); userManager.AddClaim(user.Id, new Claim("UserStatus", "Active")); } else if (user.UserName == "john.doe") { userManager.AddClaim(user.Id, new Claim("FullName", "John Doe")); userManager.AddClaim(user.Id, new Claim("Role", "Manager")); userManager.AddClaim(user.Id, new Claim("UserType", "Agent")); userManager.AddClaim(user.Id, new Claim("UserStatus", "Active")); } else if (user.UserName == "james.smith") { userManager.AddClaim(user.Id, new Claim("FullName", "James Smith")); userManager.AddClaim(user.Id, new Claim("Role", "Employee")); userManager.AddClaim(user.Id, new Claim("UserType", "Agent")); userManager.AddClaim(user.Id, new Claim("UserStatus", "Active")); } else if (user.UserName == "mary.watson") { userManager.AddClaim(user.Id, new Claim("FullName", "Mary Watson")); userManager.AddClaim(user.Id, new Claim("Role", "Employee")); userManager.AddClaim(user.Id, new Claim("UserType", "Agent")); userManager.AddClaim(user.Id, new Claim("UserStatus", "Active")); } else if (user.UserName == "tommy.jordan") { userManager.AddClaim(user.Id, new Claim("FullName", "Tommy Jordan")); userManager.AddClaim(user.Id, new Claim("Role", "Employee")); userManager.AddClaim(user.Id, new Claim("UserType", "Admin")); userManager.AddClaim(user.Id, new Claim("UserStatus", "Active")); } else if (user.UserName == "kathy.doe") { userManager.AddClaim(user.Id, new Claim("FullName", "Kathy Doe")); userManager.AddClaim(user.Id, new Claim("Role", "Employee")); userManager.AddClaim(user.Id, new Claim("UserType", "Admin")); userManager.AddClaim(user.Id, new Claim("UserStatus", "Active")); } else if (user.UserName == "jimmy.thomson") { userManager.AddClaim(user.Id, new Claim("FullName", "Jimmy Thomson")); userManager.AddClaim(user.Id, new Claim("Role", "Employee")); userManager.AddClaim(user.Id, new Claim("UserType", "Client")); userManager.AddClaim(user.Id, new Claim("UserStatus", "Active")); } else if (user.UserName == "nancy.clinton") { userManager.AddClaim(user.Id, new Claim("FullName", "Nancy Clinton")); userManager.AddClaim(user.Id, new Claim("Role", "Employee")); userManager.AddClaim(user.Id, new Claim("UserType", "Client")); userManager.AddClaim(user.Id, new Claim("UserStatus", "Active")); } } } } // Add departments if (!departmentRepository.GetAll().Any()) { GetDepartments().ForEach(d => departmentRepository.Add(d)); unitOfWork.Commit(); } // Add agents if (!agentRepository.GetAll().Any()) { GetAgents().ForEach(a => agentRepository.Add(a)); unitOfWork.Commit(); } // Add clients if (!clientRepository.GetAll().Any()) { GetClients().ForEach(c => clientRepository.Add(c)); unitOfWork.Commit(); } // Add admins if (!adminRepository.GetAll().Any()) { GetAdmins().ForEach(a => adminRepository.Add(a)); unitOfWork.Commit(); } // Add categories if (!categoryRepository.GetAll().Any()) { GetCategories().ForEach(c => categoryRepository.Add(c)); unitOfWork.Commit(); } // Add positions if (!positionRepository.GetAll().Any()) { GetPositions().ForEach(p => positionRepository.Add(p)); unitOfWork.Commit(); } // Add candidates if (!candidateRepository.GetAll().Any()) { GetCandidates().ForEach(c => candidateRepository.Add(c)); unitOfWork.Commit(); } // Add interiews if (!interviewRepository.GetAll().Any()) { GetInterviews().ForEach(i => interviewRepository.Add(i)); unitOfWork.Commit(); } // Add notifications if (!notificationRepository.GetAll().Any()) { GetNotifications().ForEach(n => notificationRepository.Add(n)); unitOfWork.Commit(); } }
/// <summary> /// 添加代理人信息 /// </summary> /// <param name="request"></param> /// <param name="pairs"></param> /// <returns></returns> public GetAgentResponse AddAgent(PostAddAgentRequest request, IEnumerable <KeyValuePair <string, string> > pairs) { var response = new GetAgentResponse(); bx_agent agent = new bx_agent(); //备注:临时屏蔽,暂时先不上 agent = _agentRepository.GetAgentIsTop(request.TopParentAgent); if (agent == null) { response.ErrCode = -4;//顶级代理人不存在 return(response); } if (!_agentRepository.IsContainSon(request.TopParentAgent, request.AgentId)) { response.ErrCode = -5;//顶级代理下面不包含子集代理 return(response); } agent = new bx_agent(); agent = _agentRepository.GetAgentByPhoneTopAgent(request.Mobile, request.TopParentAgent); if (agent != null) { response.ErrCode = -1;//手机号已存在 return(response); } agent = new bx_agent(); agent = _agentRepository.GetAgentByTopParentAgent(request.OpenId, request.TopParentAgent); if (agent != null) { response.ErrCode = -2;//OpenId已存在 response.agent = ToModel(agent, request.TopParentAgent); return(response); } int agentlevel = _agentRepository.GetAgentLevel(GetAgent(request.AgentId).ParentAgent); if (agentlevel > 2) { response.ErrCode = -3;//不允许新增下一级代理 return(response); } //插入bx_agent bx_agent model = new bx_agent(); model.AgentName = request.AgentName; model.Mobile = request.Mobile; model.OpenId = request.OpenId; model.ParentAgent = request.AgentId;//有问题 #region 分配默认值 model.CreateTime = DateTime.Now; model.IsBigAgent = 1; model.CommissionType = 0; model.IsUsed = 0; model.IsGenJin = 0; model.IsDaiLi = 0; model.IsShow = 0; model.IsShowCalc = 0; model.IsLiPei = 0; model.AgentType = 0; model.MessagePayType = 1; //发短信走当前代理人 model.RegType = 0; //小龙说默认走单店 暂无实际需要 model.IsQuote = 1; model.IsSubmit = 1; #endregion long agentId = _agentRepository.Add(model); if (agentId > 0) { //根据agentId更新ShareCode int update = 0; update = _agentRepository.Update(agentId); if (update > 0) { //存入缓存,并读取该记录 //string agentCacheKey = string.Format("agent_cacke_key-{0}-{1}", agentId, request.AgentId // ); var agentCache = _agentRepository.GetAgent((int)agentId); //HttpRuntime.Cache.Insert(agentCacheKey, agentCache, null, DateTime.Now.AddHours(12), TimeSpan.Zero, CacheItemPriority.High, null); response.agent = ToModel(agentCache, request.TopParentAgent); } } return(response); }
/// <inheritdoc /> /// <summary> /// Adds the specified agent to the repository. /// </summary> /// <param name="model">The model to add.</param> /// <returns> /// <see cref="AgentModel" />. /// </returns> public async Task <AgentModel> Add(AgentModel model) { return(_mapper.Map <AgentEntity, AgentModel>( await _agentRepository.Add( _mapper.Map <AgentModel, AgentEntity>(model)))); }