public virtual async Task UpdateCompanyIndustryAsync(CompanyIndustryEditDto input) { //TODO:更新前的逻辑判断,是否允许更新 var entity = await _companyIndustryRepository.GetAsync(input.Id.Value); input.MapTo(entity); await _companyIndustryRepository.UpdateAsync(entity); }
/// <summary> /// 通过Id获取企业行业关系表信息进行编辑或修改 /// </summary> public async Task <GetCompanyIndustryForEditOutput> GetCompanyIndustryForEditAsync(NullableIdDto <int> input) { var output = new GetCompanyIndustryForEditOutput(); CompanyIndustryEditDto companyIndustryEditDto; if (input.Id.HasValue) { var entity = await _companyIndustryRepository.GetAsync(input.Id.Value); companyIndustryEditDto = entity.MapTo <CompanyIndustryEditDto>(); } else { companyIndustryEditDto = new CompanyIndustryEditDto(); } output.CompanyIndustry = companyIndustryEditDto; return(output); }
public async Task <JsonResult> CreateCompany(CreateOrUpdateCompanyInput model) { if (PermissionChecker.IsGranted("Pages.Company.CreateCompany")) { try { var oldCompany = await _companyService.GetCompanyByUserId(model.CompanyEditDto.UserId); if (oldCompany != null) { return(Json(new { success = false, msg = "存在该用户已关联的企业" })); } CheckModelState(); using (var unitWork = UnitOfWorkManager.Begin()) { var newModel = await _companyService.CreateCompanyAsync(model.CompanyEditDto); if (newModel.Id > 0) { List <string> industryIds = newModel.Industry.Split(',').ToList(); foreach (string industryId in industryIds) { CreateOrUpdateCompanyIndustryInput industryInput = new CreateOrUpdateCompanyIndustryInput(); CompanyIndustryEditDto dto = new CompanyIndustryEditDto() { CompanyId = newModel.Id.Value, IndustryId = int.Parse(industryId) }; industryInput.CompanyIndustryEditDto = dto; await _companyIndustryAppService.CreateOrUpdateCompanyIndustryAsync(industryInput); } var relativeUser = _userAppService.Get(new EntityDto <long> { Id = model.CompanyEditDto.UserId }).Result; relativeUser.UserType = UserType.Company; if (model.CompanyAuthEditDto != null) { relativeUser.UserType = UserType.VipCompany; model.CompanyAuthEditDto.CompanyId = newModel.Id.Value; var newAuthModel = await _companyAuthAppService.CreateCompanyAuthAsync(model.CompanyAuthEditDto); } var user = _userAppService.UpdateUser(relativeUser); if (model.ContactEdit != null) { var contactEditDto = model.ContactEdit; contactEditDto.CompanyId = newModel.Id.Value; var newContactModel = await _contactAppService.CreateContactAsync(contactEditDto); if (contactEditDto.IsDefault) { await _contactAppService.SetContactDefault(newContactModel.CompanyId, newContactModel.Id.Value); } } } unitWork.Complete(); } return(Json(new { success = true, msg = "" })); } catch (Exception e) { return(Json(new { success = false, msg = "保存失败" })); } } return(Json(new { success = false, msg = "无操作权限" })); }
public async Task <JsonResult> SaveCompany(CreateOrUpdateCompanyInput model) { if (PermissionChecker.IsGranted("Pages.Company.EditCompany")) { try { var oldCompany = await _companyService.GetCompanyByUserId(model.CompanyEditDto.UserId); if (oldCompany == null || oldCompany.Id != model.CompanyEditDto.Id) { return(Json(new { success = false, msg = "不存在操作对象" })); } CheckModelState(); using (var unitWork = UnitOfWorkManager.Begin()) { await _companyService.UpdateCompanyAsync(model.CompanyEditDto); await _companyIndustryAppService.DeleteCompanyIndustryByCompanyIdAsync(model.CompanyEditDto.Id.Value); List <string> industryIds = model.CompanyEditDto.Industry.Split(',').ToList(); foreach (string industryId in industryIds) { CreateOrUpdateCompanyIndustryInput industryInput = new CreateOrUpdateCompanyIndustryInput(); CompanyIndustryEditDto dto = new CompanyIndustryEditDto() { CompanyId = model.CompanyEditDto.Id.Value, IndustryId = int.Parse(industryId) }; industryInput.CompanyIndustryEditDto = dto; await _companyIndustryAppService.CreateOrUpdateCompanyIndustryAsync(industryInput); } var relativeUser = _userAppService.Get(new EntityDto <long> { Id = model.CompanyEditDto.UserId }).Result; relativeUser.UserType = UserType.Company; if (model.CompanyAuthEditDto != null) { relativeUser.UserType = UserType.VipCompany; await _companyAuthAppService.CreateOrUpdateCompanyAuthAsync(new CreateOrUpdateCompanyAuthInput() { CompanyAuthEditDto = model.CompanyAuthEditDto }); } var user = _userAppService.UpdateUser(relativeUser); unitWork.Complete(); } return(Json(new { success = true, msg = "" })); } catch (Exception e) { return(Json(new { success = false, msg = "保存失败" })); } } return(Json(new { success = false, msg = "无操作权限" })); }
public virtual async Task <CompanyIndustryEditDto> CreateCompanyIndustryAsync(CompanyIndustryEditDto input) { //TODO:新增前的逻辑判断,是否允许新增 var entity = input.MapTo <CompanyIndustry>(); entity = await _companyIndustryRepository.InsertAsync(entity); return(entity.MapTo <CompanyIndustryEditDto>()); }