Example #1
0
        private void deleteUsersButton_Click(object sender, System.EventArgs e)
        {
            if (usersListBox.SelectedItems.Count == 0)
            {
                System.Windows.Forms.MessageBox.Show("You did not select any users for deleting!");

                return;
            }

            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                foreach (var selectedItem in usersListBox.SelectedItems)
                {
                    Models.User selectedUser = selectedItem as Models.User;

                    if (selectedUser != null)
                    {
                        if (selectedUser.IsAdmin == false)
                        {
                            databaseContext.Entry(selectedUser).State = System.Data.Entity.EntityState.Deleted;

                            // Note: Does Not Work!
                            //databaseContext.Users.Remove(selectedUser);

                            databaseContext.SaveChanges();
                        }
                    }
                }

                Search();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
Example #2
0
        public async Task <ActionResult> Put(int id, Models.DTO.LabelDTO label)
        {
            if (id != label.Id)
            {
                return(BadRequest($"Query param id {id} must match body data id {label.Id}"));
            }

            if (!_dbContext.Labels
                .Any(l => l.LabelId == id))
            {
                return(NotFound());
            }

            _dbContext.Entry(new Models.Label(label)).State = EntityState.Modified;

            await _dbContext.SaveChangesAsync();

            return(NoContent());
        }
Example #3
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fullnameTextBox.Text) || string.IsNullOrWhiteSpace(descriptionTextBox.Text))
            {
            }
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext = new Models.DatabaseContext();

                Models.User user = databaseContext.Users
                                   .Find(Infrastructure.Utility.AuthenticatedUser.Id);
                if (user == null)
                {
                    System.Windows.Forms.MessageBox.Show("خطایی رخ داده است با مدیر سیستم تماس بگیرید");
                }
                else
                {
                    user.FullName    = fullnameTextBox.Text;
                    user.Description = descriptionTextBox.Text;
                    databaseContext.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    databaseContext.SaveChanges();

                    Infrastructure.Utility.AuthenticatedUser = user;
                    ResetForm();
                    System.Windows.Forms.MessageBox.Show("اطلاعات با موفقیت ویرایش شد ");
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("خطایی رخ داده است با مدیر سیستم تماس بگیرید"
                                                     + Environment.NewLine + ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                }
            }
        }
