Esempio n. 1
0
        public async Task <int> AddPlatformAsync(PlatformAddModel platform)
        {
            string query = $@"INSERT INTO Platform (Name)
                    OUTPUT Inserted.PlatformId VALUES(@Name)";

            return(await SaveDataAsync(query, platform));
        }
Esempio n. 2
0
        public async Task <int> AddPlatform(PlatformAddModel platform)
        {
            var validator = DataValidatorHelper.Validate(platform);

            if (validator.IsValid)
            {
                var platformDb = await _gamedbAccess.GetPlatformByNameAsync(platform.Name);

                if (platformDb == null)
                {
                    return(await _gamedbAccess.AddPlatformAsync(platform));
                }

                return(platformDb.PlatformId);
            }

            Console.WriteLine($"Invalid Data from {nameof(ReleaseDateAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }