Exemplo n.º 1
0
        public async Task EditBuild(BuildModel buildModel)
        {
            await using (_context = new Sep3DBContext())
            {
                BuildModel buildModelDatabase = await _context.Builds
                                                .Include(b => b.BuildComponents)
                                                .FirstAsync(bld => bld.Id == buildModel.Id);

                buildModelDatabase.Name            = buildModel.Name;
                buildModelDatabase.BuildComponents = new Collection <BuildComponent>();

                for (var i = 0; i < buildModel.ComponentList.Count(); i++)
                {
                    ComponentModel arg = await _context.Components
                                         .FirstAsync(c => c.Id == buildModel.ComponentList[i].Id);

                    BuildComponent buildComponent = new BuildComponent
                    {
                        BuildId        = buildModelDatabase.Id,
                        BuildModel     = buildModelDatabase,
                        ComponentId    = arg.Id,
                        ComponentModel = arg
                    };
                    buildModelDatabase.BuildComponents.Add(buildComponent);
                }

                _context.Update(buildModelDatabase);
                await _context.SaveChangesAsync();
            }
        }
Exemplo n.º 2
0
        public async Task CreateBuild(BuildModel buildModel)
        {
            await using (_context = new Sep3DBContext())
            {
                buildModel.Ratings = new List <RatingBuildModel>();
                await _context.Builds.AddAsync(buildModel);

                await _context.SaveChangesAsync();

                AccountModel accountModel = await _context.Accounts
                                            .Include(a => a.Builds)
                                            .FirstAsync(account => account.UserId == buildModel.AccountModelUserId);

                BuildModel databaseBuild = await _context.Builds.OrderBy(b => b.Id).LastAsync();

                if (accountModel.Builds == null)
                {
                    accountModel.Builds = new List <BuildModel>();
                }
                accountModel.Builds.Add(databaseBuild);
                _context.Update(accountModel);

                if (databaseBuild.BuildComponents == null)
                {
                    databaseBuild.BuildComponents = new List <BuildComponent>();
                }

                for (var i = 0; i < databaseBuild.ComponentList.Count; i++)
                {
                    ComponentModel arg = await _context.Components.FirstAsync(c => c.Id == databaseBuild.ComponentList[i].Id);

                    BuildComponent buildComponent = new BuildComponent
                    {
                        BuildId        = databaseBuild.Id,
                        BuildModel     = databaseBuild,
                        ComponentId    = arg.Id,
                        ComponentModel = arg
                    };
                    databaseBuild.BuildComponents.Add(buildComponent);
                }

                _context.Update(databaseBuild);
                await _context.SaveChangesAsync();
            }
        }
Exemplo n.º 3
0
        public async Task AddComponentToBuild(int buildId, int componentId)
        {
            await using (_context = new Sep3DBContext())
            {
                BuildModel buildModel = await _context.Builds.FirstAsync(b => b.Id == buildId);

                ComponentModel componentModel = await _context.Components
                                                .Include(c => c.Ratings)
                                                .FirstAsync(c => c.Id == componentId);

                BuildComponent buildComponent = new BuildComponent
                {
                    BuildId        = buildModel.Id,
                    BuildModel     = buildModel,
                    ComponentId    = componentModel.Id,
                    ComponentModel = componentModel
                };
                if (buildModel.BuildComponents == null)
                {
                    buildModel.BuildComponents = new List <BuildComponent>();
                    buildModel.BuildComponents.Add(buildComponent);
                    Console.WriteLine("added from null");
                }
                else
                {
                    buildModel.BuildComponents.Add(buildComponent);
                    Console.WriteLine("added from existed");
                }

                foreach (var variable in buildModel.BuildComponents)
                {
                    Console.WriteLine("buildId= " + variable.BuildId + "\n Build model= " + variable.BuildModel + "componentId= " + variable.ComponentId +
                                      "\n Component model= " + variable.ComponentModel);
                }
                _context.Update(buildModel);
                await _context.SaveChangesAsync();
            }
        }