Example #4
0
        private void btnCheckStates_Click(object sender, System.EventArgs e)
        {
            //#################################################

            //ایجاد یک شی از کلاس دیتا بیس کانتکست
            Models.DatabaseContext oDatabaseContext =
                new Models.DatabaseContext();

            //#################################################

            //#################################################

            //چینش سورت شده بر اساس نام
            oDatabaseContext.Countries
            .OrderBy(current => current.Name)
            .Load();

            //#################################################

            //#################################################

            //جنس لوکال برای ایجاد یک متغیر از آن جنس
            //ایجاد یک شی از لوکال و برای ایجاد نمودن آن باید بدانیم لوکال از چه جنسی است
            //با نگه داشتن موس روی لوکال جنس آن مشخص میشود
            //System.Collections.ObjectModel.ObservableCollection<Models.Country> oLocalCountries =
            //	oDatabaseContext.Countries.Local;

            //#################################################

            //#################################################

            // اگر جنس لوکال را نخواهیم اعمال کنیم(معمول نیست)داخل متغیری از جنس ور قرار میدهیم

            var varLocalCountries =
                oDatabaseContext.Countries.Local;

            //#################################################

            //#################################################

            //تعداد کشور ها را نمایش میدهیم
            System.Windows.Forms.MessageBox
            .Show("(0) Count: " + varLocalCountries.Count);

            //#################################################

            //استیت یک انتیتی یکی از 5 حالت ذیل است
            //ادد - مودیفاید -دلیتد - آن چنجد -دیتچد

            // Delete
            //#################################################

            //از کلاس کانتری یک شی میسازیم و برابر با اولین خانه متغیر ایجاد شده از جنس لوکال قرار میدهیم
            Models.Country oDeletedCountry = varLocalCountries[0];

            //استیت متغیر را بررسی میکنیم-آنچنجد
            System.Windows.Forms.MessageBox.Show
                ("(1) " + oDatabaseContext.Entry(oDeletedCountry).State.ToString());

            //اولین خانه را حذف میکنیم
            varLocalCountries.RemoveAt(0);

            //-استیت متغیر را بررسی میکنیم-دلیتد
            System.Windows.Forms.MessageBox.Show
                ("(2) " + oDatabaseContext.Entry(oDeletedCountry).State.ToString());

            //#################################################

            //#################################################

            //تعداد کشور ها را نمایش میدهیم
            System.Windows.Forms.MessageBox
            .Show("3) Count: " + varLocalCountries.Count);

            //#################################################

            // Add New
            //#################################################

            //یک شی از کانتری رو هوا ایجاد میکنیم یعنی به کالکشن اد نمیکنیم
            Models.Country oNewCountry =
                new Models.Country();

            oNewCountry.Name = "Some Added Country";

            //استیت را بررسی میکنیم - دیتچد
            System.Windows.Forms.MessageBox.Show
                ("(4) " + oDatabaseContext.Entry(oNewCountry).State.ToString());

            //افزودن به کالکشن
            varLocalCountries.Add(oNewCountry);

            //بررسی استیت-ادد
            System.Windows.Forms.MessageBox.Show
                ("(5) " + oDatabaseContext.Entry(oNewCountry).State.ToString());

            //#################################################

            // Edit
            //#################################################

            //ایجاد یک متغیر که خانه صفر متغیر هست
            Models.Country oEditedCountry = varLocalCountries[0];

            //بررسی استیت-آنچنجد
            System.Windows.Forms.MessageBox.Show
                ("(7) " + oDatabaseContext.Entry(oEditedCountry).State.ToString());

            //نام کشور را میخوانیم و در یم متغیر قرار میدهیم و دوباره آن را در نام خودش قرار میدهیم
            string strCurrentValue = oEditedCountry.Name;

            oEditedCountry.Name = strCurrentValue;

            //بررسی استیت - آنچنجد-هوشمندی انتیتی فریم ورک
            System.Windows.Forms.MessageBox.Show
                ("(8) " + oDatabaseContext.Entry(oEditedCountry).State.ToString());

            //ولی اگر نام را عوض کنیم
            oEditedCountry.Name = "Edited Country";

            //بررسی استیت - مادیفاید
            System.Windows.Forms.MessageBox.Show
                ("(9) " + oDatabaseContext.Entry(oEditedCountry).State.ToString());

            //دوباره اگر نام اول را بهش بدیم
            oEditedCountry.Name = strCurrentValue;

            //بررسی استیت - مادیفاید
            System.Windows.Forms.MessageBox.Show
                ("(10) " + oDatabaseContext.Entry(oEditedCountry).State.ToString());

            //#################################################

            //#################################################

            //for (int intIndex = 0; intIndex <= varLocalCountries.Count - 1; intIndex++)
            //{
            //    System.Windows.Forms.MessageBox.Show(intIndex.ToString() + ") - " +
            //        oDatabaseContext.Entry(varLocalCountries[intIndex]).State.ToString());
            //}

            //#################################################
        }
