public IActionResult Register([FromBody] CompanyUserModel userModel) { // map dto to entity var user = _iMapper.Map <Companies>(userModel); var count = 1; try { // save var result = _iCompanyService.Create(user, userModel.Password); if (result != null) { return(Output(new DeleteOrUpdateResponse { id = user.CompanyId, }, count)); } throw new Exception("注册失败!"); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public IActionResult EditPassword(string id, [FromBody] CompanyUserModel userModel) { // map dto to entity and set id var user = _iMapper.Map <Companies>(userModel); user.CompanyId = id; var result = _iCompanyService.Authenticate(userModel.Email, userModel.Password); if (result != null) { try { // save _iCompanyService.EditPassword(user, userModel.NewPassword); var count = 1; return(Output(new DeleteOrUpdateResponse { id = id }, count)); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } } throw new Exception("密码或email错误,请检查"); }
public async Task <IActionResult> CompanyUserAdd(CompanyUserModel model) { ViewModel viewModel = new ViewModel(); var userResult = await _userService.FindUserIdByUsername(model.Username, Token); if (userResult.Success) { var result = await _crudService.PartialEdit(userResult.Id, CreatePatchList(CreatePatchModel("companyId", model.CompanyId.ToString())), Token, UserService.UserEntity); if (result.Success) { AddMessageToModel(viewModel, "User was successfully added to company.", false); } else { AddMessageToModel(viewModel, result.Message); } } else { AddMessageToModel(viewModel, userResult.Message); } AddViewModelToTempData(viewModel); return(RedirectToAction("Company")); }
public ActionResult AddCompanyUser(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser propertyUser = new T_CompanyUser() { UserName = model.UserName, TrueName = model.TrueName, Password = PropertyUtils.GetMD5Str(model.Password), Memo = model.Memo, Tel = model.Tel, Phone = model.Phone, Email = model.Email, CompanyId = GetSessionModel().CompanyId.Value }; // 保存到数据库 companyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public IActionResult AcceptInvitation(CompanyUserModel model) { try { var response = _service.AcceptInvitation(model.CompanyId, model.Email); return(Ok(response)); } catch (ValidationException ex) { return(BadRequest(ex.Message)); } }
public FinishRegistrationPage RegistAsCompanyUser(CompanyUserModel companyUser) { Step1(companyUser.DetailsSecurityInfo); Step2(companyUser.ContactDataInfo); Step3(companyUser.BeginRegistrationInfo); Step4(companyUser.LastInfo); var finishPage = PageFactory.Get <FinishRegistrationPage>(); finishPage.WaitForReady(); return(finishPage); }
public async Task <CompanyUserModel> AddCompanyUser(Guid companyId, Guid userId, MembershipStatus membershipStatus) { var item = new CompanyUserModel { CompanyId = companyId, UserId = userId, Status = membershipStatus, CreatedDate = DateTime.UtcNow }; var entry = await _context.CompaniesUsers.AddAsync(item); await _context.SaveChangesAsync(); return(entry.Entity); }
public JsonResult SetCompanyAdministrator(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL propertyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = new T_CompanyUser() { CompanyId = model.CompanyId, UserName = model.UserName, Email = model.Email, Password = PropertyUtils.GetMD5Str(model.Password), IsMgr = ConstantParam.USER_ROLE_MGR, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, }; //为管理员添加角色 ICompanyRoleBLL roleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); var role = roleBll.GetEntity(r => r.IsSystem == ConstantParam.USER_ROLE_MGR && r.CompanyId == model.CompanyId); if (role != null) { companyUser.CompanyUserRoles.Add(new R_CompanyUserRole() { RoleId = role.Id, }); } //创建管理员 propertyUserBll.Save(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public JsonResult Authenticate([FromBody] CompanyUserModel userModel) { var user = _iCompanyService.Authenticate(userModel.Email, userModel.Password); if (user.Status != 0) { if (user != null) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.CompanyId.ToString()) }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); var count = 1; return(Output(new CompanyLoginResponse { token = tokenString, avatar = user.Avatar, email = user.Email, name = user.CompanyName, roleid = user.RoleId, id = user.CompanyId, OrganizationCode = user.OrganizationCode, PersonalNumber = user.PersonalNumber, CompanyDescription = user.CompanyDescription, CompanyUrl = user.CompanyUrl, }, count)); } throw new Exception("用户名或密码错误!"); } throw new Exception("还未通过审核!请稍后再试!"); }
public ActionResult EditCompanyUser(int?id) { // 参数校验 if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); var companyUserInfo = companyUserBll.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUserInfo != null) { CompanyUserModel companyUserModel = new CompanyUserModel(); companyUserModel.CompanyUserId = companyUserInfo.Id; companyUserModel.UserName = companyUserInfo.UserName; companyUserModel.TrueName = companyUserInfo.TrueName; companyUserModel.Memo = companyUserInfo.Memo; companyUserModel.Tel = companyUserInfo.Tel; companyUserModel.Phone = companyUserInfo.Phone; companyUserModel.Email = companyUserInfo.Email; companyUserModel.HeadPath = companyUserInfo.HeadPath; companyUserModel.CompanyId = GetSessionModel().CompanyId.Value; // 获取指定小区的名称 IPropertyCompanyBLL propertyCompanyBll = BLLFactory <IPropertyCompanyBLL> .GetBLL("PropertyCompanyBLL"); var propertyCompany = propertyCompanyBll.GetEntity(m => m.Id == companyUserModel.CompanyId); if (propertyCompany != null) { companyUserModel.CompanyName = propertyCompany.Name; } return(View(companyUserModel)); } else { return(RedirectToAction("UserList")); } }
public ActionResult SetCompanyAdministrator(int id) { //获取要设置的物业总公司 IPropertyCompanyBLL propertyCompanyBll = BLLFactory <IPropertyCompanyBLL> .GetBLL("PropertyCompanyBLL"); T_Company company = propertyCompanyBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (company != null) { //返回初始化模型页面 CompanyUserModel model = new CompanyUserModel(); model.CompanyId = company.Id; model.CompanyName = company.Name; ViewBag.Admins = company.CompanyUsers.Where(u => u.IsMgr == ConstantParam.USER_ROLE_MGR).Select(u => u.UserName).ToList(); return(View(model)); } else { return(RedirectToAction("CompanyList")); } }
public ActionResult AddCompanyUser() { // 获取物业总公司管理员所属的物业总公司 int companyId = GetSessionModel().CompanyId.Value; // 获取指定物业总公司的名称 IPropertyCompanyBLL propertyCompanyBLL = BLLFactory <IPropertyCompanyBLL> .GetBLL("PropertyCompanyBLL"); var company = propertyCompanyBLL.GetEntity(m => m.Id == companyId); if (company != null) { CompanyUserModel model = new CompanyUserModel() { CompanyName = company.Name }; return(View(model)); } return(View()); }
public IActionResult Patch(string id, [FromBody] CompanyUserModel userModel) { // map dto to entity and set id var user = _iMapper.Map <Companies>(userModel); user.CompanyId = id; var count = 1; try { // save _iCompanyService.Patch(user, userModel.Password); return(Output(new DeleteOrUpdateResponse { id = id }, count)); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public ActionResult EditCompanyUser(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == model.CompanyUserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { companyUser.UserName = model.UserName; companyUser.TrueName = model.TrueName; companyUser.Memo = model.Memo; companyUser.Tel = model.Tel; companyUser.Phone = model.Phone; companyUser.Email = model.Email; // 保存到数据库 companyUserBll.Update(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult UploadPic(int id) { JsonModel jm = new JsonModel(); ICompanyUserBLL UserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); var companyUser = UserBll.GetEntity(m => m.DelFlag == 0 && m.Id == id); //总公司用户存在 if (companyUser != null) { CompanyUserModel userModel = new CompanyUserModel() { CompanyUserId = companyUser.Id, HeadPath = companyUser.HeadPath }; return(View(userModel)); } //用户不存在 else { jm.Msg = "用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }