Пример #1
0
        /// <summary>
        /// Executes an upsert/delete operation on a simulation's deficient library data regardless of ownership
        /// Throws a RowNotInTableException if no simulation is found
        /// </summary>
        /// <param name="model">DeficientLibraryModel</param>
        /// <param name="db">BridgeCareContext</param>
        /// <param name="username">Username</param>
        /// <returns>DeficientLibraryModel</returns>
        public DeficientLibraryModel SaveAnySimulationDeficientLibrary(DeficientLibraryModel 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(SaveSimulationDeficientLibrary(model, db));
        }
Пример #2
0
        /// <summary>
        /// Executes an upsert/delete operation on a simulation's deficient library data if the user owns it
        /// Throws a RowNotInTableException if no simulation is found for the user
        /// </summary>
        /// <param name="model">DeficientLibraryModel</param>
        /// <param name="db">BridgeCareContext</param>
        /// <param name="username">Username</param>
        /// <returns>DeficientLibraryModel</returns>
        public DeficientLibraryModel SavePermittedSimulationDeficientLibrary(DeficientLibraryModel 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 deficients.");
            }
            return(SaveSimulationDeficientLibrary(model, db));
        }
Пример #3
0
        /// <summary>
        /// Executes an upsert/delete operation on a simulation's deficient library data
        /// Throws a RowNotInTableException if no simulation is found
        /// </summary>
        /// <param name="model">DeficientLibraryModel</param>
        /// <param name="db">BridgeCareContext</param>
        /// <returns>DeficientLibraryModel</returns>
        public DeficientLibraryModel SaveSimulationDeficientLibrary(DeficientLibraryModel 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.DEFICIENTS).Single(s => s.SIMULATIONID == id);

            if (simulation.DEFICIENTS.Any())
            {
                simulation.DEFICIENTS.ToList().ForEach(deficientEntity =>
                {
                    var deficientModel = model.Deficients.SingleOrDefault(m => m.Id == deficientEntity.ID_.ToString());

                    if (deficientModel == null)
                    {
                        DeficientsEntity.DeleteEntry(deficientEntity, db);
                    }
                    else
                    {
                        deficientModel.matched = true;
                        deficientModel.UpdateDeficient(deficientEntity);
                    }
                });
            }

            if (model.Deficients.Any(m => !m.matched))
            {
                db.Deficients
                .AddRange(model.Deficients
                          .Where(deficientModel => !deficientModel.matched)
                          .Select(deficientModel => new DeficientsEntity(id, deficientModel))
                          .ToList()
                          );
            }

            db.SaveChanges();

            return(new DeficientLibraryModel(simulation));
        }
Пример #4
0
 public IHttpActionResult SaveSimulationDeficientLibrary([FromBody] DeficientLibraryModel model)
 => Ok(repo.SaveSimulationDeficientLibrary(model, db));
Пример #5
0
        public IHttpActionResult SaveSimulationDeficientLibrary([FromBody] DeficientLibraryModel model)
        {
            UserInformationModel userInformation = ESECSecurity.GetUserInformation(Request);

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