public static ModelRiskAlert Get(int idModelRiskAlert)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelRiskAlerts.FirstOrDefault(mra => mra.IDModelRiskAlert == idModelRiskAlert));
     }
 }
 /// <summary>
 /// Returns the ModelRiskAlert by idModel and regions
 /// </summary>
 /// <param name="idModel"></param>
 /// <param name="regions"></param>
 /// <param name="isActive"></param>
 /// <returns></returns>
 public static List <ModelRiskAlert> GetWithFilter(int?idModel, List <int> regions, bool?isActive)
 {
     //TODO: this method should return the CHILDS from the regions list also. Compare to [dbo].[spModelRiskAlert_GetWithFilter]
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         if (regions.Count > 0)
         {
             IQueryable <ModelRiskAlert> modelRiskAlerts = context.ModelRiskAlerts;
             //List<Region> childs = RegionManager.GetChilds()
             IQueryable <ModelRiskAlertRegion> modelRiskAlertsRegions =
                 context.ModelRiskAlertRegions.Where(mrar => regions.Contains(mrar.IDRegion));
             IQueryable <Model> models = context.Models;
             return((from mra in modelRiskAlerts
                     join mrar in modelRiskAlertsRegions
                     on mra.IDModelRiskAlert equals mrar.IDModelRiskAlert
                     join m in models
                     on mra.IDModel equals m.IDModel
                     where (isActive == null || mra.Active == isActive) &&
                     (idModel == null || mra.IDModel == idModel)
                     select mra).ToList());
         }
         else
         {
             IQueryable <ModelRiskAlert> modelRiskAlerts = context.ModelRiskAlerts;
             IQueryable <Model>          models          = context.Models;
             return((from mra in modelRiskAlerts
                     join m in models
                     on mra.IDModel equals m.IDModel
                     where (isActive == null || mra.Active == isActive) &&
                     (idModel == null || mra.IDModel == idModel)
                     select mra).ToList());
         }
     }
 }
 /// <summary>
 /// Returns the Marker with IDMarker = idMarker.
 /// </summary>
 /// <param name="idMarker"></param>
 /// <returns></returns>
 public static Marker Get(int idMarker)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return((from m in context.Markers where m.IDMarker == idMarker select m).FirstOrDefault());
     }
 }
 /// <summary>
 /// Returns list the all Markers with IDModel = idModel.
 /// </summary>
 /// <param name="idModel"></param>
 /// <returns></returns>
 public static List <Marker> GetByModelId(int idModel)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Markers.Where(m => m.IDModel == idModel).ToList());
     }
 }
 /// <summary>
 /// Returns the list of all the ModelFactorDatas.
 /// </summary>
 /// <returns></returns>
 public static List <ModelFactorData> GetAll()
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelFactorDatas.ToList());
     }
 }
Exemple #6
0
 /// <summary>
 ///  Returns the PhaseBullet by idPhase and columnNumber.
 /// </summary>
 /// <param name="idPhase"></param>
 /// <param name="columnNumber"></param>
 /// <returns></returns>
 public static List <PhaseBullet> GetByPhaseAndColumn(int idPhase, int columnNumber)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return((from o in context.PhaseBullets where o.IDPhase == idPhase && o.ColumnNumber == columnNumber select o).OrderBy(o => o.SortOrder).ToList());
     }
 }
Exemple #7
0
        /// <summary>
        /// Saves the ModelRiskAlertAttachment.
        /// </summary>
        /// <param name="modelRiskAlertAttachment"></param>
        /// <returns></returns>
        public static ModelRiskAlertAttachment Save(ModelRiskAlertAttachment modelRiskAlertAttachment)
        {
            using (IdeaContext context = ContextManager.GetNewDataContext())
            {
                context.ModelRiskAlertAttachments.AddOrUpdate(modelRiskAlertAttachment);
                context.SaveChanges();
                //Document attachmentDocument = new Document();

                // attachmentDocument.Content = Convert.ToBase64String(Encoding.ASCII.GetBytes(modelRiskAlertAttachment.Content));

                string path     = DirectoryAndFileHelper.ServerAppDataFolder + ConfigurationManager.AppSettings["RARDocumentsFolder"];
                string fileName = modelRiskAlertAttachment.IDModelRiskAlertAttachment + "-" + modelRiskAlertAttachment.AttachmentFile;
                if (!File.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //attachmentDocument.Filename = Path.GetFileName(path + fileName);
                //attachmentDocument.DocumentType = ERMTDocumentType.Document;



                DocumentManager.Save(path + fileName, Convert.FromBase64String(modelRiskAlertAttachment.Content));

                return(modelRiskAlertAttachment);
            }
        }
 /// <summary>
 /// Gets and Returns the list of map data with parameters: idModelFactor, regionsIds and DateTime.
 /// </summary>
 /// <param name="idModelFactor"></param>
 /// <param name="regionsIds"></param>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <returns></returns>
 public static List <ModelFactorData> GetMapData(int idModelFactor, string regionsIds, DateTime from, DateTime to)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         var o   = (context.spModelFactorData_GetMapData(idModelFactor, regionsIds, from, to));
         var aux = from o2 in o
                   let dtModified = o2.dt_modified
                                    where dtModified != null
                                    let data = o2.Data
                                               where data != null
                                               let dateTime = o2.Date
                                                              where dateTime != null
                                                              let dtCreated = o2.dt_created
                                                                              where dtCreated != null
                                                                              let idModelFactorData = o2.IDModelFactorData
                                                                                                      where idModelFactorData != null
                                                                                                      select new ModelFactorData
         {
             IDModelFactor     = o2.IDModelFactor,
             Data              = (Decimal)data,
             Date              = (DateTime)dateTime,
             DateModified      = (DateTime)dtModified,
             DateCreated       = (DateTime)dtCreated,
             IDModelFactorData = (int)idModelFactorData,
             IDRegion          = o2.IDRegion
         };
         return(aux.ToList());
     }
 }
