Пример #1
0
        public EmployeeByBusinessPartnerListResponse GetEmployeeByBusinessPartnersNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse();

            try
            {
                if (lastUpdateTime != null)
                {
                    response.EmployeeByBusinessPartners = unitOfWork.GetEmployeeByBusinessPartnerRepository()
                                                          .GetEmployeeByBusinessPartnersNewerThen(companyId, (DateTime)lastUpdateTime)
                                                          .ConvertToEmployeeByBusinessPartnerViewModelList();
                }
                else
                {
                    response.EmployeeByBusinessPartners = unitOfWork.GetEmployeeByBusinessPartnerRepository()
                                                          .GetEmployeeByBusinessPartners(companyId)
                                                          .ConvertToEmployeeByBusinessPartnerViewModelList();
                }
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Пример #2
0
        public EmployeeByBusinessPartnerListResponse Sync(SyncEmployeeByBusinessPartnerRequest request)
        {
            EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse();

            try
            {
                response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();

                if (request.LastUpdatedAt != null)
                {
                    response.EmployeeByBusinessPartners.AddRange(unitOfWork.GetEmployeeByBusinessPartnerRepository()
                                                                 .GetEmployeeByBusinessPartnersNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt)
                                                                 ?.ConvertToEmployeeByBusinessPartnerViewModelList() ?? new List <EmployeeByBusinessPartnerViewModel>());
                }
                else
                {
                    response.EmployeeByBusinessPartners.AddRange(unitOfWork.GetEmployeeByBusinessPartnerRepository()
                                                                 .GetEmployeeByBusinessPartners(request.CompanyId)
                                                                 ?.ConvertToEmployeeByBusinessPartnerViewModelList() ?? new List <EmployeeByBusinessPartnerViewModel>());
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Пример #3
0
        public EmployeeByBusinessPartnerListResponse Sync(SyncEmployeeByBusinessPartnerRequest request)
        {
            EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse();

            try
            {
                response = WpfApiHandler.SendToApi <SyncEmployeeByBusinessPartnerRequest, EmployeeByBusinessPartnerViewModel, EmployeeByBusinessPartnerListResponse>(request, "Sync");
            }
            catch (Exception ex)
            {
                response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Пример #4
0
        public JsonResult GetEmployeeByBusinessPartners(int companyId)
        {
            EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse();

            try
            {
                response = employeeByBusinessPartnerService.GetEmployeeByBusinessPartners(companyId);
            }
            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
            }));
        }
Пример #5
0
        public JsonResult Sync([FromBody] SyncEmployeeByBusinessPartnerRequest request)
        {
            EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse();

            try
            {
                response = this.employeeByBusinessPartnerService.Sync(request);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
Пример #6
0
        public EmployeeByBusinessPartnerListResponse GetEmployeeByBusinessPartners(int companyId)
        {
            EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse();

            try
            {
                response.EmployeeByBusinessPartners = unitOfWork.GetEmployeeByBusinessPartnerRepository().GetEmployeeByBusinessPartners(companyId)
                                                      .ConvertToEmployeeByBusinessPartnerViewModelList();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Пример #7
0
        public EmployeeByBusinessPartnerListResponse GetByEmployee(int companyId, Guid EmployeeIdentifier)
        {
            EmployeeByBusinessPartnerListResponse     response = new EmployeeByBusinessPartnerListResponse();
            List <EmployeeByBusinessPartnerViewModel> EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM EmployeeByBusinessPartners " +
                        "WHERE EmployeeIdentifier = @EmployeeIdentifier " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC;", db);

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

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        EmployeeByBusinessPartnerViewModel dbEntry = Read(query);
                        EmployeeByBusinessPartners.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage             = error.Message;
                    response.Success                    = false;
                    response.Message                    = error.Message;
                    response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.EmployeeByBusinessPartners = EmployeeByBusinessPartners;
            return(response);
        }
Пример #8
0
        public EmployeeByBusinessPartnerListResponse GetEmployeeByBusinessPartners(int companyId)
        {
            EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse();

            try
            {
                response = WpfApiHandler.GetFromApi <List <EmployeeByBusinessPartnerViewModel>, EmployeeByBusinessPartnerListResponse>("GetEmployeeByBusinessPartners", new Dictionary <string, string>()
                {
                    { "CompanyId", companyId.ToString() }
                });
            }
            catch (Exception ex)
            {
                response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Пример #9
0
        public void Sync(IEmployeeByBusinessPartnerService employeeByBusinessPartnerService, Action <int, int> callback = null)
        {
            try
            {
                SyncEmployeeByBusinessPartnerRequest request = new SyncEmployeeByBusinessPartnerRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                EmployeeByBusinessPartnerListResponse response = employeeByBusinessPartnerService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.EmployeeByBusinessPartners?.Count ?? 0;
                    List <EmployeeByBusinessPartnerViewModel> employeeByBusinessPartnersFromDB = response.EmployeeByBusinessPartners;

                    using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName))
                    {
                        db.Open();
                        using (var transaction = db.BeginTransaction())
                        {
                            SqliteCommand deleteCommand = db.CreateCommand();
                            deleteCommand.CommandText = "DELETE FROM EmployeeByBusinessPartners WHERE Identifier = @Identifier";

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

                            foreach (var employeeByBusinessPartner in employeeByBusinessPartnersFromDB)
                            {
                                deleteCommand.Parameters.AddWithValue("@Identifier", employeeByBusinessPartner.Identifier);
                                deleteCommand.ExecuteNonQuery();
                                deleteCommand.Parameters.Clear();

                                if (employeeByBusinessPartner.IsActive)
                                {
                                    employeeByBusinessPartner.IsSynced = true;

                                    insertCommand = AddCreateParameters(insertCommand, employeeByBusinessPartner);
                                    insertCommand.ExecuteNonQuery();
                                    insertCommand.Parameters.Clear();

                                    syncedItems++;
                                    callback?.Invoke(syncedItems, toSync);
                                }
                            }

                            transaction.Commit();
                        }
                        db.Close();
                    }
                }
                else
                {
                    throw new Exception(response.Message);
                }
            }
            catch (Exception ex)
            {
                MainWindow.ErrorMessage = ex.Message;
            }
        }
Пример #10
0
        public EmployeeByBusinessPartnerListResponse GetByBusinessPartner(Guid businessPartnerIdentifier, string filterString, int currentPage = 1, int itemsPerPage = 50)
        {
            EmployeeByBusinessPartnerListResponse     response = new EmployeeByBusinessPartnerListResponse();
            List <EmployeeByBusinessPartnerViewModel> employeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        "SELECT ebp.ServerId, ebp.Identifier, ebp.Code, ebp.StartDate, ebp.EndDate, ebp.RealEndDate, " +
                        "e.Id, e.Identifier, e.Code, e.Name, e.EmployeeCode, e.SurName, e.Passport,  " +
                        "ebp.BusinessPartnerId, ebp.BusinessPartnerIdentifier, ebp.BusinessPartnerCode, ebp.BusinessPartnerName, ebp.BusinessPartnerInternalCode, ebp.BusinessPartnerNameGer,  " +
                        "ebp.IsSynced, ebp.UpdatedAt, ebp.CreatedById, ebp.CreatedByName, ebp.CompanyId, ebp.CompanyName " +
                        "FROM EmployeeByBusinessPartners ebp, Employees e " +
                        "WHERE ebp.BusinessPartnerIdentifier = @BusinessPartnerIdentifier " +
                        "AND ebp.EmployeeIdentifier = e.Identifier " +
                        "ORDER BY ebp.EmployeeName " +
                        "LIMIT @ItemsPerPage OFFSET @Offset;", db);

                    selectCommand.Parameters.AddWithValue("@BusinessPartnerIdentifier", businessPartnerIdentifier);
                    selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage);
                    selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        int counter = 0;
                        EmployeeByBusinessPartnerViewModel dbEntry = new EmployeeByBusinessPartnerViewModel();
                        dbEntry.Id              = SQLiteHelper.GetInt(query, ref counter);
                        dbEntry.Identifier      = SQLiteHelper.GetGuid(query, ref counter);
                        dbEntry.Code            = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.StartDate       = SQLiteHelper.GetDateTime(query, ref counter);
                        dbEntry.EndDate         = SQLiteHelper.GetDateTime(query, ref counter);
                        dbEntry.RealEndDate     = SQLiteHelper.GetDateTime(query, ref counter);
                        dbEntry.Employee        = SQLiteHelper.GetEmployeeFull(query, ref counter);
                        dbEntry.BusinessPartner = SQLiteHelper.GetBusinessPartner(query, ref counter);
                        dbEntry.IsSynced        = SQLiteHelper.GetBoolean(query, ref counter);
                        dbEntry.UpdatedAt       = SQLiteHelper.GetDateTime(query, ref counter);
                        dbEntry.CreatedBy       = SQLiteHelper.GetCreatedBy(query, ref counter);
                        dbEntry.Company         = SQLiteHelper.GetCompany(query, ref counter);

                        employeeByBusinessPartners.Add(dbEntry);
                    }


                    response.EmployeeByBusinessPartners = employeeByBusinessPartners;

                    selectCommand = new SqliteCommand(
                        "SELECT Count(*) " +
                        "FROM EmployeeByBusinessPartners ebp, Employees e " +
                        "WHERE ebp.BusinessPartnerIdentifier = @BusinessPartnerIdentifier " +
                        "AND ebp.EmployeeIdentifier = e.Identifier;", db);
                    selectCommand.Parameters.AddWithValue("@BusinessPartnerIdentifier", businessPartnerIdentifier);

                    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.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.EmployeeByBusinessPartners = employeeByBusinessPartners;
            return(response);
        }