public async Task UpdateOrSaveWebSiteInputBase_Check() { var full = WebSiteFull.MapFrom(InputSample.NewSaveWebSiteInput); Assert.NotNull(full.WebSite); await Task.CompletedTask; }
public async Task <ApiResult> UpdateWebSite(UpdateWebSiteInput input) { // 是否使用系统的配置 WhenUseSysAlipayPayment(input); WhenUseSysWeiXinPay(input); //todo:记录日志 var websiteTemp = _siteFullRepository.GetAllNoTracking() .Where(i => i.WebSite.Id == input.Id) .Select(i => new { i.WebSite.WebSiteMater, i.WebSite.WorkerName, i.WebSiteConfig.GivePointsPerMonth, i.WebSiteConfig.DefaultNotePrice, i.WebSiteConfig.DefaultJfPrice }).FirstOrDefault(); if (websiteTemp == null) { return(ApiResult.DataNotFound()); //throw new UserFriendlyException("该站点不存在,无法编辑!"); } // 更新站点 var insertWebsite = WebSiteFull.MapFrom(input); insertWebsite.WebSite.Id = input.Id; await _siteFullRepository.UpdateAsync(insertWebsite); // 站点管理员的 WorkerName 和 PROVINCEID 变更时 var UserSysSetting = await _userSysSettingRepository .FirstOrDefaultAsync(i => i.Id == input.WebSiteMater && i.WebSiteId == input.Id); if (UserSysSetting == null) { throw new UserFriendlyException("注意,总站信息不对!"); } if (UserSysSetting.Provinceid != input.PROVINCEID || UserSysSetting.Swfzr != input.WorkerName) { UserSysSetting.Provinceid = input.PROVINCEID; UserSysSetting.Swfzr = input.WorkerName; await _userSysSettingRepository.UpdateAsync(UserSysSetting); } // 每月赠送次数 变更时 var UserScore = await _userScoreRepository.FirstOrDefaultAsync(i => i.Id == input.WebSiteMater); if (UserScore != null) { if (UserScore.GivePointsPerMonth != input.GivePointsPerMonth) { UserScore.GivePointsPerMonth = input.GivePointsPerMonth; await _userScoreRepository.UpdateAsync(UserScore); } } //站点短信与积分单价变化时,更新所有站点用户的短信与积分单价,暂时不做这个操作 //if (website.DefaultJfPrice!=input.DefaultJfPrice // ||website.DefaultNotePrice!=input.DefaultNotePrice) //{ //} return(new ApiResult().Success()); }
public async Task <ApiResult <SaveWebSiteOutput> > SaveWebSite(SaveWebSiteInput input) { // 是否使用系统的配置 WhenUseSysAlipayPayment(input); WhenUseSysWeiXinPay(input); //todo:记日志 // 检查数据库中是否存在数据 var existedDatas = await _websiteRepository.GetAll() .Where(i => i.WebSiteKey == input.WebSiteKey || i.Id == input.Id) .Select(i => new { i.Id, i.WebSiteKey }).ToDynamicListAsync(); if (existedDatas.Any(i => i.Id == input.Id)) { throw new UserFriendlyException("站点Id已存在!"); } if (existedDatas.Any(i => i.WebSiteKey == input.WebSiteKey)) { throw new UserFriendlyException("订单Id前缀已存在!"); } // 创建站点管理员账号 // todo:管理员账号基础信息处理及角色分配 DateTime time = DateTime.Now; string userId = input.Id + time.ToString("yyyyMMddHHmmss") + RNG.Next(10).ToString().PadLeft(10, '0'); string safePassword = Guid.NewGuid().ToString("N").Substring(0, 6); // 创建站点 var siteFull = WebSiteFull.MapFrom(input); siteFull.WebSite.Id = input.Id; siteFull.WebSite.WebSiteMater = userId; var insertWebSiteTask = _siteFullRepository.InsertAsync(siteFull); // 创建站点管理员账号信息 var insertUserTask = _userRepository.InsertAsync(new Users { Id = userId, WebSiteId = input.Id, UserName = input.Loginname, LoginName = input.Loginname, EmailAddress = input.Email, Password = Encryptor.MD5Entry(safePassword), Safepassword = safePassword, IsActive = true, }); // 创建站点管理员附属信息(商务经理、省) var insertUserSysSettingTask = _userSysSettingRepository.InsertAsync(new UserSysSetting { Id = userId, Swfzr = input.WorkerName, Provinceid = input.PROVINCEID, WebSiteId = input.Id }); // 创建站点管理员的每月积分 var insertUserScoreTask = _userScoreRepository.InsertAsync(new UserScore { Id = userId, GivePointsPerMonth = input.GivePointsPerMonth, NotePrice = input.DefaultJfPrice, JfPrice = input.DefaultJfPrice }); await(insertWebSiteTask, insertUserTask, insertUserSysSettingTask, insertUserScoreTask); return(ApiResult.Success(new SaveWebSiteOutput { Safepassword = safePassword, LoginName = input.Loginname })); }