Exemple #9
0
 public static Phase Get(int idPhase)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Phases.FirstOrDefault(p => p.IDPhase == idPhase));
     }
 }
        public void SetUp()
        {
            // Arrange
            IdeaContext context = TestIdeaContextFactory.Create(NUM_IDEAS);

            _controller = new HomeController(context);
        }
        /// <summary>
        /// Saves a new factor, first deletes all the fields.
        /// </summary>
        /// <param name="factor"></param>
        public static void Save(Factor factor, String culture)
        {
            factor.Introduction         = CleanFormat(factor.Introduction);
            factor.EmpiricalCases       = CleanFormat(factor.EmpiricalCases);
            factor.DataCollection       = CleanFormat(factor.DataCollection);
            factor.Questionnaire        = CleanFormat(factor.Questionnaire);
            factor.ObservableIndicators = CleanFormat(factor.ObservableIndicators);

            if (factor.Description == null)
            {
                factor.Description = string.Empty;
            }

            if (factor.HtmlDocument == null)
            {
                factor.HtmlDocument = string.Empty;
            }

            factor.HtmlDocument = factor.IdFactor + ".htm";

            GenerateFactorHTML(factor, culture);

            using (IdeaContext context = ContextManager.GetNewDataContext())
            {
                context.Factors.AddOrUpdate(factor);
                context.SaveChanges();
            }
        }
 /// <summary>
 /// Returns the factor with name = factorName.
 /// </summary>
 /// <param name="factorName"></param>
 /// <returns></returns>
 public static Factor GetByName(String factorName)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Factors.FirstOrDefault(f => f.Name.ToLower() == factorName.ToLower()));
     }
 }
        /// <summary>
        /// Creates an <see cref="IdeaContext"/> using an in-memory
        /// database and populates it with test data.
        /// </summary>
        /// <param name="numIdeas">The number of ideas you want to be created in the database</param>
        /// <returns>A test context backed by an in-memory database</returns>
        public static IdeaContext Create(int numIdeas)
        {
            // ================================================================
            // Use the in-memory database to make the tests lightning fast.
            // Create unique database names based on the test id
            // ================================================================
            var options = new DbContextOptionsBuilder <IdeaContext>()
                          .UseInMemoryDatabase(TestContext.CurrentContext.Test.ID)
                          .Options;

            // ================================================================
            // Seed the in-memory database with known data
            // ================================================================
            using (var context = new IdeaContext(options))
            {
                for (int i = 1; i <= numIdeas; i++)
                {
                    context.Add(new Idea
                    {
                        Name        = $"Idea name {i}",
                        Description = $"Description {i}",
                        Rating      = i % 3 + 1
                    });
                }
                context.SaveChanges();
            }

            // ================================================================
            // Use a clean copy of the context within the tests
            // ================================================================
            return(new IdeaContext(options));
        }
