Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                //using (var ScenGenContext = new ScenarioGeneratorModel("test user"))
                using (var ScenGenContext = new ScenarioGeneratorModel("test user", DateTime.Parse("2015-Sep-25")))
                //using (var ScenGenContext = new ScenarioGeneratorModel("test user", @"data source=FMD-D8-3076\TRIDENTD01;initial catalog=ScenarioV6;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework", DateTime.Parse("2015-Aug-13")))
                //using (var ScenGenContext = new ScenarioGeneratorModel("test user", @"data source=FMD-D8-3076\TRIDENTD01;initial catalog=ScenarioV6;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"))
                {
                    //Database.SetInitializer<ScenarioGeneratorModel>(new ScenarioGeneratorInitializer());
                    ScenGenContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                    Console.WriteLine("*****Scenario Group Details List*****");

                    var groupDetails = ScenGenContext.ScenarioGroupDetails;
                    foreach (ScenarioGroupDetail detail in groupDetails)
                    {
                        Console.WriteLine("  ::: " + detail.Representation);
                    }

                    ScenarioRepository ScenRep = new ScenarioRepository(ScenGenContext);

                    var list = ScenGenContext.ScenarioGroups.Where(sg => sg.ScenarioGroupDetails.OrderBy(c => c.StartTime).FirstOrDefault().ScenarioGroupParentID == null);

                    Console.WriteLine("*****Scenario Group List*****");

                    foreach (ScenarioGroup group in list)
                    {

                        Console.Write("GROUP ID:" + group.ScenarioGroupID);

                        ScenarioGroupDetail detail = group.ScenarioGroupDetail;
                        Console.Write("  ::: " + detail.Name);
                        if (detail.ApprovedAt != null)
                        {
                            Console.WriteLine(" ::: Approved ");
                            //detail.Name = detail.Name + "  CHANGED!!! ";
                        }
                        else
                        {
                            Console.WriteLine(" ::: Unapproved ");
                            //detail.ApprovedAt = DateTime.UtcNow;
                            //detail.ApprovedBy = "approver";
                        }

                        Console.WriteLine(" --- Children --- ");
                        foreach (ScenarioGroupDetail detail2 in group.ScenarioGroupChildrenDetails)
                        {
                            Console.Write(detail2.ScenarioGroupID);
                            Console.Write(" +++ " + detail2.Name);

                            if (detail2.ApprovedAt != null)
                            {
                                Console.WriteLine(" +++ Approved ");
                                detail2.Name = detail.Name + "  CHANGED!!! ";
                            }
                            else
                            {
                                Console.WriteLine(" +++ Unapproved ");
                                //detail2.ApprovedAt = DateTime.UtcNow;
                                //detail2.ApprovedBy = "approver";
                            }

                        }

                    }

                    //ScenarioGroup newGroup = new ScenarioGroup();
                    //ScenGenContext.Set<ScenarioGroup>().Add(newGroup);
                    //ScenarioGroupDetail newGroupDetail = new ScenarioGroupDetail() { Name = "New Group 2"};
                    //newGroup.ScenarioGroupDetails.Add(newGroupDetail);

                    ScenarioRepository Rep = new ScenarioRepository(ScenGenContext);
                    if (!ScenGenContext.ReadOnlyView)
                        Rep.SaveChanges3();

                }

            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", validationErrors.Entry.Entity.GetType().Name, validationErrors.Entry.State);
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

            Console.ReadKey();
        }