Exemplo n.º 1
0
        public async Task <bool> UpdateAsync(ProfessionViewModel professionViewModel, CancellationToken ct = default(CancellationToken))
        {
            if (professionViewModel.id == null)
            {
                return(false);
            }

            var profession = await _professionRepository.GetByIdAsync((int)professionViewModel.id, ct);

            if (profession == null)
            {
                return(false);
            }

            profession.ModifiedDate = DateTime.Now;
            profession.IPAddress    = professionViewModel.iPAddress;

            profession.Name        = professionViewModel.name;
            profession.Description = professionViewModel.description;

            return(await _professionRepository.UpdateAsync(profession, ct));
        }
Exemplo n.º 2
0
        public bool UpdateProfession(ProfessionViewModel professionViewModel)
        {
            if (professionViewModel.id == null)
            {
                return(false);
            }

            var profession = _professionRepository.GetById((int)professionViewModel.id);

            if (profession == null)
            {
                return(false);
            }

            profession.ModifiedDate = DateTime.Now;
            profession.IPAddress    = professionViewModel.iPAddress;

            profession.Name        = professionViewModel.name;
            profession.Description = professionViewModel.description;

            return(_professionRepository.Update(profession));
        }
        public static Profession ConvertToProfession(this ProfessionViewModel professionViewModel)
        {
            Profession profession = new Profession()
            {
                Id         = professionViewModel.Id,
                Identifier = professionViewModel.Identifier,

                Code       = professionViewModel.Code,
                SecondCode = professionViewModel.SecondCode ?? "",
                Name       = professionViewModel.Name,

                CountryId = professionViewModel.Country?.Id ?? null,

                CreatedById = professionViewModel.CreatedBy?.Id ?? null,
                CompanyId   = professionViewModel.Company?.Id ?? null,

                CreatedAt = professionViewModel.CreatedAt,
                UpdatedAt = professionViewModel.UpdatedAt
            };

            return(profession);
        }
        public ProfessionResponse GetProfession(Guid identifier)
        {
            ProfessionResponse  response   = new ProfessionResponse();
            ProfessionViewModel profession = new ProfessionViewModel();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM Professions " +
                        "WHERE Identifier = @Identifier;", db);
                    selectCommand.Parameters.AddWithValue("@Identifier", identifier);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        ProfessionViewModel dbEntry = Read(query);
                        profession = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.Profession     = new ProfessionViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success    = true;
            response.Profession = profession;
            return(response);
        }
        public static ProfessionViewModel ConvertToProfessionViewModel(this Profession profession)
        {
            ProfessionViewModel professionViewModel = new ProfessionViewModel()
            {
                Id         = profession.Id,
                Identifier = profession.Identifier,

                Code       = profession.Code,
                SecondCode = profession.SecondCode,
                Name       = profession.Name,

                Country = profession.Country?.ConvertToCountryViewModelLite(),

                IsActive = profession.Active,

                CreatedBy = profession.CreatedBy?.ConvertToUserViewModelLite(),
                Company   = profession.Company?.ConvertToCompanyViewModelLite(),

                UpdatedAt = profession.UpdatedAt,
                CreatedAt = profession.CreatedAt
            };

            return(professionViewModel);
        }
        public void Navigate(NavigateTypes navigateTypes, object context = null)
        {
            ViewModelBase viewModel = null;

            switch (navigateTypes)
            {
            case NavigateTypes.Back:
                if (_History.Count > 0)
                {
                    viewModel = _History.Pop();
                }

                if (viewModel == null)
                {
                    viewModel = _ProfessionsViewModel;
                }

                break;

            case NavigateTypes.Help:
                if (_HelpViewModel == null)
                {
                    _HelpViewModel = new HelpViewModel();
                }

                viewModel = _HelpViewModel;

                if (_CurrentViewModel != null)
                {
                    _History.Push(_CurrentViewModel);
                }

                break;

            case NavigateTypes.Error:
                var exception = (Exception)context;

                viewModel = new ErrorViewModel(exception);
                break;

            case NavigateTypes.Profession:
                var professionName = (string)context;
                ProfessionViewModel professionViewModel;

                if (!_ProfessionViewModels.TryGetValue(professionName, out professionViewModel))
                {
                    var profession = BulkOrderDeedManager.Instance.Professions.FirstOrDefault(p => String.Compare(professionName, p.Name, true) == 0);

                    if (profession != null)
                    {
                        professionViewModel = new ProfessionViewModel(profession);
                        _ProfessionViewModels[professionName] = professionViewModel;
                        viewModel = professionViewModel;
                    }
                }
                else
                {
                    viewModel = professionViewModel;
                }

                if (viewModel != null && _CurrentViewModel != null)
                {
                    _History.Push(_CurrentViewModel);
                }

                break;

            case NavigateTypes.BulkOrderDeedsForReward:
                var professionRewardSearchCriteria = (ProfessionRewardSearchCriteria)context;
                BulkOrderDeedsForRewardViewModel bulkOrderDeedsForRewardViewModel;

                if (!_BulkOrderDeedsForRewardViewModels.TryGetValue(professionRewardSearchCriteria, out bulkOrderDeedsForRewardViewModel))
                {
                    bulkOrderDeedsForRewardViewModel = new BulkOrderDeedsForRewardViewModel(professionRewardSearchCriteria);
                    _BulkOrderDeedsForRewardViewModels[professionRewardSearchCriteria] = bulkOrderDeedsForRewardViewModel;
                }

                viewModel = bulkOrderDeedsForRewardViewModel;

                if (viewModel != null && _CurrentViewModel != null)
                {
                    _History.Push(_CurrentViewModel);
                }

                break;

            case NavigateTypes.BulkOrderDeedCollection:
                if (_CollectionViewModel == null)
                {
                    _CollectionViewModel = new CollectionViewModel();
                }

                _CollectionViewModel.RefreshIfNecessary();
                viewModel = _CollectionViewModel;

                if (_CurrentViewModel != null)
                {
                    _History.Push(_CurrentViewModel);
                }

                break;

            case NavigateTypes.AddBulkOrderDeedToCollection:
                var collectionBulkOrderDeed = (CollectionBulkOrderDeed)context;

                viewModel = new AddBulkOrderDeedToCollectionViewModel(collectionBulkOrderDeed);

                if (_CurrentViewModel != null)
                {
                    _History.Push(_CurrentViewModel);
                }

                break;

            default:
            case NavigateTypes.Professions:
                try
                {
                    if (_ProfessionsViewModel == null)
                    {
                        _ProfessionsViewModel = new ProfessionsViewModel();
                    }

                    viewModel = _ProfessionsViewModel;
                }
                catch (Exception ex)
                {
                    Navigate(NavigateTypes.Error, ex);
                }

                _History.Clear();

                break;
            }

            if (viewModel != null)
            {
                _CurrentViewModel = viewModel;
                App.Current.MainWindow.DataContext = _CurrentViewModel;
            }
        }
        public ProfessionListResponse GetProfessionsByPage(int companyId, ProfessionViewModel professionSearchObject, int currentPage = 1, int itemsPerPage = 50)
        {
            ProfessionListResponse     response    = new ProfessionListResponse();
            List <ProfessionViewModel> Professions = new List <ProfessionViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM Professions " +
                        "WHERE (@SecondCode IS NULL OR @SecondCode = '' OR SecondCode LIKE @SecondCode) " +
                        "AND (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " +
                        //"AND (@Country IS NULL OR @Country = '' OR CountryCode LIKE @Country) " +
                        "AND (@Country IS NULL OR @Country = '' OR CountryName LIKE @Country) " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC " +
                        "LIMIT @ItemsPerPage OFFSET @Offset;", db);

                    selectCommand.Parameters.AddWithValue("@SecondCode", ((object)professionSearchObject.Search_SecondCode) != null ? "%" + professionSearchObject.Search_SecondCode + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Name", ((object)professionSearchObject.Search_Name) != null ? "%" + professionSearchObject.Search_Name + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Country", ((object)professionSearchObject.Search_Country) != null ? "%" + professionSearchObject.Search_Country + "%" : "");
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);
                    selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage);
                    selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        ProfessionViewModel dbEntry = Read(query);
                        Professions.Add(dbEntry);
                    }


                    selectCommand = new SqliteCommand(
                        "SELECT Count(*) " +
                        "FROM Professions " +
                        "WHERE (@SecondCode IS NULL OR @SecondCode = '' OR SecondCode LIKE @SecondCode) " +
                        "AND (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " +
                        //"AND (@Country IS NULL OR @Country = '' OR CountryCode LIKE @Country) " +
                        "AND (@Country IS NULL OR @Country = '' OR CountryName LIKE @Country) " +
                        "AND CompanyId = @CompanyId;", db);

                    selectCommand.Parameters.AddWithValue("@SecondCode", ((object)professionSearchObject.Search_SecondCode) != null ? "%" + professionSearchObject.Search_SecondCode + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Name", ((object)professionSearchObject.Search_Name) != null ? "%" + professionSearchObject.Search_Name + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Country", ((object)professionSearchObject.Search_Country) != null ? "%" + professionSearchObject.Search_Country + "%" : "");

                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);

                    query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        response.TotalItems = query.GetInt32(0);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.Professions    = new List <ProfessionViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success     = true;
            response.Professions = Professions;
            return(response);
        }
