Example #1
0
        public BusinessPartnerByConstructionSiteListResponse Sync(SyncBusinessPartnerByConstructionSiteRequest request)
        {
            BusinessPartnerByConstructionSiteListResponse response = new BusinessPartnerByConstructionSiteListResponse();

            try
            {
                response.BusinessPartnerByConstructionSites = new List <BusinessPartnerByConstructionSiteViewModel>();

                if (request.LastUpdatedAt != null)
                {
                    response.BusinessPartnerByConstructionSites.AddRange(unitOfWork.GetBusinessPartnerByConstructionSiteRepository()
                                                                         .GetBusinessPartnerByConstructionSitesNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt)
                                                                         ?.ConvertToBusinessPartnerByConstructionSiteViewModelList() ?? new List <BusinessPartnerByConstructionSiteViewModel>());
                }
                else
                {
                    response.BusinessPartnerByConstructionSites.AddRange(unitOfWork.GetBusinessPartnerByConstructionSiteRepository()
                                                                         .GetBusinessPartnerByConstructionSites(request.CompanyId)
                                                                         ?.ConvertToBusinessPartnerByConstructionSiteViewModelList() ?? new List <BusinessPartnerByConstructionSiteViewModel>());
                }

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

            return(response);
        }
Example #2
0
        public BusinessPartnerByConstructionSiteListResponse Sync(SyncBusinessPartnerByConstructionSiteRequest request)
        {
            BusinessPartnerByConstructionSiteListResponse response = new BusinessPartnerByConstructionSiteListResponse();

            try
            {
                response = WpfApiHandler.SendToApi <SyncBusinessPartnerByConstructionSiteRequest, BusinessPartnerByConstructionSiteViewModel, BusinessPartnerByConstructionSiteListResponse>(request, "Sync");
            }
            catch (Exception ex)
            {
                response.BusinessPartnerByConstructionSites = new List <BusinessPartnerByConstructionSiteViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Example #3
0
        public JsonResult Sync([FromBody] SyncBusinessPartnerByConstructionSiteRequest request)
        {
            BusinessPartnerByConstructionSiteListResponse response = new BusinessPartnerByConstructionSiteListResponse();

            try
            {
                response = this.employeeByConstructionSiteService.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 void Sync(IBusinessPartnerByConstructionSiteService businessPartnerByConstructionSiteService, Action <int, int> callback = null)
        {
            try
            {
                SyncBusinessPartnerByConstructionSiteRequest request = new SyncBusinessPartnerByConstructionSiteRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                BusinessPartnerByConstructionSiteListResponse response = businessPartnerByConstructionSiteService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.BusinessPartnerByConstructionSites?.Count ?? 0;
                    List <BusinessPartnerByConstructionSiteViewModel> businessPartnerByConstructionSitesFromDB = response.BusinessPartnerByConstructionSites;

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

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

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

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

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