private static string GetPreferredName(Models.NormalPoint point) { switch (point.PreferredName) { case PreferredNameType.Chinese: return(point.ChineseName); case PreferredNameType.English: return(point.EnglishName); default: throw new ArgumentOutOfRangeException(nameof(point)); } }
private async Task <bool> PopulateGamePointAttributes(Models.NormalPoint normalPoint, NormalPointCreateOrUpdateOneRequestDto requestDto, bool isKeylolOperator, bool keepSteamAppId = false) { if (requestDto.DisplayAliases == null) { ModelState.AddModelError("vm.DisplayAliases", "游戏据点必须填写别名"); return(false); } if (requestDto.CoverImage == null) { ModelState.AddModelError("vm.CoverImage", "游戏据点必须填写封面图片"); return(false); } if (!Helpers.IsTrustedUrl(requestDto.CoverImage)) { ModelState.AddModelError("vm.CoverImage", "不允许使用可不信图片来源"); return(false); } if (requestDto.DeveloperPointsId == null) { ModelState.AddModelError("vm.DeveloperPointsId", "游戏据点必须填写开发商据点"); return(false); } if (requestDto.PublisherPointsId == null) { ModelState.AddModelError("vm.PublisherPointsId", "游戏据点必须填写发行商据点"); return(false); } if (requestDto.GenrePointsId == null) { ModelState.AddModelError("vm.GenrePointsId", "游戏据点必须填写类型据点"); return(false); } if (requestDto.TagPointsId == null) { ModelState.AddModelError("vm.TagPointsId", "游戏据点必须填写特性据点"); return(false); } if (requestDto.MajorPlatformPointsId == null) { ModelState.AddModelError("vm.MajorPlatformPointsId", "游戏据点必须填写主要平台据点"); return(false); } if (requestDto.MinorPlatformPointsId == null) { ModelState.AddModelError("vm.MinorPlatformPointsId", "游戏据点必须填写次要平台据点"); return(false); } if (requestDto.SeriesPointsId == null) { ModelState.AddModelError("vm.SeriesPointsId", "游戏据点必须填写系列据点"); return(false); } if (isKeylolOperator) { if (!keepSteamAppId) { if (requestDto.SteamAppId == null) { ModelState.AddModelError("vm.SteamAppId", "游戏据点的 App ID 不能为空"); return(false); } normalPoint.SteamAppId = requestDto.SteamAppId.Value; } if (requestDto.ReleaseDate == null) { ModelState.AddModelError("vm.ReleaseDate", "游戏据点的面世日期不能为空"); return(false); } normalPoint.ReleaseDate = requestDto.ReleaseDate.Value; } normalPoint.DisplayAliases = requestDto.DisplayAliases; normalPoint.CoverImage = requestDto.CoverImage; normalPoint.DeveloperPoints = await _dbContext.NormalPoints .Where( p => p.Type == NormalPointType.Manufacturer && requestDto.DeveloperPointsId.Contains(p.Id)) .ToListAsync(); normalPoint.PublisherPoints = await _dbContext.NormalPoints .Where( p => p.Type == NormalPointType.Manufacturer && requestDto.PublisherPointsId.Contains(p.Id)) .ToListAsync(); normalPoint.GenrePoints = await _dbContext.NormalPoints .Where(p => p.Type == NormalPointType.Genre && requestDto.GenrePointsId.Contains(p.Id)) .ToListAsync(); normalPoint.TagPoints = await _dbContext.NormalPoints .Where(p => p.Type == NormalPointType.Genre && requestDto.TagPointsId.Contains(p.Id)) .ToListAsync(); normalPoint.MajorPlatformPoints = await _dbContext.NormalPoints .Where( p => p.Type == NormalPointType.Platform && requestDto.MajorPlatformPointsId.Contains(p.Id)) .ToListAsync(); normalPoint.MinorPlatformForPoints = await _dbContext.NormalPoints .Where( p => p.Type == NormalPointType.Platform && requestDto.MinorPlatformPointsId.Contains(p.Id)) .ToListAsync(); normalPoint.SeriesPoints = await _dbContext.NormalPoints .Where(p => p.Type == NormalPointType.Genre && requestDto.SeriesPointsId.Contains(p.Id)) .ToListAsync(); return(true); }