Ejemplo n.º 1
0
        private Module CreateModule(
            string name,
            string desc,
            IEnumerable <ModuleReplacement> replacements,
            IEnumerable <ModuleTag> tags,
            ApplicationUser account)
        {
            var module = new Module()
            {
                Name                = name,
                Description         = desc,
                PublishedDateTime   = DateTime.Now,
                LastUpdatedDateTime = DateTime.Now,
                Author              = account,
                GithubLink          = _faker.Random.Bool(0.8f) ? "https://github.com/DofMod/SmithMagic" : null,
                IsCore              = _faker.Random.Bool()
            };

            _db.Modules.Add(module);

            _db.SaveChanges();

            foreach (var r in replacements)
            {
                var moduleModuleReplacementRelation = new ModuleModuleReplacementRelation()
                {
                    Module            = module,
                    ModuleReplacement = r,
                };
                _db.ModuleModuleReplacementRelations.Add(moduleModuleReplacementRelation);
            }

            foreach (var tag in tags)
            {
                var moduleModuleTagRelation = new ModuleModuleTagRelation()
                {
                    Module    = module,
                    ModuleTag = tag,
                };
                _db.ModuleModuleTagRelations.Add(moduleModuleTagRelation);
            }

            _db.SaveChanges();

            return(module);
        }
Ejemplo n.º 2
0
        public async Task <Module> CreateModule(string token,
                                                string name,
                                                string description,
                                                string githubLink,
                                                IReadOnlyCollection <ModuleReplacement> replacements,
                                                bool isCore)
        {
            var account = await GetAccountFromToken(token);

            var module = new Module()
            {
                Name                = name,
                Description         = description,
                IsCore              = isCore,
                PublishedDateTime   = DateTime.Now,
                LastUpdatedDateTime = DateTime.Now,
                AuthorId            = account.Id,
                GithubLink          = githubLink,
            };
            await _applicationDbContext.Modules.AddAsync(module);

            foreach (var r in replacements)
            {
                var replacement = new ModuleReplacement()
                {
                    Link = r.Link,
                    Name = r.Name,
                };
                await _applicationDbContext.ModuleReplacements.AddAsync(replacement);

                var moduleModuleReplacementRelation = new ModuleModuleReplacementRelation()
                {
                    Module            = module,
                    ModuleReplacement = replacement,
                };
                await _applicationDbContext.ModuleModuleReplacementRelations.AddAsync(moduleModuleReplacementRelation);
            }

            await _applicationDbContext.SaveChangesAsync();

            return(module);
        }