Пример #1
0
        public static IRepositoryDocument GetRepositoryDocument(EnumRepositoryType type)
        {
            string path = (EngineConfiguration.Instance).PathFolderRepository;

            switch (type)
            {
                case EnumRepositoryType.Folder:
                    return new RepositoryDocumentFolder(path);
                    
                case EnumRepositoryType.SQL:
                    throw new NotImplementedException();
                    
                default:
                    throw new NotImplementedException(Messages.RepositoryDocumentNotImplemented);
                    
            }
        }
Пример #2
0
        private void DosomethingWithOrders(EnumRepositoryType repoType, bool useSingleTransaction, IUnitOfWorkGeneric work, bool showMessages)
        {
            int editIndex = 0;
            int count = 0;
            try
            {
                // Get current count
                count = work.PearsonRepository.GetAll().Count();

                lblStatistics.Text = "Total pearsons returned: " + count.ToString();

                // Add new pearson and orders
                Pearson newPearson = new Entities.Pearson { FirstName = "Marko", LastName = "Novak" };

                newPearson = work.PearsonRepository.Create(newPearson);

                newPearson = work.PearsonRepository.GetById(newPearson.Id);

                newPearson.Orders.Add(new Order { Pearson = newPearson, Price = 45, Subject = "Some demo text..." });

                newPearson.Orders.Add(new Order { Pearson = newPearson, Price = 53, Subject = "More demo text..." });

                // Add Orders on created pearson
                editIndex = GetEditIndex(count);

                lblStatistics.Text = lblStatistics.Text + ", Edit index: " + editIndex.ToString();

                Pearson updatePearson = work.PearsonRepository.GetAll().ToArray()[editIndex];

                updatePearson.Orders.Add(new Order { Pearson = updatePearson, Price = 45, Subject = "Some demo text..." });

                updatePearson.Orders.Add(new Order { Pearson = updatePearson, Price = 53, Subject = "More demo text..." });

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: \n" + ex.Message);
            }
        }
Пример #3
0
        private void Dosomething(EnumRepositoryType repoType, bool useSingleTransaction, IUnitOfWork work, bool showMessages)
        {
            int deleteIndex = 0;
            int editIndex = 0;
            int count = 0;
            try
            {
                string data;

                // Get current count
                count = work.PearsonRepository.Get().Count();

                lblStatistics.Text = "Total pearsons returned: " + count.ToString();

                work.PearsonRepository.Create(new Entities.Pearson { FirstName = "Peter", LastName = "Topolšek" });
                work.PearsonRepository.Create(new Entities.Pearson { FirstName = "Peter", LastName = "Topolšek" });

                if (!useSingleTransaction)
                    work.Save();

                deleteIndex = GetDeleteIndex(count);
                editIndex = GetEditIndex(count);

                data = string.Join(",", work.PearsonRepository.Get().Select(p => p.FirstName).ToArray());

                if (showMessages)
                    MessageBox.Show("Before edit: \n" + data);

                Pearson updatePearson = work.PearsonRepository.Get().ToArray()[editIndex];

                updatePearson.FirstName = "Katarina";
                updatePearson.LastName = "Ročnik";

                work.PearsonRepository.Update(updatePearson);

                Pearson deletePearson = work.PearsonRepository.Get().ToArray()[deleteIndex];

                work.PearsonRepository.Delete(deletePearson.Id);

                if (!useSingleTransaction)
                    work.Save();

                data = string.Join(",", work.PearsonRepository.Get().Select(p => p.FirstName).ToArray());
                if (showMessages)
                    MessageBox.Show("After edit: \n" + data);

                if (showMessages)
                    MessageBox.Show("Final result: \n" + data + "\n Število vseh: " + work.PearsonRepository.Get().Count().ToString());

                if (chkRaiseError.Checked)
                    throw new Exception("Error, nothing should be saved or everything, depends of UnitOfWork/Repository combination you pick...");

                work.Save();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: \n" + ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }