Example #1
0
        public ConstructionSiteResponse Delete(Guid identifier)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            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 ConstructionSites WHERE Identifier = @Identifier";
                insertCommand.Parameters.AddWithValue("@Identifier", identifier);
                try
                {
                    insertCommand.ExecuteReader();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
Example #2
0
        public ConstructionSiteResponse Create(ConstructionSiteViewModel constructionSite)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

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

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

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, constructionSite);
                    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);
            }
        }
Example #3
0
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

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

            #endregion

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

                CurrentConstructionSite.ConstructionSiteCalculations = ConstructionSiteCalculationsFromDB;
                var test = CurrentConstructionSite;
                ConstructionSiteResponse response = constructionSiteService.Create(CurrentConstructionSite);
                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;

                    ConstructionSiteCreatedUpdated();

                    Application.Current.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Normal,
                        new Action(() =>
                    {
                        FlyoutHelper.CloseFlyout(this);
                    })
                        );
                }
            });
            td.IsBackground = true;
            td.Start();
        }
        public ConstructionSiteResponse Create(ConstructionSiteViewModel constructionSite)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            try
            {
                response = WpfApiHandler.SendToApi <ConstructionSiteViewModel, ConstructionSiteResponse>(constructionSite, "Create");
            }
            catch (Exception ex)
            {
                response.ConstructionSite = new ConstructionSiteViewModel();
                response.Success          = false;
                response.Message          = ex.Message;
            }

            return(response);
        }
        public ConstructionSiteResponse Delete(Guid identifier)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            try
            {
                ConstructionSiteViewModel re = new ConstructionSiteViewModel();
                re.Identifier = identifier;
                response      = WpfApiHandler.SendToApi <ConstructionSiteViewModel, ConstructionSiteResponse>(re, "Delete");
            }
            catch (Exception ex)
            {
                response.ConstructionSite = new ConstructionSiteViewModel();
                response.Success          = false;
                response.Message          = ex.Message;
            }

            return(response);
        }
Example #6
0
        public JsonResult Delete([FromBody] ConstructionSiteViewModel constructionSite)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            try
            {
                response = this.constructionSiteService.Delete(constructionSite.Identifier);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                Console.WriteLine(ex.Message);
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
Example #7
0
        public ConstructionSiteResponse DeleteAll()
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            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 ConstructionSites";
                    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 ConstructionSiteResponse Delete(Guid identifier)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            try
            {
                ConstructionSite deletedConstructionSite = unitOfWork.GetConstructionSiteRepository().Delete(identifier);

                unitOfWork.Save();

                response.ConstructionSite = deletedConstructionSite.ConvertToConstructionSiteViewModel();
                response.Success          = true;
            }
            catch (Exception ex)
            {
                response.ConstructionSite = new ConstructionSiteViewModel();
                response.Success          = false;
                response.Message          = ex.Message;
            }

            return(response);
        }
