public static void Main(string[] args)
        {
            StateService stateService = new StateService();

            Console.WriteLine("Menu .....");
            Console.WriteLine("1. Add A new State");
            Console.WriteLine("2. Delete a State");
            Console.WriteLine("3. Update a State");

            int choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
                case 1:
                    {
                        State newState = new State();
                        Console.WriteLine("enter the State Id");
                        newState.StateId = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("enter the State Name");
                        newState.StateName = Console.ReadLine();
                        stateService.Add(newState);
                        break;
                    }
                case 2:
                    {
                        Console.WriteLine("enter the State Id");
                        int StateId = Convert.ToInt32(Console.ReadLine());
                        stateService.Delete(StateId);
                        break;
                    }
                case 3:
                    {
                        State updatedState = new State();
                        Console.WriteLine("enter the State Id");
                        updatedState.StateId = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("enter the State Name");
                        updatedState.StateName = Console.ReadLine();
                        stateService.update(updatedState);
                        break;
                    }
            }
        }
示例#2
0
        public void SyncState()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Sync required data from FHGLocal to DB

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // State Table

            Repository<int, CusState> _fhgStateRep = new Repository<int, CusState>(_UnitOfWorkFHG.Session);
            Repository<Guid, State> _aplStateRepo = new Repository<Guid, State>(_UnitOfWorkAPL.Session);

            var stateAPLDB = _aplStateRepo.All().ToList();
            var stateFHG = _fhgStateRep.All().ToList();

            int itemCount = 1;
            // Add Missing data
            foreach (CusState c in stateFHG)
            {
                e.TotalWorkItems = stateFHG.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing States - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (State s in stateAPLDB)
                {
                    if (s.Shortname == c.Shortname)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    State s = new State();
                    s.Shortname = c.Shortname;
                    s.Name = c.Fullname;
                    _aplStateRepo.Add(s);
                }

                itemCount++;
            }

            // Remove extra data.
            foreach (State s in stateAPLDB)
            {
                bool found = false;
                foreach (CusState c in stateFHG)
                {
                    if (s.Shortname == c.Shortname)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _aplStateRepo.Delete(s);
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }