public ActionResult AddCompany(TCompany company) { company.ParenttCompanyId = Company.CompanyId; company.CompanyId = Guid.NewGuid(); company.CreateTime = DateTime.Now; company.ModifyTime = DateTime.Now; var result = AccountService.AddCompany(company, null); return(new MyJsonResult { Data = result }); }
/// <summary> /// 添加公司 /// </summary> /// <param name="company">公司信息</param> /// <param name="operational">操作信息</param> /// <returns>结果</returns> public static Result AddCompany(TCompany company, Operational operational) { Result result = new Result(); try { // 将领域对象转化成数据库实体对象 var mCompany = company.ToMCompany(); var registerAccount = mCompany.ToRegisterAccount(); // 创建用户对象 var account = new Account(registerAccount); account.AddUser(); account.SetCompanyId(mCompany.CompanyId); // 将领域对象转化成数据库实体对象 var mAccount = account.ToMAccount(); // 通过工资单元持久化数据 using (var unit = DbContext.CreateIPowerUnitOfWork()) { var accountesRepository = DbContext.CreateIAccountesRepository(unit); var companyRepository = DbContext.CreateICompanyRepository(unit); accountesRepository.Add(mAccount); companyRepository.Add(mCompany); unit.Complete(); } result.IsSucceed = true; result.Message = "添加成功"; } catch (CustomException ex) { result.IsSucceed = false; result.Message = ex.Message; } catch (Exception ex) { result.IsSucceed = false; result.Message = "添加失败"; // 记录异常日志 LogService.WriteLog(ex, "添加公司"); } return(result); }
/// <summary> /// 对象转化 /// </summary> /// <param name="company">Company</param> /// <returns>TCompany</returns> public static MCompany ToMCompany(this TCompany company) { var tCompany = new MCompany { CompanyId = company.CompanyId, CompanyAccountNo = company.CompanyAccountNo, CompanyAddress = company.CompanyAddress ?? string.Empty, CompanyName = company.CompanyName, CompanyStatus = company.CompanyStatus, ContactName = company.ContactName ?? string.Empty, ContactPhone = company.ContactPhone ?? string.Empty, ModifyTime = company.ModifyTime, ParenttCompanyId = company.ParenttCompanyId, CreateTime = company.CreateTime }; return(tCompany); }
/// <summary> /// 对象转化 /// </summary> /// <param name="company">Company</param> /// <returns>TCompany</returns> public static TCompany ToTCompany(this Company company) { var tCompany = new TCompany { CompanyId = company.Key, CompanyAccountNo = company.CompanyAccountNo, CompanyAddress = company.CompanyAddress, CompanyName = company.CompanyName, CompanyStatus = company.CompanyStatus, ContactName = company.ContactName, ContactPhone = company.ContactPhone, ModifyTime = company.ModifyTime, ParenttCompanyId = company.ParenttCompanyId, CreateTime = company.CreateTime }; return(tCompany); }