public ActionResult EditIdentification(string spaceKey, IdentificationEditModel editModel) { //获取认证标识下拉框 IEnumerable<IdentificationType> identificationTypes = identificationService.GetIdentificationTypes(true); SelectList identificationTypeList = null; identificationTypeList = new SelectList(identificationTypes, "IdentificationTypeId", "Name", editModel.IdentificationTypeId); ViewData["identificationTypeList"] = identificationTypeList; string fileName = string.Empty; Stream stream = null; IUser user = UserContext.CurrentUser; HttpPostedFileBase logo = Request.Files["identificationFile"]; if (logo.ContentLength > 0) { fileName = logo.FileName; LogoSettings logoSettings = logoSettingsManager.Get(); //校验附件的扩展名 if (!logoSettings.ValidateFileExtensions(fileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为" + logoSettings.AllowedFileExtensions.TrimEnd(',') + "的文件"); return View(editModel); } //校验附件的大小 TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Identification()); if (!tenantLogoSettings.ValidateFileLength(logo.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength)); return View(editModel); } stream = logo.InputStream; } //编辑 if (editModel.IdentificationId > 0) { Identification identification = identificationService.GetIdentification(editModel.IdentificationId); if (identification.UserId != user.UserId) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有编辑该身份认证的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint })); } //如果该次申请的身份认证与之前的身份认证相同就不需要判断有没有申请过该认证 long identificationTypeId = identificationService.GetIdentification(editModel.IdentificationId).IdentificationTypeId; if (identificationTypeId != editModel.IdentificationTypeId) { //判断该用户有没有申请过该认证 if (IsAppliedCommon(editModel.IdentificationTypeId)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "您已经申请过该认证"); return View(editModel); } } identification = editModel.AsIdentification(); identificationService.UpdateIdentification(identification, stream); } //创建 else { if (logo.ContentLength == 0) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "证件扫描不能为空"); return View(editModel); } //判断该用户有没有申请过该认证 if (IsAppliedCommon(editModel.IdentificationTypeId)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "您已经申请过该认证"); return View(editModel); } Identification identification = editModel.AsIdentification(); identificationService.CreateIdentification(identification, stream); } return RedirectToAction("IdentificationResult", new { IdentificationTypeId = editModel.IdentificationTypeId }); }
public ActionResult EditIdentification(string spaceKey, long identificationId = 0) { User user = (User)UserContext.CurrentUser; if (user == null) { return Redirect(SiteUrls.Instance().Login(true)); } //对访问权限的判断 long userid = UserIdToUserNameDictionary.GetUserId(spaceKey); if (userid != user.UserId) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有查看该身份认证的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint })); } IdentificationEditModel editModel = null; //获取认证标识下拉框 IEnumerable<IdentificationType> identificationTypes = identificationService.GetIdentificationTypes(true); SelectList identificationTypeList = null; //创建 if (identificationId == 0) { editModel = new IdentificationEditModel(); //获取当前帐号的默认资料 user = userService.GetFullUser(user.UserId); if (user.Profile != null) { editModel.TrueName = user.TrueName; editModel.Email = user.Profile.Email; editModel.Mobile = user.Profile.Mobile; } pageResourceManager.InsertTitlePart("申请身份认证"); //创建的话只取该用户没有申请的身份验证标识 List<Identification> identifications = identificationService.GetUserIdentifications(user.UserId); //获取其没申请的标识ID IEnumerable<long> notApplyIdentificationTypeIds = identificationTypes.Select(n => n.IdentificationTypeId).Except(identifications.Select(u => u.IdentificationTypeId)); List<IdentificationType> notApplyidentificationTypes = new List<IdentificationType>(); foreach (var identificationTypeId in notApplyIdentificationTypeIds) { IdentificationType IdentificationType = identificationTypes.Where(n => n.IdentificationTypeId == identificationTypeId).SingleOrDefault(); notApplyidentificationTypes.Add(IdentificationType); } identificationTypeList = new SelectList(notApplyidentificationTypes, "IdentificationTypeId", "Name", editModel.IdentificationTypeId); if (notApplyIdentificationTypeIds.Count() == 0) { pageResourceManager.InsertTitlePart("身份认证状态"); return RedirectToAction("IdentificationResult"); } } //编辑 else { Identification identification = identificationService.GetIdentification(identificationId); if (identification.UserId != user.UserId) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有查看该身份认证的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint })); } editModel = identification.AsEditModel(); identificationTypeList = new SelectList(identificationTypes, "IdentificationTypeId", "Name", editModel.IdentificationTypeId); ViewData["identificationTypeName"] = identificationTypes.Where(n => n.IdentificationTypeId == editModel.IdentificationTypeId).First().Name; pageResourceManager.InsertTitlePart("编辑身份认证"); } ViewData["identificationTypeList"] = identificationTypeList; return View(editModel); }