Beispiel #1
0
        /// <summary>
        /// ادد و نمایش برنامه
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void Form1_Load(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext = new DataBaseContext();
                //Person person = new Person("mohammad", "saeid", "nazari");
                //dataBaseContext.People.Add(person);
                dataBaseContext.SaveChanges();

                dataBaseContext.People.Load();

                lstPeople.ValueMember   = "ID";
                lstPeople.DisplayMember = "DisplayFullName";
                lstPeople.DataSource    = dataBaseContext.People.Local;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
Beispiel #2
0
 protected override void DisposeCore()
 {
     if (dbContext != null)
     {
         dbContext.Dispose();
     }
 }
        private void Button_Add_Click(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext = new DataBaseContext();
                Country country = new Country()
                {
                    Name = "iran"
                };
                dataBaseContext.Countries.Add(country);
                dataBaseContext.SaveChanges();
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
Beispiel #4
0
        public async Task Execute(IJobExecutionContext context)
        {
            DataBaseContext BaseContext = new DataBaseContext();

            foreach (Purpose reminder in BaseContext._Purposes.Include("user"))
            {
                EventTime eventTime = BaseContext._EventTimes.Where(p => p.purpose == reminder).FirstOrDefault();
                if (eventTime != null)
                {
                    if (eventTime.dateTime != null)
                    {
                        if (eventTime.dateTime.Date == System.DateTime.Today &&
                            eventTime.dateTime.Hour == System.DateTime.Now.Hour &&
                            eventTime.dateTime.Minute == System.DateTime.Now.Minute)
                        {
                            if (reminder.user.SendMessageTelegram == true)
                            {
                                TelegramBotClient BotClient = new TelegramBotClient("779815529:AAEQVsHABl-V1rNhxX3vDnCo_r1xQjYczNU");

                                System.String name = "Название: " + reminder.Name + "\n";
                                name += "Описание: " + reminder.Note + "\n";
                                name += "Продолжительность: " + reminder.Duration;

                                await BotClient.SendTextMessageAsync(reminder.user.ID, name);
                            }
                        }
                    }
                }
            }
            BaseContext.Dispose();
        }
Beispiel #5
0
        private void btn4_Click(object sender, EventArgs e)
        {
            DataBaseContext oDataBaseContext = null;

            try
            {
                oDataBaseContext = new DataBaseContext();
                Country oCountry = new Country();

                string a = txt2.Text;
                oDataBaseContext.Countries.Where(c => c.Name == a).Load();
                oDataBaseContext.Countries.Local.Clear();

                oDataBaseContext.SaveChanges();
                Display();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (oDataBaseContext != null)
                {
                    oDataBaseContext.Dispose();
                    oDataBaseContext = null;
                }
                EmptyTXT();
            }
        }
Beispiel #6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext = new DataBaseContext();
                Person person = null;
                person = new Person()
                {
                    Name       = "ایران",
                    Population = "زیاد"
                };
                dataBaseContext.Persons.Add(person);
                person = new Person
                {
                    Name       = "جیبوتی",
                    Population = "کم"
                };
                dataBaseContext.Persons.Add(person);
                dataBaseContext.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
Beispiel #7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext = new DataBaseContext();
                Person person = new Person();
                person.GetFullName = new FullName("mohammad", "hajian");
                Address address = new Address("iran");
                address.City      = "esfahan";
                person.GetAddress = address;
                dataBaseContext.People.Add(person);
                dataBaseContext.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// در این کلاس چند یوزر به طول مشترک در یک گروه میروند
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnUsersToGroup_Click(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext = new DataBaseContext();
                ///نکته : برای یافتن یک داده از دیتابیس و بیرون اوردن آن لازم نیس آن را نیو کنیم
                ///ابتدا گروهی که یوزر ها میخاهند در ان بروند را بیرون میاوریم
                Group groupCommom = dataBaseContext.Groups.Where(c => c.Name == "group 2").FirstOrDefault();
                ///سپس یوزر هایی که در ان گروه میروند را بیرون میاوریم
                User user1 = dataBaseContext.Users.Where(c => c.Name == "user 2").FirstOrDefault();
                User user2 = dataBaseContext.Users.Where(c => c.Name == "user 4").FirstOrDefault();
                User user3 = dataBaseContext.Users.Where(c => c.Name == "user 6").FirstOrDefault();
                ///سپس نام آن گروهی که گروهه بیرون آمده در ان است را به پراپرتی یوزر ان اضافه میکنیم
                groupCommom.Users.Add(user1);
                groupCommom.Users.Add(user2);
                groupCommom.Users.Add(user3);
                ///سیو دیتابیس
                dataBaseContext.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
        public async Task GetByIdAsyncWithEventsShouldReturnTheCurrentStateOfTheAggregate()
        {
            //Arrange

            #region mock of DataBaseContext , mock of IDomainEventRebuilder and mock of moqInvoker

            var aggregateId    = Guid.NewGuid();
            var optionsBuilder = new DbContextOptionsBuilder <DataBaseContext>();
            optionsBuilder.UseInMemoryDatabase("FakeInMemoryData");
            var moqContext = new DataBaseContext(optionsBuilder.Options);
            moqContext.Database.EnsureCreated();

            var obj  = new EventOject(aggregateId, "Dupont", "45 av charles degaulle paris, france");
            var type = obj.GetType().AssemblyQualifiedName;
            var json = @"
                {
                    'FullName':'Dupont',
                    'Adresse':'45 av charles degaulle paris, france'
                }";

            moqContext.EventStore.Add(new EventStore(aggregateId,
                                                     1,
                                                     "2@735f8407-16be-44b5-be96-2bab582b5298",
                                                     type,
                                                     DateTime.Now, json));
            moqContext.SaveChanges();

            Mock <IDomainEventRebuilder> moqDomainEventRebuilder = new Mock <IDomainEventRebuilder>();
            moqDomainEventRebuilder.Setup(m => m.RebuildDomainEvents(It.IsAny <IEnumerable <EventStore> >()))
            .Returns(new List <Event>
            {
                obj
            });

            var aggregate = (StubAggregate)typeof(StubAggregate)
                            .GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic,
                                            null,
                                            new Type[0],
                                            new ParameterModifier[0])
                            ?.Invoke(new object[0]);

            var moqInvoker = new Mock <IInvoker <StubAggregate> >();
            moqInvoker.Setup(i => i.CreateInstanceOfAggregateRoot <StubAggregate>()).Returns(aggregate);

            #endregion mock of DataBaseContext , mock of IDomainEventRebuilder and mock of moqInvoker

            var sut = new EventStoreRepository <StubAggregate>(moqContext, moqInvoker.Object, moqDomainEventRebuilder.Object);

            //Act
            var result = await sut.GetByIdAsync <StubAggregate>(aggregateId);

            moqContext.Dispose();

            //Assert
            Assert.NotNull(aggregate);
            Assert.Equal(aggregate, result);
            Assert.Equal(aggregateId, aggregate.Id);
            Assert.Equal(obj.FullName, aggregate.FullName);
            Assert.Equal(obj.Adresse, aggregate.Adresse);
        }
Beispiel #10
0
        /// <summary>
        /// همانند بالا
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnGroupsToUser_Click(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext = new DataBaseContext();

                User userActive = dataBaseContext.Users.Where(c => c.Name == "user 1").FirstOrDefault();

                Group group1 = dataBaseContext.Groups.Where(c => c.Name == "group 1").FirstOrDefault();
                Group group2 = dataBaseContext.Groups.Where(c => c.Name == "group 2").FirstOrDefault();
                Group group3 = dataBaseContext.Groups.Where(c => c.Name == "group 3").FirstOrDefault();

                userActive.Groups.Add(group1);
                userActive.Groups.Add(group2);
                userActive.Groups.Add(group3);

                dataBaseContext.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
Beispiel #11
0
        public async Task Execute(IJobExecutionContext context)
        {
            DataBaseContext BaseContext = new DataBaseContext();

            foreach (Event reminder in BaseContext._Events.Include("user"))
            {
                EventTime eventTime = BaseContext._EventTimes.Where(p => p._event == reminder).FirstOrDefault();
                if (eventTime != null)
                {
                    if (eventTime.dateTime != null)
                    {
                        if (eventTime.dateTime.Date == System.DateTime.Today &&
                            eventTime.dateTime.Hour == System.DateTime.Now.Hour &&
                            eventTime.dateTime.Minute == System.DateTime.Now.Minute)
                        {
                            if (reminder.user.SendMessageE_Mail == true && reminder.user.EmailAdress != null)
                            {
                                // отправитель - устанавливаем адрес и отображаемое в письме имя
                                MailAddress from = new MailAddress("*****@*****.**", "CalendarBot");
                                // кому отправляем
                                MailAddress to = new MailAddress(reminder.user.EmailAdress);
                                // создаем объект сообщения
                                MailMessage m = new MailMessage(from, to);
                                // тема письма
                                m.Subject = "Мероприятие";
                                // текст письма
                                System.String busy = "";
                                if (reminder.Busy == true)
                                {
                                    busy = "Занят";
                                }
                                else
                                {
                                    busy = "Не занят";
                                }
                                m.Body  = "<h2>" + "Название: " + reminder.Name + "<br>";
                                m.Body += "Описание: " + reminder.Note + "<br>";
                                m.Body += "Локация: " + reminder.Location + "<br>";
                                m.Body += "Занятость: " + busy + "<br>";
                                m.Body += "</h2>";
                                // письмо представляет код html
                                m.IsBodyHtml = true;

                                //m.Attachments.Add(@"Путь к файлу!");

                                // адрес smtp-сервера и порт, с которого будем отправлять письмо
                                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                                // логин и пароль
                                smtp.Credentials = new NetworkCredential("*****@*****.**", "123456qweASD123456");
                                smtp.EnableSsl   = true;
                                await smtp.SendMailAsync(m);

                                System.Console.WriteLine("Сообщение отправлено!");
                            }
                        }
                    }
                }
            }
            BaseContext.Dispose();
        }
Beispiel #12
0
        public void MonthlyFinancialList()
        {
            Models.DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext =
                    new DataBaseContext();

                List <MonthlyFinancial> monthlyFinancials =
                    dataBaseContext.MonthlyFinancials
                    .OrderBy(current => current.Register_Date)
                    .ToList();

                monthlyFinancialListDataGridView.DataSource = monthlyFinancials;
            }
            catch (System.Exception ex)
            {
                Infrastructure.Utility.ExceptionShow(ex);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
        private void button_Add_Groups_Click(object sender, EventArgs e)
        {
            databasecontext = new DataBaseContext();

            try
            {
                var Group1 = databasecontext.Groups.Where(c => c.Name == "Group1").FirstOrDefault();
                var Group2 = databasecontext.Groups.Where(c => c.Name == "Group2").FirstOrDefault();
                var User1  = databasecontext.Users.Where(c => c.Name == "User1").FirstOrDefault();

                User1.Groups = new List <Group>();

                User1.Groups.Add(Group1);
                User1.Groups.Add(Group2);

                //databasecontext.Users.Add(User1);      اگر اینکار رو بکنیم یه یوزر دیگه ساخته میشه
                databasecontext.SaveChanges();
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
            finally
            {
                if (databasecontext != null)
                {
                    databasecontext.Dispose();
                    databasecontext = null;
                }
            }
        }
Beispiel #14
0
 public void Dispose()
 {
     if (_context != null)
     {
         _context.Dispose();
     }
 }
Beispiel #15
0
 public void Dispose()
 {
     if (_Context != null)
     {
         _Context.Dispose();
     }
     GC.SuppressFinalize(this);
 }
Beispiel #16
0
        /// <summary>
        /// Executa a confirmação de mudancas.
        /// </summary>
        public void CommitChanges()
        {
            // Realizando o commit da transação
            if (StaticDataContext == null)
            {
                return;
            }

            if (StaticDataContext.Database.CurrentTransaction != null)
            {
                StaticDataContext.Database.CurrentTransaction.Commit();
            }

            StaticDataContext.PerformingTransaction = false;
            StaticDataContext.Dispose();
            StaticDataContext = null;
        }
 private void Casting_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (databasecontext != null)
     {
         databasecontext.Dispose();
         databasecontext = null;
     }
 }
Beispiel #18
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (GetDataBaseContext != null)
     {
         GetDataBaseContext.Dispose();
         GetDataBaseContext = null;
     }
 }
Beispiel #19
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Beispiel #20
0
 public virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         db.Dispose();
     }
     disposed = true;
 }
Beispiel #21
0
        /// <summary>
        /// توضیحات با دقت خوانده شود
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnDoSomthing_Click(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                ///ابتدا یک دیتابیس کانتکس نیو میکنیم
                dataBaseContext = new DataBaseContext();
                ///سپس یک کانتری میسازیم و کشوری که ایدی اش یک باشد را تویش میریزیم
                Country country = dataBaseContext.Countries.Where(c => c.ID == 1).FirstOrDefault();
                ///اگر همچین کانتری وجود نداشت از برنامه خارج میشود
                if (country == null)
                {
                    return;
                }
                State state = null;

                ///شهر اصفهان را به کشوری که جست و جو شده نسبت میدهد
                ///ایدی کشوری که جست و  جو شده را به ایدی شهر اصفهان میدهد
                state = new State
                {
                    Name      = "اصفهان",
                    CountryId = country.ID
                };
                dataBaseContext.States.Add(state);

                ///کل کشوری که جست و جو شده را به قسمت کشوره استان اضافه میکند
                state = new State
                {
                    Name    = "تهران",
                    Country = country
                };
                dataBaseContext.States.Add(state);

                ///در کلاس کانتری یک لیست استان داشتیم
                ///در ان لیست این شهر شیراز را ادد میکند
                state = new State
                {
                    Name = "شیراز"
                };
                country.States.Add(state);

                ///در اخر سیو میکنیم
                dataBaseContext.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
Beispiel #22
0
        public void Dispose()
        {
            if (_dataBaseContext != null)
            {
                _dataBaseContext.Rollback();
            }

            _dataBaseContext.Dispose();
        }
Beispiel #23
0
        private void BtnAddNewPeople_Click(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext = new DataBaseContext();
                Person person = null;
                ///ابتدا یک شخص را میسازیم و نامش را میگذاریم
                person = new Person
                {
                    FullName = "Mahdi Hajian"
                };
                ///سپس ان را ادد میکنیم
                dataBaseContext.Persons.Add(person);

                ///این دفعه شخص دیگری را میسازیم ولی ادرس هم بهش میدهیم
                person = new Person
                {
                    FullName = "ali ramazani"
                };
                Addess addess = null;
                addess = new Addess
                {
                    City    = "shiraz",
                    State   = "fars",
                    Country = "iran"
                };
                person.Addess = addess;
                dataBaseContext.Persons.Add(person);

                ///
                /// مثال پایین اشتباه است
                /// نمیشود مستقیم به ادرس اضافه کرد
                ///
                //person = new Person();
                //person.FullName = "saeid nazari";
                //person.Addess.City = "اصفهان";
                //person.Addess.State = "استان اصفهان";
                //person.Addess.Country = "ایران";
                //dataBaseContext.Persons.Add(person);

                dataBaseContext.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
Beispiel #24
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             entities.Dispose();
         }
     }
     this.disposed = true;
 }
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_dbContext != null)
         {
             _dbContext.Dispose();
             _dbContext = null;
         }
     }
 }
Beispiel #26
0
 private void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             _dataBaseContext.Dispose();
         }
     }
     _disposed = true;
 }
Beispiel #27
0
 public virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             Db.Dispose();
         }
     }
     _disposed = true;
 }
Beispiel #28
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             _context.Dispose();
         }
     }
     _disposed = true;
 }
Beispiel #29
0
 public virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             db.Dispose();
         }
         this.disposed = true;
     }
 }
        private void Button_Do_Click(object sender, EventArgs e)
        {
            DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext = new DataBaseContext();
                var country = dataBaseContext.Countries.FirstOrDefault(c => c.ID == 1);
                if (country == null)
                {
                    return;
                }
                State state = null;

                state          = new State();
                state.Name     = "isfahan";
                country.States = new List <State>
                {
                    state
                };
                //dataBaseContext.Countries.Add(country);     اگر اینکار رو بکنیم یه کانتری دیگه ساخته میشه

                state = new State
                {
                    Name      = "shiraz",
                    CountryID = country.ID
                };
                dataBaseContext.States.Add(state);


                state = new State
                {
                    Name    = "tehran",
                    Country = country
                };
                dataBaseContext.States.Add(state);


                dataBaseContext.SaveChanges();
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }