Beispiel #1
0
        public EmployeeByConstructionSiteResponse Delete(Guid identifier)
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

            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 EmployeeByConstructionSites 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);
            }
        }
Beispiel #2
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (CurrentEmployeeOnConstructionSite == null)
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Radnik_na_odabranom_gradilištu"));
                return;
            }

            #endregion

            Thread th = new Thread(() =>
            {
                EmployeeByConstructionSiteResponse response = employeeByConstructionSiteService.Delete(CurrentEmployeeOnConstructionSite);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_brisanja_sa_serveraUzvičnik"));
                    return;
                }

                response = new EmployeeByConstructionSiteSQLiteRepository().Delete(CurrentEmployeeOnConstructionSite.Identifier);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_brisanjaUzvičnik"));
                    return;
                }

                DisplayEmployeesNotOnConstructionSiteData();
                DisplayEmployeesOnConstructionSiteData();
            });
            th.IsBackground = true;
            th.Start();
        }
Beispiel #3
0
        public EmployeeByConstructionSiteResponse Create(EmployeeByConstructionSiteViewModel employeeByConstructionSite)
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

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

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

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, employeeByConstructionSite);
                    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);
            }
        }
Beispiel #4
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (CurrentBusinessPartnerOnConstructionSite == null)
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Poslovni_partner_na_odabranom_gradilištu"));
                return;
            }

            #endregion

            Thread th = new Thread(() =>
            {
                // Remove business partner on construction site
                BusinessPartnerByConstructionSiteResponse response = businessPartnerByConstructionSiteService.Delete(CurrentBusinessPartnerOnConstructionSite);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_brisanja_sa_serveraUzvičnik"));
                    return;
                }

                // Remove employees on that construction site from that business partner
                EmployeeByConstructionSiteListResponse employeesResponse = new EmployeeByConstructionSiteSQLiteRepository()
                                                                           .GetByConstructionSiteAndBusinessPartner(
                    CurrentBusinessPartnerOnConstructionSite.ConstructionSite.Identifier,
                    CurrentBusinessPartnerOnConstructionSite.BusinessPartner.Identifier);

                foreach (var item in employeesResponse.EmployeeByConstructionSites)
                {
                    item.RealEndDate = CurrentBusinessPartnerOnConstructionSite.RealEndDate;
                    EmployeeByConstructionSiteResponse employeeResponse = employeeByConstructionSiteService.Delete(item);
                    new EmployeeByConstructionSiteSQLiteRepository().Delete(item.Identifier);
                }


                response = new BusinessPartnerByConstructionSiteSQLiteRepository().Delete(CurrentBusinessPartnerOnConstructionSite.BusinessPartner.Identifier, CurrentConstructionSite.Identifier);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_brisanjaUzvičnik"));
                    return;
                }

                DisplayBusinessPartnersOnConstructionSiteData();

                ConstructionSiteBusinessPartnerUpdated();
            });
            th.IsBackground = true;
            th.Start();
        }
Beispiel #5
0
        public EmployeeByConstructionSiteResponse Delete(EmployeeByConstructionSiteViewModel employeeByConstructionSite)
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

            try
            {
                response = WpfApiHandler.SendToApi <EmployeeByConstructionSiteViewModel, EmployeeByConstructionSiteResponse>(employeeByConstructionSite, "Delete");
            }
            catch (Exception ex)
            {
                response.EmployeeByConstructionSite = new EmployeeByConstructionSiteViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public EmployeeByConstructionSiteResponse Create(EmployeeByConstructionSiteViewModel re)
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

            try
            {
                ConstructionSite constructionSite = unitOfWork.GetConstructionSiteRepository().GetConstructionSite(re.ConstructionSite.Id);

                Employee employee = unitOfWork.GetEmployeeRepository().GetEmployeeEntity(re.Employee.Id);
                employee.ConstructionSiteCode = constructionSite.InternalCode;
                employee.ConstructionSiteName = constructionSite.Name;
                employee.UpdatedAt            = DateTime.Now;

                EmployeeByConstructionSite addedEmployeeByConstructionSite = unitOfWork.GetEmployeeByConstructionSiteRepository().Create(re.ConvertToEmployeeByConstructionSite());

                EmployeeCard ec = new EmployeeCard()
                {
                    Identifier  = Guid.NewGuid(),
                    EmployeeId  = re.Employee.Id,
                    CardDate    = addedEmployeeByConstructionSite.StartDate,
                    Description = "Radnik " + employee?.Name + " " + employee?.SurName + " je krenuo da radi na gradilištu " + constructionSite?.Name + ". Radnik je na gradilištu od: " + re.StartDate.ToString("dd.MM.yyyy") + " do " + re.EndDate.ToString("dd.MM.yyyy"),
                    PlusMinus   = "+",
                    CreatedById = re.CreatedBy?.Id,
                    CompanyId   = re.Company?.Id,
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now
                };
                unitOfWork.GetEmployeeCardRepository().Create(ec);

                unitOfWork.Save();

                response.EmployeeByConstructionSite = addedEmployeeByConstructionSite.ConvertToEmployeeByConstructionSiteViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByConstructionSite = new EmployeeByConstructionSiteViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public EmployeeByConstructionSiteResponse Delete(EmployeeByConstructionSiteViewModel re)
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

            try
            {
                EmployeeByConstructionSite deletedEmployeeByConstructionSite = unitOfWork.GetEmployeeByConstructionSiteRepository().Delete(re.ConvertToEmployeeByConstructionSite());

                Employee         employee         = unitOfWork.GetEmployeeRepository().GetEmployeeEntity((int)deletedEmployeeByConstructionSite.EmployeeId);
                ConstructionSite constructionSite = unitOfWork.GetConstructionSiteRepository().GetConstructionSite((int)deletedEmployeeByConstructionSite.ConstructionSiteId);
                employee.ConstructionSiteCode = "";
                employee.ConstructionSiteName = "";
                employee.UpdatedAt            = DateTime.Now;

                EmployeeCard ec = new EmployeeCard()
                {
                    Identifier  = Guid.NewGuid(),
                    EmployeeId  = deletedEmployeeByConstructionSite.Employee.Id,
                    CardDate    = (DateTime)deletedEmployeeByConstructionSite.RealEndDate,
                    Description = "Radnik " + employee?.Name + " " + employee.SurName + " je prestao da radi na gradilištu " + constructionSite?.Name + ". Prestanak je od: " + ((DateTime)deletedEmployeeByConstructionSite.RealEndDate).ToString("dd.MM.yyyy"),
                    CreatedById = deletedEmployeeByConstructionSite.CreatedById,
                    PlusMinus   = "-",
                    CompanyId   = deletedEmployeeByConstructionSite.CompanyId,
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now
                };
                unitOfWork.GetEmployeeCardRepository().Create(ec);

                unitOfWork.Save();

                response.EmployeeByConstructionSite = deletedEmployeeByConstructionSite.ConvertToEmployeeByConstructionSiteViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByConstructionSite = new EmployeeByConstructionSiteViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public JsonResult Delete([FromBody] EmployeeByConstructionSiteViewModel employeeByConstructionSite)
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

            try
            {
                response = this.employeeByConstructionSiteService.Delete(employeeByConstructionSite);
            }
            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
            }));
        }
Beispiel #9
0
        public EmployeeByConstructionSiteResponse DeleteAll()
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

            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 EmployeeByConstructionSites";
                    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);
        }