コード例 #1
0
        public PerformanceLibraryModel SaveAnySimulationPerformanceLibrary(PerformanceLibraryModel model, BridgeCareContext db)
        {
            var id = int.Parse(model.Id);

            if (!db.Simulations.Any(s => s.SIMULATIONID == id))
            {
                throw new RowNotInTableException($"No scenario was found with id {id}");
            }
            return(SaveSimulationPerformanceLibrary(model, db));
        }
コード例 #2
0
        public PerformanceLibraryModel SavePermittedSimulationPerformanceLibrary(PerformanceLibraryModel model, BridgeCareContext db, string username)
        {
            var id = int.Parse(model.Id);

            if (!db.Simulations.Any(s => s.SIMULATIONID == id))
            {
                throw new RowNotInTableException($"No scenario was found with id {id}");
            }
            if (!db.Simulations.Include(s => s.USERS).First(s => s.SIMULATIONID == id).UserCanModify(username))
            {
                throw new UnauthorizedAccessException("You are not authorized to modify this scenario's performance.");
            }
            return(SaveSimulationPerformanceLibrary(model, db));
        }
コード例 #3
0
ファイル: PerformanceLibraryDAL.cs プロジェクト: radtek/iAM
        /// <summary>
        /// Executes an upsert/delete operation on a simulation's performance library data
        /// Throws a RowNotInTableException if no simulation is found
        /// </summary>
        /// <param name="model">PerformanceLibraryModel</param>
        /// <param name="db">BridgeCareContext</param>
        /// <returns>PerformanceLibraryModel</returns>
        public PerformanceLibraryModel SaveSimulationPerformanceLibrary(PerformanceLibraryModel model, BridgeCareContext db)
        {
            var id = int.Parse(model.Id);

            if (!db.Simulations.Any(s => s.SIMULATIONID == id))
            {
                throw new RowNotInTableException($"No scenario was found with id {id}");
            }

            var simulation = db.Simulations.Include(s => s.PERFORMANCES).Single(s => s.SIMULATIONID == id);

            if (simulation.PERFORMANCES.Any())
            {
                simulation.PERFORMANCES.ToList().ForEach(performanceEntity =>
                {
                    var performanceModel = model.Equations
                                           .SingleOrDefault(m => m.Id == performanceEntity.PERFORMANCEID.ToString());

                    if (performanceModel == null)
                    {
                        PerformanceEntity.DeleteEntry(performanceEntity, db);
                    }
                    else
                    {
                        performanceModel.matched = true;
                        performanceModel.UpdatePerformance(performanceEntity);
                    }
                });
            }

            if (model.Equations.Any(m => !m.matched))
            {
                db.Performances.AddRange(model.Equations
                                         .Where(performanceModel => !performanceModel.matched)
                                         .Select(performanceModel => new PerformanceEntity(id, performanceModel))
                                         .ToList()
                                         );
            }

            db.SaveChanges();

            return(new PerformanceLibraryModel(simulation));
        }
コード例 #4
0
        public IHttpActionResult SaveSimulationPerformanceLibrary([FromBody] PerformanceLibraryModel model)
        {
            var performanceLibraryModel = repo.SaveSimulationPerformanceLibrary(model, db);

            return(Ok(performanceLibraryModel));
        }
コード例 #5
0
        public IHttpActionResult SaveSimulationPerformanceLibrary([FromBody] PerformanceLibraryModel model)
        {
            UserInformationModel userInformation = ESECSecurity.GetUserInformation(Request);

            return(Ok(PerformanceLibrarySaveMethods[userInformation.Role](model, userInformation)));
        }