public PhysicalPersonResponse Delete(Guid identifier)
        {
            PhysicalPersonResponse response = new PhysicalPersonResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();

                SqliteCommand insertCommand = new SqliteCommand();
                insertCommand.Connection = db;

                //Use parameterized query to prevent SQL injection attacks
                insertCommand.CommandText = "DELETE FROM PhysicalPersons WHERE Identifier = @Identifier";
                insertCommand.Parameters.AddWithValue("@Identifier", identifier);

                try
                {
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
        public PhysicalPersonResponse Create(PhysicalPersonViewModel physicalPerson)
        {
            PhysicalPersonResponse response = new PhysicalPersonResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();

                SqliteCommand insertCommand = db.CreateCommand();
                insertCommand.CommandText = SqlCommandInsertPart;

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, physicalPerson);
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
        public PhysicalPersonResponse Delete(Guid identifier)
        {
            PhysicalPersonResponse response = new PhysicalPersonResponse();

            try
            {
                response = WpfApiHandler.SendToApi <Guid, PhysicalPersonViewModel, PhysicalPersonResponse>(identifier, "Delete");
            }
            catch (Exception ex)
            {
                response.PhysicalPerson = new PhysicalPersonViewModel();
                response.Success        = false;
                response.Message        = ex.Message;
            }

            return(response);
        }
        public PhysicalPersonResponse Create(PhysicalPersonViewModel PhysicalPerson)
        {
            PhysicalPersonResponse response = new PhysicalPersonResponse();

            try
            {
                response = WpfApiHandler.SendToApi <PhysicalPersonViewModel, PhysicalPersonResponse>(PhysicalPerson, "Create");
            }
            catch (Exception ex)
            {
                response.PhysicalPerson = new PhysicalPersonViewModel();
                response.Success        = false;
                response.Message        = ex.Message;
            }

            return(response);
        }
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (PhysicalPersonCardsFromDB == null || PhysicalPersonCardsFromDB.Count == 0)
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Ne_postoje_stavke_za_proknjižavanje"));
                return;
            }

            #endregion

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

                CurrentPhysicalPerson.PhysicalPersonCards = PhysicalPersonCardsFromDB;
                PhysicalPersonResponse response           = physicalPersonService.Create(CurrentPhysicalPerson);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_čuvanja_na_serveruUzvičnik"));
                    SubmitButtonContent     = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled     = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik"));
                    SubmitButtonContent       = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled       = true;

                    PhysicalPersonCreatedUpdated();

                    Application.Current.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Normal,
                        new Action(() =>
                    {
                        FlyoutHelper.CloseFlyout(this);
                    })
                        );
                }
            });
            th.IsBackground = true;
            th.Start();
        }
Ejemplo n.º 6
0
        public PhysicalPersonResponse Delete(Guid identifier)
        {
            PhysicalPersonResponse response = new PhysicalPersonResponse();

            try
            {
                response.PhysicalPerson = unitOfWork.GetPhysicalPersonRepository().Delete(identifier)?.ConvertToPhysicalPersonViewModel();
                unitOfWork.Save();

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.PhysicalPerson = new PhysicalPersonViewModel();
                response.Success        = false;
                response.Message        = ex.Message;
            }

            return(response);
        }
        public PhysicalPersonResponse DeleteAll()
        {
            PhysicalPersonResponse response = new PhysicalPersonResponse();

            try
            {
                using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
                {
                    db.Open();
                    db.EnableExtensions(true);

                    SqliteCommand insertCommand = new SqliteCommand();
                    insertCommand.Connection = db;

                    //Use parameterized query to prevent SQL injection attacks
                    insertCommand.CommandText = "DELETE FROM PhysicalPersons";
                    try
                    {
                        insertCommand.ExecuteNonQuery();
                    }
                    catch (SqliteException error)
                    {
                        response.Success = false;
                        response.Message = error.Message;

                        MainWindow.ErrorMessage = error.Message;
                        return(response);
                    }
                    db.Close();
                }
            }
            catch (SqliteException error)
            {
                response.Success = false;
                response.Message = error.Message;
                return(response);
            }

            response.Success = true;
            return(response);
        }
        public PhysicalPersonResponse GetPhysicalPerson(Guid identifier)
        {
            PhysicalPersonResponse  response       = new PhysicalPersonResponse();
            PhysicalPersonViewModel PhysicalPerson = new PhysicalPersonViewModel();

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

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        PhysicalPersonViewModel dbEntry = Read(query);
                        PhysicalPerson = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.PhysicalPerson = new PhysicalPersonViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success        = true;
            response.PhysicalPerson = PhysicalPerson;
            return(response);
        }