Example #5
0
		private void AddNewCountryButton_Click(object sender, System.EventArgs e)
		{
			Models.DatabaseContext databaseContext = null;

			try
			{
				databaseContext =
					new Models.DatabaseContext();

				// **************************************************
				// Create:
				// **************************************************

				// Solution (1)
				//Models.Country country = new Models.Country();

				//country.Name = "New Country";

				//databaseContext.Countries.Add(country);
				// /Solution (1)

				// Solution (2)
				Models.Country country = new Models.Country();

				country.Name = "New Country";

				databaseContext.Entry(country).State =
					System.Data.Entity.EntityState.Added;
				// /Solution (2)

				databaseContext.SaveChanges();

				System.Guid id = System.Guid.NewGuid();

				// **************************************************
				// Modify:
				// **************************************************

				// Solution (1)
				//Models.Country theCountry =
				//	databaseContext.Countries
				//	.Where(current => current.Id == sId)
				//	.FirstOrDefault();

				//theCountry.Name = "Something Else...";
				// /Solution (1)

				// Solution (2)
				Models.Country theCountry = new Models.Country();

				theCountry.Id = id; // مهم
				theCountry.Name = "Something Else...";

				databaseContext.Entry(theCountry).State =
					System.Data.Entity.EntityState.Modified;
				// /Solution (2)

				// **************************************************
				// Modify: (Just Some Fields Value)
				// **************************************************

				// خیلی جالبه
				databaseContext.Entry(theCountry).Property(current => current.Name).IsModified = true;

				// **************************************************
				// Delete:
				// **************************************************

				// Solution (1)
				//Models.Country theCountry =
				//	databaseContext.Countries
				//	.Where(current => current.Id == sId)
				//	.FirstOrDefault();

				//databaseContext.Countries.Remove(theCountry);
				// /Solution (1)

				// Solution (2)
				Models.Country myCountry = new Models.Country();

				theCountry.Id = id; // مهم

				databaseContext.Entry(theCountry).State =
					System.Data.Entity.EntityState.Deleted;
				// /Solution (2)
			}
			catch (System.Exception ex)
			{
				System.Windows.Forms.MessageBox.Show(ex.Message);
			}
			finally
			{
				if (databaseContext != null)
				{
					databaseContext.Dispose();
					//databaseContext = null;
				}
			}
		}
Example #6
0
		private void CheckStatesButton_Click(object sender, System.EventArgs e)
		{
			Models.DatabaseContext databaseContext = new Models.DatabaseContext();

			// **************************************************
			databaseContext.Countries
				.OrderBy(current => current.Code)
				.Load();
			// **************************************************

			// **************************************************
			//System.Collections.ObjectModel.ObservableCollection<Models.Country>
			//	localCountries = databaseContext.Countries.Local;
			// **************************************************

			// **************************************************
			var localCountries =
				databaseContext.Countries.Local;
			// **************************************************

			// **************************************************
			System.Windows.Forms.MessageBox
				.Show("(1) Count: " + localCountries.Count);
			// **************************************************

			// Delete
			// **************************************************
			Models.Country deletedCountry = localCountries[0];

			System.Windows.Forms.MessageBox.Show
				("(2) " + databaseContext.Entry(deletedCountry).State.ToString());

			localCountries.RemoveAt(0);

			System.Windows.Forms.MessageBox.Show
				("(3) " + databaseContext.Entry(deletedCountry).State.ToString());
			// **************************************************

			// **************************************************
			System.Windows.Forms.MessageBox
				.Show("(4) Count: " + localCountries.Count);
			// **************************************************

			// Add New
			// **************************************************
			Models.Country newCountry = new Models.Country();

			newCountry.Name = "Some Added Country";

			System.Windows.Forms.MessageBox.Show
				("(5) " + databaseContext.Entry(newCountry).State.ToString());

			localCountries.Add(newCountry);

			System.Windows.Forms.MessageBox.Show
				("(6) " + databaseContext.Entry(newCountry).State.ToString());
			// **************************************************

			// Edit
			// **************************************************
			Models.Country editedCountry = localCountries[0];

			System.Windows.Forms.MessageBox.Show
				("(7) " + databaseContext.Entry(editedCountry).State.ToString());

			string currentValue = editedCountry.Name;
			editedCountry.Name = currentValue;

			System.Windows.Forms.MessageBox.Show
				("(8) " + databaseContext.Entry(editedCountry).State.ToString());

			editedCountry.Name = "Edited Country";

			System.Windows.Forms.MessageBox.Show
				("(9) " + databaseContext.Entry(editedCountry).State.ToString());

			editedCountry.Name = currentValue;

			System.Windows.Forms.MessageBox.Show
				("(10) " + databaseContext.Entry(editedCountry).State.ToString());
			// **************************************************

			// **************************************************
			//for (int index = 0; index <= localCountries.Count - 1; index++)
			//{
			//	System.Windows.Forms.MessageBox.Show(index.ToString() + ") - " +
			//		databaseContext.Entry(localCountries[index]).State.ToString());
			//}
			// **************************************************

			// یک رکوردی را که از بانک اطلاعاتی دریافت کرده‌ایم را
			// چند بار یک یا چند فیلد آنرا تغییر داده
			// و پس از آن آنرا از مجموعه حذف می‌کنیم
			// وضعیت آن رکورد چه خواهد بود؟

			// یک رکورد ایجاد می‌کنیم
			// و به مجموعه اضافه می‌کنیم
			// تعدادی از پراپرتی‌های آنرا تغییر می‌دهیم 
			// مجددا با دستور
			// Remove یا RemoveAt
			// همان رکورد را حذف می‌کنیم
			// وضعیت آن رکورد چه خواهد بود؟

			Models.Country theNewCountry = new Models.Country();

			databaseContext.Countries.Add(theNewCountry);

			databaseContext.Countries.Remove(theNewCountry);

			// theNewCountry.State ?
		}