Example #9
0
        public ConstructionSiteResponse GetConstructionSite(Guid identifier)
        {
            ConstructionSiteResponse  response         = new ConstructionSiteResponse();
            ConstructionSiteViewModel constructionSite = new ConstructionSiteViewModel();

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

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        ConstructionSiteViewModel dbEntry = Read(query);
                        constructionSite = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage   = error.Message;
                    response.Success          = false;
                    response.Message          = error.Message;
                    response.ConstructionSite = new ConstructionSiteViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success          = true;
            response.ConstructionSite = constructionSite;
            return(response);
        }
        public ConstructionSiteResponse Create(ConstructionSiteViewModel constructionSite)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            try
            {
                // Backup items
                List <ConstructionSiteDocumentViewModel> constructionSiteDocuments = constructionSite.ConstructionSiteDocuments?.ToList() ?? new List <ConstructionSiteDocumentViewModel>();
                constructionSite.ConstructionSiteDocuments = null;
                List <ConstructionSiteNoteViewModel> constructionSiteNotes = constructionSite.ConstructionSiteNotes?.ToList() ?? new List <ConstructionSiteNoteViewModel>();
                constructionSite.ConstructionSiteNotes = null;
                List <ConstructionSiteCalculationViewModel> constructionSiteCalculations = constructionSite.ConstructionSiteCalculations?.ToList() ?? new List <ConstructionSiteCalculationViewModel>();
                constructionSite.ConstructionSiteCalculations = null;

                ConstructionSite createdConstructionSite = unitOfWork.GetConstructionSiteRepository()
                                                           .Create(constructionSite.ConvertToConstructionSite());

                // Update notes
                if (constructionSiteNotes != null && constructionSiteNotes.Count > 0)
                {
                    foreach (ConstructionSiteNoteViewModel item in constructionSiteNotes
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <ConstructionSiteNoteViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetConstructionSiteNoteRepository().Create(item.ConvertToConstructionSiteNote());
                    }

                    foreach (ConstructionSiteNoteViewModel item in constructionSiteNotes
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <ConstructionSiteNoteViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        unitOfWork.GetConstructionSiteNoteRepository().Create(item.ConvertToConstructionSiteNote());

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

                // Update documents
                if (constructionSiteDocuments != null && constructionSiteDocuments.Count > 0)
                {
                    foreach (ConstructionSiteDocumentViewModel item in constructionSiteDocuments
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <ConstructionSiteDocumentViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetConstructionSiteDocumentRepository().Create(item.ConvertToConstructionSiteDocument());
                    }

                    foreach (ConstructionSiteDocumentViewModel item in constructionSiteDocuments
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <ConstructionSiteDocumentViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        unitOfWork.GetConstructionSiteDocumentRepository().Create(item.ConvertToConstructionSiteDocument());

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

                // Update calculations
                if (constructionSiteCalculations != null && constructionSiteCalculations.Count > 0)
                {
                    foreach (ConstructionSiteCalculationViewModel item in constructionSiteCalculations
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <ConstructionSiteCalculationViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetConstructionSiteCalculationRepository().Create(item.ConvertToConstructionSiteCalculation());
                    }

                    foreach (ConstructionSiteCalculationViewModel item in constructionSiteCalculations
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <ConstructionSiteCalculationViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        unitOfWork.GetConstructionSiteCalculationRepository().Create(item.ConvertToConstructionSiteCalculation());

                        unitOfWork.GetConstructionSiteCalculationRepository().Delete(item.Identifier);
                    }
                }
                //// Update items
                //var ConstructionSiteDocumentsFromDB = unitOfWork.GetConstructionSiteDocumentRepository().GetConstructionSiteDocumentsByConstructionSite(createdConstructionSite.Id);
                //foreach (var item in ConstructionSiteDocumentsFromDB)
                //    if (!constructionSiteDocuments.Select(x => x.Identifier).Contains(item.Identifier))
                //        unitOfWork.GetConstructionSiteDocumentRepository().Delete(item.Identifier);
                //foreach (var item in constructionSiteDocuments)
                //{
                //    item.ConstructionSite = new ConstructionSiteViewModel() { Id = createdConstructionSite.Id };
                //    unitOfWork.GetConstructionSiteDocumentRepository().Create(item.ConvertToConstructionSiteDocument());
                //}

                //var ConstructionSiteNotesFromDB = unitOfWork.GetConstructionSiteNoteRepository().GetConstructionSiteNotesByConstructionSite(createdConstructionSite.Id);
                //foreach (var item in ConstructionSiteNotesFromDB)
                //    if (!constructionSiteNotes.Select(x => x.Identifier).Contains(item.Identifier))
                //        unitOfWork.GetConstructionSiteNoteRepository().Delete(item.Identifier);
                //foreach (var item in constructionSiteNotes)
                //{
                //    item.ConstructionSite = new ConstructionSiteViewModel() { Id = createdConstructionSite.Id };
                //    unitOfWork.GetConstructionSiteNoteRepository().Create(item.ConvertToConstructionSiteNote());
                //}

                unitOfWork.Save();

                response.ConstructionSite = createdConstructionSite.ConvertToConstructionSiteViewModel();
                response.Success          = true;
            }
            catch (Exception ex)
            {
                response.ConstructionSite = new ConstructionSiteViewModel();
                response.Success          = false;
                response.Message          = ex.Message;
            }

            return(response);
        }