Exemple #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();
                }
            }
        }
Exemple #2
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");
            }
        }