Exemple #14
0
        static void Main(string[] args)
        {
            //define the data class to use to initialize database through entity
            EntityMapHelper.SetEntityInitializer<IdeaContext>(new IdeaEntityInitializer());

            //define the data class to use to add custom sql commands at
            EntityMapHelper.SetDbInitializer<IdeaContext>(new IdeaDbInitializer());

            //define the pattern structure to initialize database
            EntityMapHelper.Initialize<IdeaContext>().With<DropCreateAlways<IdeaContext>>();

            //that's all, you can now use it and directly get the default data as in the exemple
            using (var context = new IdeaContext())
            {
                Console.WriteLine("default ideas : ");
                context.Ideas.ToList().ForEach(
                        idea => Console.WriteLine("- {0} ({1} comments)", idea.Title, idea.Comments.Count)
                    );
                Console.WriteLine("Press enter so print sql initialization script");
                Console.ReadLine();
                Console.Clear();

                string sql = context.GetSqlCreationScript();
                Console.WriteLine(sql);

                Console.WriteLine("Press enter so print generated Edmx script");
                Console.ReadLine();
                Console.Clear();

                string edmx = context.GetGeneratedEdmx();
                Console.WriteLine(edmx);
            }

            Console.Read();
        }
 public static List <Report> GetByNameAndType(string name, int type)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Reports.Where(r => r.Type == type && r.Name.ToLower() == name.ToLower()).ToList());
     }
 }
 /// <summary>
 /// Gets and  Returns the ModelFactorDatas by idModelFactor.
 /// </summary>
 /// <param name="idModelFactor"></param>
 /// <returns></returns>
 public static List <ModelFactorData> GetByModelFactor(int idModelFactor)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelFactorDatas.Where(mfd => mfd.IDModelFactor == idModelFactor).OrderBy(mfd => mfd.Date).ToList());
     }
 }
 /// <summary>
 ///  Returns the list of all Reports.
 /// </summary>
 /// <returns></returns>
 public static List <Report> GetAll()
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Reports.ToList());
     }
 }
 /// <summary>
 /// Returns the ModelFactorDatas by region.
 /// </summary>
 /// <param name="idRegion"></param>
 /// <returns></returns>
 public static List <ModelFactorData> GetByRegion(int idRegion)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelFactorDatas.Where(mfd => mfd.IDRegion == idRegion).ToList());
     }
 }
 /// <summary>
 /// Returns a Report by idReport.
 /// </summary>
 /// <param name="idReport"></param>
 /// <returns></returns>
 public static Report Get(int idReport)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Reports.FirstOrDefault(r => r.IDReport == idReport));
     }
 }
Exemple #20
0
 /// <summary>
 /// Returns all the PhaseBullets.
 /// </summary>
 /// <returns></returns>
 public static List <PhaseBullet> GetAll()
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return((from o in context.PhaseBullets select o).ToList());
     }
 }
 /// <summary>
 /// Returns the list of Reports by idModel.
 /// </summary>
 /// <param name="idModel"></param>
 /// <returns></returns>
 public static List <Report> GetByModel(int idModel)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Reports.Where(r => r.IDModel == idModel).ToList());
     }
 }
 /// <summary>
 /// Returns all Markers.
 /// </summary>
 /// <returns></returns>
 public static IQueryable <Marker> GetAll()
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Markers);
     }
 }
 /// <summary>
 /// Returns the list of ModelRiskAlert by idModelRiskAlert.
 /// </summary>
 /// <param name="idModelRiskAlert"></param>
 /// <returns></returns>
 public static List <ModelRiskAlertPhase> GetByModelRiskAlertID(int idModelRiskAlert)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelRiskAlertPhases.Where(mraph => mraph.IDModelRiskAlert == idModelRiskAlert).ToList());
     }
 }
 /// <summary>
 /// Returns the Marker by name.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static List <Marker> GetByName(string name)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Markers.Where(m => m.Name.ToLower().Equals(name.ToLower())).ToList());
     }
 }
 /// <summary>
 /// Returns the Model by name.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static List <Model> GetByName(string name)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Models.Where(m => m.Name == name).ToList());
     }
 }
 /// <summary>
 /// Returns the list of ModelRiskAlert by idModel.
 /// </summary>
 /// <param name="idModel"></param>
 /// <returns></returns>
 public static List <ModelRiskAlert> GetByModelID(int idModel)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelRiskAlerts.Where(mra => mra.IDModel == idModel).ToList());
     }
 }
 /// <summary>
 /// Returns the Model with IDModel = idModel
 /// </summary>
 /// <param name="idModel"></param>
 /// <returns></returns>
 public static Model Get(int idModel)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.Models.FirstOrDefault(m => m.IDModel == idModel));
     }
 }
 /// <summary>
 /// Returns all the ModelRiskAlert.
 /// </summary>
 /// <returns></returns>
 public static List <ModelRiskAlert> GetAll()
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelRiskAlerts.ToList());
     }
 }
 /// <summary>
 /// Gets and Returns the ModelFactorData with IDModelFactorData == idModelFactorData
 /// </summary>
 /// <param name="idModelFactorData"></param>
 /// <returns></returns>
 public static ModelFactorData GetById(int idModelFactorData)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelFactorDatas.FirstOrDefault(mfd => mfd.IDModelFactorData == idModelFactorData));
     }
 }
Exemple #30
0
 /// <summary>
 /// Returns the list of all the Roles.
 /// </summary>
 /// <returns></returns>
 public static List <Role> GetAll()
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return((from o in context.Roles select o).ToList());
     }
 }
Exemple #31
0
 public static List <ModelRiskAlertRegion> GetByRegion(Region region)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         return(context.ModelRiskAlertRegions.Where(mrar => mrar.IDRegion == region.IDRegion).ToList());
     }
 }