Example #7
0
        private void changePasswordButton_Click(object sender, System.EventArgs e)
        {
            string errorMessage = string.Empty;

            if (string.IsNullOrWhiteSpace(oldpasswordTextBox.Text) ||
                string.IsNullOrWhiteSpace(newpasswordTextBox.Text) ||
                string.IsNullOrWhiteSpace(confirmPasswordTextBox.Text))
            {
                errorMessage = "فیلدهای الزامی را پر کنید ";
            }

            else
            {
                if (confirmPasswordTextBox.Text.Length < 8)
                {
                    if (errorMessage != string.Empty)
                    {
                        errorMessage += System.Environment.NewLine;
                    }

                    errorMessage +=
                        "طول رمز عبور جدید حداقل8 کاراکتر می باشد.";
                }

                if (string.Compare(confirmPasswordTextBox.Text, newpasswordTextBox.Text, ignoreCase: false) != 0)
                {
                    if (errorMessage != string.Empty)
                    {
                        errorMessage += System.Environment.NewLine;
                    }

                    errorMessage +=
                        "رمز عبور جدید و تکرار رمز برابر نیست ";
                }
            }

            if (errorMessage != string.Empty)
            {
                System.Windows.Forms.MessageBox.Show(errorMessage);

                oldpasswordTextBox.Focus();

                return;
            }
            else
            {
                Models.DatabaseContext databaseContext = null;
                try
                {
                    Models.User user = databaseContext.Users
                                       .Find(Infrastructure.Utility.AuthenticatedUser.Id);
                    if (user != null)
                    {
                        user.Password = newpasswordTextBox.Text;
                        databaseContext.Entry(user).State = System.Data.Entity.EntityState.Modified;
                        databaseContext.SaveChanges();
                        System.Windows.Forms.MessageBox.Show("رمز عبور با موفقیت تغییر کرد ");
                    }
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("خطایی رخ داده است با مدیر سیستم تماس بگیرید"
                                                         + System.Environment.NewLine + ex.Message);
                }
                finally
                {
                    if (databaseContext != null)
                    {
                        databaseContext.Dispose();
                    }
                }
                return;
            }
        }
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // **************************************************
            // DatabaseContext - Add New User
            // **************************************************
            {
                Models.DatabaseContext databaseContext = null;

                try
                {
                    databaseContext =
                        new Models.DatabaseContext();

                    Models.User user = new Models.User
                    {
                        IsActive = true,
                        Username = "******",
                    };

                    databaseContext.Users.Add(user);

                    databaseContext.SaveChanges();
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (databaseContext != null)
                    {
                        databaseContext.Dispose();
                        databaseContext = null;
                    }
                }
            }
            // **************************************************
            // /DatabaseContext - Add New User
            // **************************************************

            // **************************************************
            // UnitOfWork - Add New User
            // **************************************************
            {
                Dal.UnitOfWork unitOfWork = null;

                try
                {
                    unitOfWork =
                        new Dal.UnitOfWork();

                    Models.User user = new Models.User
                    {
                        IsActive = true,
                        Username = "******",
                    };

                    unitOfWork.UserRepository.Insert(user);

                    unitOfWork.Save();
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (unitOfWork != null)
                    {
                        unitOfWork.Dispose();
                        unitOfWork = null;
                    }
                }
            }
            // **************************************************
            // /UnitOfWork - Add New User
            // **************************************************

            System.Guid id =
                new System.Guid
                    ("a1a57f49-51fc-4c4b-8f06-19cd117d5c9e");

            string username = "******";

            // **************************************************
            // DatabaseContext - Get The User From Database -> Update The User -> Save The User Changes To Database
            // **************************************************
            {
                Models.DatabaseContext databaseContext = null;

                try
                {
                    databaseContext =
                        new Models.DatabaseContext();

                    //Models.User user =
                    //	databaseContext.Users
                    //	.Where(current => current.Id == id)
                    //	.FirstOrDefault();

                    Models.User user =
                        databaseContext.Users
                        .Where(current => string.Compare(current.Username, username, true) == 0)
                        .FirstOrDefault();

                    if (user != null)
                    {
                        user.IsActive = false;
                        user.Username = "******";

                        databaseContext.SaveChanges();
                    }
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (databaseContext != null)
                    {
                        databaseContext.Dispose();
                        databaseContext = null;
                    }
                }
            }
            // **************************************************
            // /DatabaseContext - Get The User From Database -> Update The User -> Save The User Changes To Database
            // **************************************************

            // **************************************************
            // UnitOfWork - Get The User From Database -> Update The User -> Save The User Changes To Database
            // **************************************************
            {
                Dal.UnitOfWork unitOfWork = null;

                try
                {
                    unitOfWork =
                        new Dal.UnitOfWork();

                    //Models.User user =
                    //	unitOfWork.UserRepository.GetById(id);

                    Models.User user =
                        unitOfWork.UserRepository.GetByUsername(username);

                    if (user != null)
                    {
                        user.IsActive = false;
                        user.Username = "******";

                        // نوشتن دستور ذیل الزامی نیست! ولی اگر بنویسیم مشکلی ندارد
                        //unitOfWork.UserRepository.Update(user);

                        unitOfWork.Save();
                    }
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (unitOfWork != null)
                    {
                        unitOfWork.Dispose();
                        unitOfWork = null;
                    }
                }
            }
            // **************************************************
            // /UnitOfWork - Get The User From Database -> Update The User -> Save The User Changes To Database
            // **************************************************

            // **************************************************
            // DatabaseContext - Just Update The User with Id -> Save The User Changes To Database
            // **************************************************
            {
                Models.DatabaseContext databaseContext = null;

                try
                {
                    databaseContext =
                        new Models.DatabaseContext();

                    Models.User user = new Models.User();

                    user.Id       = id;
                    user.IsActive = false;
                    user.Username = "******";

                    databaseContext.Entry(user).State =
                        System.Data.Entity.EntityState.Modified;

                    databaseContext.SaveChanges();
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (databaseContext != null)
                    {
                        databaseContext.Dispose();
                        databaseContext = null;
                    }
                }
            }
            // **************************************************
            // /DatabaseContext - Just Update The User with Id -> Save The User Changes To Database
            // **************************************************

            // **************************************************
            // UnitOfWork - Just Update The User with Id -> Save The User Changes To Database
            // **************************************************
            {
                Dal.UnitOfWork unitOfWork = null;

                try
                {
                    unitOfWork =
                        new Dal.UnitOfWork();

                    Models.User user = new Models.User();

                    user.Id       = id;
                    user.IsActive = false;
                    user.Username = "******";

                    unitOfWork.UserRepository.Update(user);

                    unitOfWork.Save();
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (unitOfWork != null)
                    {
                        unitOfWork.Dispose();
                        unitOfWork = null;
                    }
                }
            }
            // **************************************************
            // /UnitOfWork - Just Update The User with Id -> Save The User Changes To Database
            // **************************************************

            // **************************************************
            // DatabaseContext - Get The User From Database -> Delete The User
            // **************************************************
            {
                Models.DatabaseContext databaseContext = null;

                try
                {
                    databaseContext =
                        new Models.DatabaseContext();

                    //Models.User user =
                    //	databaseContext.Users
                    //	.Where(current => current.Id == id)
                    //	.FirstOrDefault();

                    Models.User user =
                        databaseContext.Users
                        .Where(current => string.Compare(current.Username, username, true) == 0)
                        .FirstOrDefault();

                    if (user != null)
                    {
                        databaseContext.Users.Remove(user);

                        databaseContext.SaveChanges();
                    }
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (databaseContext != null)
                    {
                        databaseContext.Dispose();
                        databaseContext = null;
                    }
                }
            }
            // **************************************************
            // /DatabaseContext - Get The User From Database -> Delete The User
            // **************************************************

            // **************************************************
            // UnitOfWork - Get The User From Database -> Delete The User
            // **************************************************
            {
                Dal.UnitOfWork unitOfWork = null;

                try
                {
                    unitOfWork =
                        new Dal.UnitOfWork();

                    //Models.User user =
                    //	unitOfWork.UserRepository.GetById(id);

                    Models.User user =
                        unitOfWork.UserRepository.GetByUsername(username);

                    if (user != null)
                    {
                        unitOfWork.UserRepository.Delete(user);

                        unitOfWork.Save();
                    }
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (unitOfWork != null)
                    {
                        unitOfWork.Dispose();
                        unitOfWork = null;
                    }
                }
            }
            // **************************************************
            // /UnitOfWork - Get The User From Database -> Delete The User
            // **************************************************

            // **************************************************
            // DatabaseContext - Just Delete The User with Id
            // **************************************************
            {
                Models.DatabaseContext databaseContext = null;

                try
                {
                    databaseContext =
                        new Models.DatabaseContext();

                    Models.User user = new Models.User();

                    user.Id = id;

                    databaseContext.Entry(user).State =
                        System.Data.Entity.EntityState.Deleted;

                    databaseContext.SaveChanges();
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (databaseContext != null)
                    {
                        databaseContext.Dispose();
                        databaseContext = null;
                    }
                }
            }
            // **************************************************
            // /DatabaseContext - Just Delete The User with Id
            // **************************************************

            // **************************************************
            // UnitOfWork - Just Delete The User with Id
            // **************************************************
            {
                Dal.UnitOfWork unitOfWork = null;

                try
                {
                    unitOfWork =
                        new Dal.UnitOfWork();

                    Models.User user = new Models.User();

                    user.Id = id;

                    unitOfWork.UserRepository.Delete(user);

                    unitOfWork.Save();
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (unitOfWork != null)
                    {
                        unitOfWork.Dispose();
                        unitOfWork = null;
                    }
                }
            }
            // **************************************************
            // /UnitOfWork - Just Delete The User with Id
            // **************************************************

            // **************************************************
            // DatabaseContext - Get Users For Filling DropDownList
            // **************************************************
            {
                Models.DatabaseContext databaseContext = null;

                try
                {
                    databaseContext =
                        new Models.DatabaseContext();

                    //var users =
                    //	databaseContext.Users
                    //	.ToList()
                    //	;

                    //var users =
                    //	databaseContext.Users
                    //	.OrderBy(current => current.Username)
                    //	.ToList()
                    //	;

                    var users =
                        databaseContext.Users
                        .Where(current => current.IsActive)
                        .OrderBy(current => current.Username)
                        .ToList()
                    ;

                    //var users =
                    //	databaseContext.Users
                    //	.Where(current => current.IsActive)
                    //	.Where(current => current.IsDeleted == false)
                    //	.OrderBy(current => current.Username)
                    //	.ToList()
                    //	;
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (databaseContext != null)
                    {
                        databaseContext.Dispose();
                        databaseContext = null;
                    }
                }
            }
            // **************************************************
            // /DatabaseContext - Get Users For Filling DropDownList
            // **************************************************

            // **************************************************
            // UnitOfWork - Get Users For Filling DropDownList
            // **************************************************
            {
                Dal.UnitOfWork unitOfWork = null;

                try
                {
                    unitOfWork =
                        new Dal.UnitOfWork();

                    var users =
                        unitOfWork.UserRepository.GetActiveUsers();
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (unitOfWork != null)
                    {
                        unitOfWork.Dispose();
                        unitOfWork = null;
                    }
                }
            }
            // **************************************************
            // /UnitOfWork - Get Users For Filling DropDownList
            // **************************************************
        }