Пример #1
0
        private void AddFakeOrders()
        {
            //GetFakeOrder
            _Test test = new _Test();

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    //над присоеденить к контексту
                    int       orderNumer = 26500;
                    DateTime  date       = new DateTime(2014, 2, 01);
                    OrderLine Order      = new OrderLine();
                    for (int i = orderNumer; i < orderNumer + 30000; i++)
                    {
                        Order.OrderNumber = i;

                        Order.Direction    = db.Directions.Find(test.rnd.Next(1, 12));
                        Order.WorkType     = db.WorkTypes.Find(test.rnd.Next(1, 13));
                        Order.Subject      = db.Subjects.Find(test.rnd.Next(1, 9));
                        Order.Source       = db.Sources.Find(test.rnd.Next(1, 6));
                        Order.Status       = db.Statuses.Find(test.rnd.Next(1, 10));
                        Order.WorkInCredit = test.RandomBool();
                        Order.Dates        = new Dates()
                        {
                            DateOfReception = date, DeadLine = date.AddDays(test.rnd.Next(1, 30))
                        };
                        Order.Money = new Money()
                        {
                            Price = test.rnd.Next(500, 1001), Prepayment = 500
                        };
                        Order.SaveToBase      = test.RandomBool();
                        Order.Saved           = true;
                        Order.WorkDescription = test.RandWorkDescription();
                        //Order.Author =
                        Persone Persone = new Persone();
                        Persone.PriceRating = test.rnd.Next(0, 10);
                        Persone.Male        = test.RandomBool();
                        Persone.Female      = !Persone.Male;
                        Persone.Name        = test.RandName(Persone.Male);
                        Persone.Surname     = test.RandSurName(Persone.Male);
                        Persone.Patronimic  = test.RandPatronimic(Persone.Male);
                        Persone.Contacts    = new Contacts()
                        {
                            Phone1 = test.RandPhone(), Phone2 = test.RandPhone()
                        };
                        Persone.PersoneDescription = new PersoneDescription()
                        {
                            Description = test.RandDescription()
                        };

                        Order.Client = new Client()
                        {
                            Persone = Persone, Course = test.rnd.Next(1, 4)
                        };
                        Order.Client.Universities.Add(db.Universities.Find(test.rnd.Next(1, 7)));
                        Order.User = db.Users.Find(test.rnd.Next(0, 2));

                        //нижние две строки кода - признак того, что что-то пошло не тиак, но вроде работает....
                        db.Configuration.AutoDetectChangesEnabled = false;
                        db.Configuration.ValidateOnSaveEnabled    = false;
                        db.Orderlines.Add(Order);

                        db.SaveChanges();

                        db.Entry(Order).State = EntityState.Modified;
                        Order.ParentId        = Order.OrderLineId;

                        db.SaveChanges();

                        db.Entry(Order).State = EntityState.Detached;
                        if (i % test.rnd.Next(1, 11) == 0)
                        {
                            date = date.AddDays(1);
                            if (date.Year == DateTime.Now.Year && date.Month == DateTime.Now.Month && date.Day > DateTime.Now.Day)
                            {
                                break;
                            }
                        }
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Пример #2
0
        private void AddFakeAuthors()
        {
            //GetFakeOrder
            _Test test = new _Test();

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    DateTime  date  = new DateTime(2021, 2, 01);
                    OrderLine Order = new OrderLine();
                    for (int i = 0; i < 50; i++)
                    {
                        Author  author  = new Author();
                        Persone persone = new Persone();
                        author.Direction.Add(db.Directions.Find(test.rnd.Next(1, 12)));
                        author.Subject.Add(db.Subjects.Find(test.rnd.Next(1, 9)));
                        persone.Male       = test.RandomBool();
                        persone.Female     = !persone.Male;
                        persone.Name       = test.RandName(persone.Male);
                        persone.Surname    = test.RandSurName(persone.Male);
                        persone.Patronimic = test.RandPatronimic(persone.Male);
                        persone.Contacts   = new Contacts()
                        {
                            Phone1 = test.RandPhone(), Phone2 = test.RandPhone()
                        };
                        persone.PersoneDescription = new PersoneDescription()
                        {
                            Description = test.RandDescription()
                        };
                        persone.Dates.Add(new Dates()
                        {
                            DayBirth = new DateTime(test.rnd.Next(1955, 2001),
                                                    test.rnd.Next(1, 12), test.rnd.Next(1, 28)),
                            StartDateWork = new DateTime(test.rnd.Next(2008, 2021),
                                                         test.rnd.Next(1, 12), test.rnd.Next(1, 28))
                        }
                                          );

                        //persone.PersoneDescription = new PersoneDescription() { BlackList=};
                        author.Rating       = test.rnd.Next(0, 10);
                        persone.NickName    = persone.Name + "_" + author.Direction[0].DirectionName;
                        author.Persone      = persone;
                        author.AuthorStatus = db.AuthorStatuses.Find(test.rnd.Next(1, 6));



                        db.Authors.Add(author);

                        db.SaveChanges();
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }