예제 #1
0
 public void UpdateTarget(TargetsEntity entity)
 {
     entity.ATTRIBUTE_ = Attribute;
     entity.TARGETNAME = Name;
     entity.YEARS      = Year;
     entity.TARGETMEAN = TargetMean;
     entity.CRITERIA   = Criteria;
 }
예제 #2
0
 public TargetParameters(TargetsEntity entity)
 {
     Id         = entity.ID_;
     Attribute  = entity.ATTRIBUTE_;
     TargetMean = entity.TARGETMEAN ?? 0;
     Name       = entity.TARGETNAME;
     Criteria   = entity.CRITERIA;
     Row        = 0;
 }
예제 #3
0
 public TargetModel(TargetsEntity entity)
 {
     Id         = entity.ID_.ToString();
     Attribute  = entity.ATTRIBUTE_;
     Name       = entity.TARGETNAME;
     Year       = entity.YEARS ?? DateTime.Now.Year;
     TargetMean = entity.TARGETMEAN ?? 0;
     Criteria   = entity.CRITERIA;
 }
예제 #4
0
파일: TargetsDAL.cs 프로젝트: radtek/iAM
        /// <summary>
        /// Executes an upsert/delete operation on a simulation's target library data
        /// Throws a RowNotInTableException if no simulation is found
        /// </summary>
        /// <param name="model">TargetLibraryModel</param>
        /// <param name="db">BridgeCareContext</param>
        /// <returns>TargetLibraryModel</returns>
        public TargetLibraryModel SaveSimulationTargetLibrary(TargetLibraryModel 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.TARGETS).Single(s => s.SIMULATIONID == id);

            if (simulation.TARGETS.Any())
            {
                simulation.TARGETS.ToList().ForEach(targetEntity =>
                {
                    var targetModel = model.Targets.SingleOrDefault(m => m.Id == targetEntity.ID_.ToString());

                    if (targetModel == null)
                    {
                        TargetsEntity.DeleteEntry(targetEntity, db);
                    }
                    else
                    {
                        targetModel.matched = true;
                        targetModel.UpdateTarget(targetEntity);
                    }
                });
            }

            if (model.Targets.Any(m => !m.matched))
            {
                db.Targets
                .AddRange(model.Targets
                          .Where(targetModel => !targetModel.matched)
                          .Select(targetModel => new TargetsEntity(id, targetModel))
                          .ToList()
                          );
            }

            db.SaveChanges();

            return(new TargetLibraryModel(simulation));
        }