Exemplo n.º 1
0
        public override void Add(Game item, string cultureCode)
        {
            AssignIdIfEmpty(item);
            if (item.Genres == null)
            {
                item.Genres = item.NameGenres != null?_genreRepository.LoadDomainEntities(item.NameGenres) : _genreRepository.Get(genre => genre.Locals.Any(z => z.Name == "Other")).ToList();
            }

            item.PlatformTypes = item.NamePlatformTypes != null?_platformRepository.LoadDomainEntities(item.NamePlatformTypes) : null;

            if (item.Publisher != null)
            {
                item.Publisher = _publisherRepository.GetItemById(item.Publisher.Id);
            }

            if (!item.Locals.Any())
            {
                item.Locals = new List <GameLocal>()
                {
                    new GameLocal()
                    {
                        Culture = new Culture()
                        {
                            Code = cultureCode
                        },
                        Description = item.Description
                    }
                };
            }

            _gameRepository.Add(item);
            UnitOfWork.Save();
            Logger.Write(Operation.Insert, item);
        }