Beispiel #1
0
        public ShipmentDocumentListResponse Sync(SyncShipmentDocumentRequest request)
        {
            ShipmentDocumentListResponse response = new ShipmentDocumentListResponse();

            try
            {
                response.ShipmentDocuments = new List <ShipmentDocumentViewModel>();

                if (request.LastUpdatedAt != null)
                {
                    response.ShipmentDocuments.AddRange(unitOfWork.GetShipmentDocumentRepository()
                                                        .GetShipmentDocumentsNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt)
                                                        ?.ConvertToShipmentDocumentViewModelList() ?? new List <ShipmentDocumentViewModel>());
                }
                else
                {
                    response.ShipmentDocuments.AddRange(unitOfWork.GetShipmentDocumentRepository()
                                                        .GetShipmentDocuments(request.CompanyId)
                                                        ?.ConvertToShipmentDocumentViewModelList() ?? new List <ShipmentDocumentViewModel>());
                }

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

            return(response);
        }
        public ShipmentDocumentListResponse Sync(SyncShipmentDocumentRequest request)
        {
            ShipmentDocumentListResponse response = new ShipmentDocumentListResponse();

            try
            {
                response = WpfApiHandler.SendToApi <SyncShipmentDocumentRequest, ShipmentDocumentViewModel, ShipmentDocumentListResponse>(request, "Sync");
            }
            catch (Exception ex)
            {
                response.ShipmentDocuments = new List <ShipmentDocumentViewModel>();
                response.Success           = false;
                response.Message           = ex.Message;
            }

            return(response);
        }
        public JsonResult Sync([FromBody] SyncShipmentDocumentRequest request)
        {
            ShipmentDocumentListResponse response = new ShipmentDocumentListResponse();

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

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
Beispiel #4
0
        public void Sync(IShipmentDocumentService ShipmentDocumentService, Action <int, int> callback = null)
        {
            try
            {
                SyncShipmentDocumentRequest request = new SyncShipmentDocumentRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                ShipmentDocumentListResponse response = ShipmentDocumentService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.ShipmentDocuments?.Count ?? 0;
                    List <ShipmentDocumentViewModel> items = response.ShipmentDocuments;

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

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

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

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

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