Exemplo n.º 8
0
        private void btnProfessions_Insert_Click(object sender, RoutedEventArgs e)
        {
            Thread th = new Thread(() =>
            {
                ProfessionButtonContent = " Učitavanje EXCEL fajla... ";
                ProfessionButtonEnabled = false;

                List <ProfessionViewModel> banks = new List <ProfessionViewModel>();

                #region Excel
                OpenFileDialog oDlg   = new OpenFileDialog();
                oDlg.InitialDirectory = "C:\\";
                oDlg.Filter           = "xlsx Files (*.xlsx)|*.xlsx";
                if (true == oDlg.ShowDialog())
                {
                    Microsoft.Office.Interop.Excel.Application xlApp      = new Microsoft.Office.Interop.Excel.Application();
                    Microsoft.Office.Interop.Excel.Workbook xlWorkbook    = xlApp.Workbooks.Open(oDlg.FileName);
                    Microsoft.Office.Interop.Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
                    Microsoft.Office.Interop.Excel.Range xlRange          = xlWorksheet.UsedRange;

                    int rowCount = xlRange.Rows.Count;
                    int colCount = xlRange.Columns.Count;

                    for (int i = 2; i <= rowCount; i++)
                    {
                        ProfessionViewModel profession = new ProfessionViewModel();
                        profession.Code       = xlRange.Cells[i, 1].Text;
                        profession.SecondCode = xlRange.Cells[i, 1].Text;
                        profession.Name       = xlRange.Cells[i, 2].Text;
                        profession.Country    = new CountryViewModel()
                        {
                            Mark = xlRange.Cells[i, 3].Text
                        };

                        profession.Identifier = Guid.NewGuid();
                        profession.IsSynced   = false;
                        profession.CreatedBy  = new UserViewModel()
                        {
                            Id = MainWindow.CurrentUserId
                        };
                        profession.Company = new CompanyViewModel()
                        {
                            Id = MainWindow.CurrentCompanyId
                        };
                        profession.CreatedAt = DateTime.Now;
                        profession.UpdatedAt = DateTime.Now;

                        banks.Add(profession);
                    }
                }
                #endregion

                ProfessionButtonContent = " Unos podataka u toku... ";
                ProfessionButtonEnabled = false;

                string apiUrl = BaseApiUrl + "/SeedData/SeedProfessions";
                string values = JsonConvert.SerializeObject(
                    banks,
                    Formatting.Indented,
                    new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });

                SendData(apiUrl, values);

                ProfessionButtonContent = " Profesije ";
                ProfessionButtonEnabled = true;
            });

            th.IsBackground = true;
            th.Start();
        }
