コード例 #1
0
        public override void Execute(object parameter)
        {
            int situation = viewModel.CurrentSituation;

            if (situation == (int)Constants.SITUATIONS.NORMAL)
            {
                viewModel.CurrentSituation = (int)Constants.SITUATIONS.ADD;
            }
            else if (situation == (int)Constants.SITUATIONS.SELECTED)
            {
                viewModel.CurrentSituation = (int)Constants.SITUATIONS.EDIT;
            }
            else
            {
                if (IsValid())
                {
                    CorrectData();

                    if (situation == (int)Constants.SITUATIONS.ADD)
                    {
                        var branch = BranchMapper.Map(viewModel.CurrentBranch, new Branch());
                        branch.IsDeleted    = false;
                        branch.CreationDate = DateTime.Now;
                        branch.Creator      = Kernel.AuthenticatedUser;

                        DB.BranchRepository.Add(branch);
                    }
                    else if (situation == (int)Constants.SITUATIONS.EDIT)
                    {
                        int id             = viewModel.CurrentBranch.Id;
                        var existingBranch = DB.BranchRepository.FindById(id);
                        if (existingBranch != null)
                        {
                            existingBranch = BranchMapper.Map(viewModel.CurrentBranch, existingBranch);
                            existingBranch.CreationDate = DateTime.Now;
                            existingBranch.Creator      = Kernel.AuthenticatedUser;
                            DB.BranchRepository.Update(existingBranch);
                        }
                    }

                    viewModel.Message = "Əməliyyat uğurla həyata keçdi";
                    BusinessUtil.DoAnimation(viewModel.MessageDialog);

                    // reload all branches
                    List <Branch>      branches = DB.BranchRepository.Get();
                    List <BranchModel> models   = new List <BranchModel>();
                    foreach (var entity in branches)
                    {
                        var model = BranchMapper.Map(entity);
                        models.Add(model);
                    }

                    viewModel.Branches = new List <BranchModel>(models);
                    viewModel.InitializeViewModel();
                }
            }
        }
コード例 #2
0
        public override void Execute(object parameter)
        {
            BranchControl   branchControl   = new BranchControl();
            BranchViewModel branchViewModel = new BranchViewModel();

            branchViewModel.MessageDialog = branchControl.MessageDialog;

            List <Branch>      branches = DB.BranchRepository.Get();
            List <BranchModel> models   = new List <BranchModel>();

            foreach (var branch in branches)
            {
                var model = BranchMapper.Map(branch);
                models.Add(model);
            }

            branchViewModel.AllBranches = new List <BranchModel>(models);
            branchViewModel.InitializeViewModel();
            branchControl.DataContext = branchViewModel;

            viewModel.Grid.Children.Clear();
            viewModel.Grid.Children.Add(branchControl);
        }
コード例 #3
0
        public override void Execute(object parameter)
        {
            DialogViewModel dialogViewModel = new DialogViewModel();

            dialogViewModel.DialogText = "Silmək istədiyinizdən əminsinizmi?";

            Dialog dialog = new Dialog();

            dialog.DataContext = dialogViewModel;
            if (dialog.ShowDialog() == true)
            {
                int id     = viewModel.SelectedBranch.Id;
                var branch = DB.BranchRepository.FindById(id);
                if (branch != null)
                {
                    branch.IsDeleted = true;
                    DB.BranchRepository.Update(branch);
                }

                viewModel.Message = "Əməliyyat uğurla həyata keçdi";
                BusinessUtil.DoAnimation(viewModel.MessageDialog);

                // reload all branches
                List <Branch>      branches = DB.BranchRepository.Get();
                List <BranchModel> models   = new List <BranchModel>();
                foreach (var entity in branches)
                {
                    var model = BranchMapper.Map(entity);
                    models.Add(model);
                }

                viewModel.Branches = new List <BranchModel>(models);
                viewModel.InitializeViewModel();

                Logger.LogInformation($"Branch: {id}  has been deleted");
            }
        }