public async Task <IActionResult> AddHospitalAsync([FromBody] AddHospitalRequestDto request) { HospitalBiz hospitalBiz = new HospitalBiz(); if (await hospitalBiz.AnyAccountAsync(request.Account)) { return(Failed(ErrorCode.UserData, "已经存在相同的账号!")); } var hospitalGuid = Guid.NewGuid().ToString("N"); var textGuid = Guid.NewGuid().ToString("N"); request.Content = string.IsNullOrWhiteSpace(request.Content) ? "暂无详细" : request.Content; request.HosTag = string.IsNullOrWhiteSpace(request.HosTag) ? "暂无标签" : request.HosTag; var richtextModel = new RichtextModel { Content = request.Content, CreatedBy = UserID, CreationDate = DateTime.Now, Enable = true, LastUpdatedBy = UserID, LastUpdatedDate = DateTime.Now, OrgGuid = string.Empty, OwnerGuid = hospitalGuid, TextGuid = textGuid, }; var hospitalModel = new HospitalModel { HosAbstract = request.HosAbstract, HosDetailGuid = textGuid, HosLevel = request.HosLevel, HosName = request.HosName, HosTag = request.HosTag, Location = request.Location, LogoGuid = request.LogoGuid, PlatformType = PlatformType.CloudDoctor.ToString(), RegisteredDate = request.RegisteredDate, Visibility = request.Visibility, HospitalGuid = hospitalGuid, CreatedBy = UserID, LastUpdatedBy = UserID, Enable = request.Enable, OrgGuid = string.Empty, ContactNumber = request.ContactNumber, Sort = request.Sort, GuidanceUrl = request.GuidanceUrl ?? string.Empty, ExternalLink = request.ExternalLink ?? string.Empty, Password = CryptoHelper.AddSalt(hospitalGuid, request.Password), Account = request.Account, IsHospital = request.IsHospital, Longitude = request.Longitude, Latitude = request.Latitude }; var officeAll = await new OfficeBiz().GetAllAsync2(); var offices = officeAll.Select(a => (new { a.OfficeName, ParentName = officeAll.FirstOrDefault(b => b.OfficeGuid == a.ParentOfficeGuid)?.OfficeName, a.Sort, a.Enable, a.PictureGuid })).Distinct(); var offices2 = new List <OfficeModel>(); foreach (var item in offices) { GetOfficeModel(item.ParentName, item.OfficeName, item.Sort, item.Enable, item.PictureGuid, hospitalModel, offices2, offices); } var result = await hospitalBiz.AddAsync(hospitalModel, richtextModel, offices2); if (!result) { return(Failed(ErrorCode.UserData, "添加失败")); } return(Success()); }
public async Task <IActionResult> UpdateHospitalAsync([FromBody] UpdateHospitalRequestDto request) { var hospitalBiz = new HospitalBiz(); var hospitalModel = await hospitalBiz.GetAsync(request.HospitalGuid); if (hospitalModel == null) { return(Failed(ErrorCode.DataBaseError, "数据错误")); } if (request.Account != hospitalModel.Account && await hospitalBiz.AnyAccountAsync(request.Account)) { return(Failed(ErrorCode.UserData, "已经存在相同的账号!")); } var contentBiz = new RichtextBiz(); request.Content = string.IsNullOrWhiteSpace(request.Content) ? "暂无详细" : request.Content; request.HosTag = string.IsNullOrWhiteSpace(request.HosTag) ? "暂无标签" : request.HosTag; var richtextModel = await contentBiz.GetAsync(hospitalModel.HosDetailGuid); var richtextIsAdd = false; if (richtextModel != null) { richtextModel.Content = request.Content; richtextModel.LastUpdatedBy = UserID; richtextModel.LastUpdatedDate = DateTime.Now; richtextModel.OrgGuid = string.Empty; richtextModel.OwnerGuid = request.HospitalGuid; } else { var textGuid = Guid.NewGuid().ToString("N"); richtextModel = new RichtextModel { Content = request.Content, CreatedBy = UserID, CreationDate = DateTime.Now, Enable = true, LastUpdatedBy = UserID, LastUpdatedDate = DateTime.Now, OrgGuid = string.Empty, OwnerGuid = hospitalModel.HospitalGuid, TextGuid = textGuid, }; hospitalModel.HosDetailGuid = textGuid; richtextIsAdd = true; } hospitalModel.HosAbstract = request.HosAbstract; hospitalModel.HosLevel = request.HosLevel; hospitalModel.HosName = request.HosName; hospitalModel.HosTag = request.HosTag; hospitalModel.Location = request.Location; hospitalModel.LogoGuid = request.LogoGuid; hospitalModel.RegisteredDate = request.RegisteredDate; hospitalModel.Visibility = request.Visibility; hospitalModel.LastUpdatedBy = UserID; hospitalModel.LastUpdatedDate = DateTime.Now; hospitalModel.Enable = request.Enable; hospitalModel.ContactNumber = request.ContactNumber; hospitalModel.Sort = request.Sort; hospitalModel.GuidanceUrl = request.GuidanceUrl ?? string.Empty; hospitalModel.ExternalLink = request.ExternalLink ?? string.Empty; hospitalModel.Account = request.Account; hospitalModel.IsHospital = request.IsHospital; hospitalModel.Longitude = request.Longitude; hospitalModel.Latitude = request.Latitude; if (null != request.Password) { hospitalModel.Password = CryptoHelper.AddSalt(hospitalModel.HospitalGuid, request.Password); } var response = await hospitalBiz.UpdateAsync(hospitalModel, richtextModel, richtextIsAdd); if (!response) { return(Failed(ErrorCode.DataBaseError, "修改失败")); } return(Success(response)); }