Exemplo n.º 9
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (CurrentProfession.SecondCode == null)
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Šifra"));
                return;
            }

            if (String.IsNullOrEmpty(CurrentProfession.Name))
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Naziv_zanimanja"));
                return;
            }

            #endregion

            Thread th = new Thread(() =>
            {
                SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke"));
                SaveButtonEnabled = false;

                CurrentProfession.Company = new CompanyViewModel()
                {
                    Id = MainWindow.CurrentCompanyId
                };
                CurrentProfession.CreatedBy = new UserViewModel()
                {
                    Id = MainWindow.CurrentUserId
                };

                CurrentProfession.IsSynced = false;

                //ProfessionResponse response = new ProfessionSQLiteRepository().Delete(CurrentProfession.Identifier);

                ProfessionResponse response = professionService.Create(CurrentProfession);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_čuvanja_na_serveruUzvičnik"));
                    SaveButtonContent       = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled       = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik"));
                    SaveButtonContent         = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled         = true;

                    ProfessionCreatedUpdated();

                    if (IsCreateProcess)
                    {
                        CurrentProfession            = new ProfessionViewModel();
                        CurrentProfession.Identifier = Guid.NewGuid();

                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            txtSecondCode.Focus();
                        })
                            );
                    }
                    else
                    {
                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            if (IsPopup)
                            {
                                FlyoutHelper.CloseFlyoutPopup(this);
                            }
                            else
                            {
                                FlyoutHelper.CloseFlyout(this);
                            }
                        })
                            );
                    }
                }
            });
            th.IsBackground = true;
            th.Start();
        }