Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] Experiment experiment)
        {
            if (id != experiment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var form = Request.Form;
                    experiment.ExpArtefacts = new List <ExpArtefact>();
                    experiment.ExpJudges    = new List <ExpJudge>();
                    var    expID        = experiment.Id;
                    string expNameParam = form["Parameters"];
                    var    expParam     = await _context.ExperimentParameters
                                          .FirstOrDefaultAsync(m => m.Description == expNameParam);

                    int expParamID = expParam.Id;
                    experiment.ExperimentParametersId = expParamID;
                    experiment.ExperimentParameters   = expParam;

                    var artefacts = form["expArtefacts"];
                    foreach (string x in artefacts)
                    {
                        var artefactName = x.Trim();
                        var expArtefact  = await _context.Artefact.
                                           FirstOrDefaultAsync(m => m.Name == artefactName);

                        var         artefactID = expArtefact.Id;
                        ExpArtefact exp        = new ExpArtefact();
                        exp.ExperimentId = expID;
                        exp.ArtefactId   = artefactID;
                        exp.Experiment   = experiment;
                        exp.Artefact     = expArtefact;
                        experiment.ExpArtefacts.Add(exp);
                    }

                    var judges = form["expJudges"];
                    foreach (string x in judges)
                    {
                        var judgeName = x.Trim();
                        var judge     = await _context.Judge.
                                        FirstOrDefaultAsync(m => m.Name == judgeName);

                        var      judgeID = judge.Id;
                        ExpJudge exp     = new ExpJudge();
                        exp.ExperimentId = expID;
                        exp.JudgeLoginId = judge.LoginId;
                        exp.Experiment   = experiment;
                        exp.Judge        = judge;
                        experiment.ExpJudges.Add(exp);
                    }
                    _context.Update(experiment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExperimentExists(experiment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(experiment));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] Experiment experiment)
        {
            var form = Request.Form;

            experiment.ExpArtefacts   = new List <ExpArtefact>();
            experiment.ExpJudges      = new List <ExpJudge>();
            experiment.ExpResearchers = new List <ExpResearcher>();
            experiment.ExpAlgorithms  = new List <ExpAlgorithm>();

            var    expID        = experiment.Id;
            string expNameParam = form["Parameters"];
            var    expParam     = await _context.ExperimentParameters
                                  .FirstOrDefaultAsync(m => m.Description == expNameParam);

            int expParamID = expParam.Id;

            experiment.ExperimentParametersId = expParamID;
            experiment.ExperimentParameters   = expParam;

            var expAlgorithmName = form["algorithms"];
            var expAlgorithm     = await _context.Algorithm
                                   .FirstOrDefaultAsync(m => m.Description == expAlgorithmName);

            int          expAlgorithmID = expAlgorithm.Id;
            ExpAlgorithm expAL          = new ExpAlgorithm();

            expAL.AlgorithmId  = expAlgorithmID;
            expAL.Algorithm    = expAlgorithm;
            expAL.Experiment   = experiment;
            expAL.ExperimentId = expID;
            experiment.ExpAlgorithms.Add(expAL);

            var artefacts = form["expArtefacts"];

            foreach (string x in artefacts)
            {
                var artefactName = x.Trim();
                var expArtefact  = await _context.Artefact.
                                   FirstOrDefaultAsync(m => m.Name == artefactName);

                var         artefactID = expArtefact.Id;
                ExpArtefact exp        = new ExpArtefact();
                exp.ExperimentId = expID;
                exp.ArtefactId   = artefactID;
                exp.Experiment   = experiment;
                exp.Artefact     = expArtefact;
                experiment.ExpArtefacts.Add(exp);
            }

            var judges = form["expJudges"];

            foreach (string x in judges)
            {
                var judgeName = x.Trim();
                var judge     = await _context.Judge.
                                FirstOrDefaultAsync(m => m.Name == judgeName);

                var      judgeID = judge.Id;
                ExpJudge exp     = new ExpJudge();
                exp.ExperimentId = expID;
                exp.JudgeLoginId = judge.LoginId;
                exp.Experiment   = experiment;
                exp.Judge        = judge;
                experiment.ExpJudges.Add(exp);
            }

            var           researcher    = GetCurrentUserAsync().Result.Id;
            ExpResearcher expResearcher = new ExpResearcher();

            expResearcher.ResearcherLoginId = researcher;
            expResearcher.Researcher        = await _context.Researcher.
                                              FirstOrDefaultAsync(r => r.LoginId == researcher);

            expResearcher.ExperimentId = expID;
            expResearcher.Experiment   = experiment;
            experiment.ExpResearchers.Add(expResearcher);

            if (ModelState.IsValid)
            {
                _context.Add(experiment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(experiment));
        }