Ejemplo n.º 9
0
        public PhysicalPersonResponse Create(PhysicalPersonViewModel physicalPerson)
        {
            PhysicalPersonResponse response = new PhysicalPersonResponse();

            try
            {
                //Backup items
                List <PhysicalPersonCardViewModel> physicalPersonCards = physicalPerson
                                                                         .PhysicalPersonCards?.ToList() ?? new List <PhysicalPersonCardViewModel>();
                physicalPerson.PhysicalPersonCards = null;

                List <PhysicalPersonDocumentViewModel> physicalPersonDocuments = physicalPerson
                                                                                 .PhysicalPersonDocuments?.ToList() ?? new List <PhysicalPersonDocumentViewModel>();
                physicalPerson.PhysicalPersonDocuments = null;

                List <PhysicalPersonItemViewModel> physicalPersonItems = physicalPerson
                                                                         .PhysicalPersonItems?.ToList() ?? new List <PhysicalPersonItemViewModel>();
                physicalPerson.PhysicalPersonItems = null;

                List <PhysicalPersonLicenceViewModel> physicalPersonLicences = physicalPerson
                                                                               .PhysicalPersonLicences?.ToList() ?? new List <PhysicalPersonLicenceViewModel>();
                physicalPerson.PhysicalPersonLicences = null;

                List <PhysicalPersonNoteViewModel> physicalPersonNotes = physicalPerson
                                                                         .PhysicalPersonNotes?.ToList() ?? new List <PhysicalPersonNoteViewModel>();
                physicalPerson.PhysicalPersonNotes = null;

                List <PhysicalPersonProfessionViewModel> physicalPersonProfessions = physicalPerson
                                                                                     .PhysicalPersonProfessions?.ToList() ?? new List <PhysicalPersonProfessionViewModel>();
                physicalPerson.PhysicalPersonProfessions = null;

                PhysicalPerson createdOutputInvoice = unitOfWork.GetPhysicalPersonRepository()
                                                      .Create(physicalPerson.ConvertToPhysicalPerson());

                // Update items
                if (physicalPersonCards != null && physicalPersonCards.Count > 0)
                {
                    foreach (PhysicalPersonCardViewModel item in physicalPersonCards
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <PhysicalPersonCardViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetPhysicalPersonCardRepository().Create(item.ConvertToPhysicalPersonCard());
                    }

                    foreach (PhysicalPersonCardViewModel item in physicalPersonCards
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <PhysicalPersonCardViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        unitOfWork.GetPhysicalPersonCardRepository().Create(item.ConvertToPhysicalPersonCard());

                        unitOfWork.GetPhysicalPersonCardRepository().Delete(item.Identifier);
                    }
                }

                // Update items
                if (physicalPersonDocuments != null && physicalPersonDocuments.Count > 0)
                {
                    foreach (PhysicalPersonDocumentViewModel item in physicalPersonDocuments
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <PhysicalPersonDocumentViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetPhysicalPersonDocumentRepository().Create(item.ConvertToPhysicalPersonDocument());
                    }

                    foreach (PhysicalPersonDocumentViewModel item in physicalPersonDocuments
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <PhysicalPersonDocumentViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        unitOfWork.GetPhysicalPersonDocumentRepository().Create(item.ConvertToPhysicalPersonDocument());

                        unitOfWork.GetPhysicalPersonDocumentRepository().Delete(item.Identifier);
                    }
                }

                // Update items
                if (physicalPersonItems != null && physicalPersonItems.Count > 0)
                {
                    foreach (PhysicalPersonItemViewModel item in physicalPersonItems
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <PhysicalPersonItemViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetPhysicalPersonItemRepository().Create(item.ConvertToPhysicalPersonItem());
                    }

                    foreach (PhysicalPersonItemViewModel item in physicalPersonItems
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <PhysicalPersonItemViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        unitOfWork.GetPhysicalPersonItemRepository().Create(item.ConvertToPhysicalPersonItem());

                        unitOfWork.GetPhysicalPersonItemRepository().Delete(item.Identifier);
                    }
                }

                // Update items
                if (physicalPersonLicences != null && physicalPersonLicences.Count > 0)
                {
                    foreach (PhysicalPersonLicenceViewModel item in physicalPersonLicences
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <PhysicalPersonLicenceViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetPhysicalPersonLicenceRepository().Create(item.ConvertToPhysicalPersonLicence());
                    }

                    foreach (PhysicalPersonLicenceViewModel item in physicalPersonLicences
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <PhysicalPersonLicenceViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        unitOfWork.GetPhysicalPersonLicenceRepository().Create(item.ConvertToPhysicalPersonLicence());

                        unitOfWork.GetPhysicalPersonLicenceRepository().Delete(item.Identifier);
                    }
                }

                // Update items
                if (physicalPersonNotes != null && physicalPersonNotes.Count > 0)
                {
                    foreach (PhysicalPersonNoteViewModel item in physicalPersonNotes
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <PhysicalPersonNoteViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetPhysicalPersonNoteRepository().Create(item.ConvertToPhysicalPersonNote());
                    }

                    foreach (PhysicalPersonNoteViewModel item in physicalPersonNotes
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <PhysicalPersonNoteViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        unitOfWork.GetPhysicalPersonNoteRepository().Create(item.ConvertToPhysicalPersonNote());

                        unitOfWork.GetPhysicalPersonNoteRepository().Delete(item.Identifier);
                    }
                }

                // Update items
                if (physicalPersonProfessions != null && physicalPersonProfessions.Count > 0)
                {
                    foreach (PhysicalPersonProfessionViewModel item in physicalPersonProfessions
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <PhysicalPersonProfessionViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetPhysicalPersonProfessionRepository().Create(item.ConvertToPhysicalPersonProfession());
                    }

                    foreach (PhysicalPersonProfessionViewModel item in physicalPersonProfessions
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <PhysicalPersonProfessionViewModel>())
                    {
                        item.PhysicalPerson = new PhysicalPersonViewModel()
                        {
                            Id = createdOutputInvoice.Id
                        };
                        unitOfWork.GetPhysicalPersonProfessionRepository().Create(item.ConvertToPhysicalPersonProfession());

                        unitOfWork.GetPhysicalPersonProfessionRepository().Delete(item.Identifier);
                    }
                }

                unitOfWork.Save();

                response.PhysicalPerson = createdOutputInvoice.ConvertToPhysicalPersonViewModel();
                response.Success        = true;
            }
            catch (Exception ex)
            {
                response.PhysicalPerson = new PhysicalPersonViewModel();
                response.Success        = false;
                response.Message        = ex.Message;
            }

            return(response);
        }