Пример #1
0
        public BusinessPartnerBankListResponse Sync(SyncBusinessPartnerBankRequest request)
        {
            BusinessPartnerBankListResponse response = new BusinessPartnerBankListResponse();

            try
            {
                response.BusinessPartnerBanks = new List <BusinessPartnerBankViewModel>();

                if (request.LastUpdatedAt != null)
                {
                    response.BusinessPartnerBanks.AddRange(unitOfWork.GetBusinessPartnerBankRepository()
                                                           .GetBusinessPartnerBanksNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt)
                                                           ?.ConvertToBusinessPartnerBankViewModelList() ?? new List <BusinessPartnerBankViewModel>());
                }
                else
                {
                    response.BusinessPartnerBanks.AddRange(unitOfWork.GetBusinessPartnerBankRepository()
                                                           .GetBusinessPartnerBanks(request.CompanyId)
                                                           ?.ConvertToBusinessPartnerBankViewModelList() ?? new List <BusinessPartnerBankViewModel>());
                }

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

            return(response);
        }
        public BusinessPartnerBankListResponse Sync(SyncBusinessPartnerBankRequest request)
        {
            BusinessPartnerBankListResponse response = new BusinessPartnerBankListResponse();

            try
            {
                response = WpfApiHandler.SendToApi <SyncBusinessPartnerBankRequest, BusinessPartnerBankViewModel, BusinessPartnerBankListResponse>(request, "Sync");
            }
            catch (Exception ex)
            {
                response.BusinessPartnerBanks = new List <BusinessPartnerBankViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public BusinessPartnerBankListResponse GetBusinessPartnerBanks(int companyId)
        {
            BusinessPartnerBankListResponse response = new BusinessPartnerBankListResponse();

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("CompanyID", companyId.ToString());

                response = WpfApiHandler.GetFromApi <List <BusinessPartnerBankViewModel>, BusinessPartnerBankListResponse>("GetBusinessPartnerBanks", parameters);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Пример #4
0
        public JsonResult Sync([FromBody] SyncBusinessPartnerBankRequest request)
        {
            BusinessPartnerBankListResponse response = new BusinessPartnerBankListResponse();

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

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
        public BusinessPartnerBankListResponse GetBusinessPartnerBanksNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            BusinessPartnerBankListResponse response = new BusinessPartnerBankListResponse();

            try
            {
                response = WpfApiHandler.GetFromApi <List <BusinessPartnerBankViewModel>, BusinessPartnerBankListResponse>("GetBusinessPartnerBanksNewerThen", new Dictionary <string, string>()
                {
                    { "CompanyId", companyId.ToString() },
                    { "LastUpdateTime", lastUpdateTime.ToString() }
                });
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Пример #6
0
        public BusinessPartnerBankListResponse GetBusinessPartnerBanksByBusinessPartner(int companyId, Guid businessPartnerIdentifier)
        {
            BusinessPartnerBankListResponse     response             = new BusinessPartnerBankListResponse();
            List <BusinessPartnerBankViewModel> businessPartnerBanks = new List <BusinessPartnerBankViewModel>();

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

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

                    SqliteDataReader query = selectCommand.ExecuteReader();
                    while (query.Read())
                    {
                        BusinessPartnerBankViewModel dbEntry = Read(query);
                        businessPartnerBanks.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage       = error.Message;
                    response.Success              = false;
                    response.Message              = error.Message;
                    response.BusinessPartnerBanks = new List <BusinessPartnerBankViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.BusinessPartnerBanks = businessPartnerBanks;
            return(response);
        }
Пример #7
0
        public void Sync(IBusinessPartnerBankService BusinessPartnerBankService, Action <int, int> callback = null)
        {
            try
            {
                SyncBusinessPartnerBankRequest request = new SyncBusinessPartnerBankRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                BusinessPartnerBankListResponse response = BusinessPartnerBankService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.BusinessPartnerBanks?.Count ?? 0;
                    List <BusinessPartnerBankViewModel> businessPartnerBanksFromDB = response.BusinessPartnerBanks;

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

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

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

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

                                    insertCommand = AddCreateParameters(insertCommand, businessPartnerBank);
                                    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;
            }
        }