public InputInvoiceListResponse Sync(SyncInputInvoiceRequest request) { InputInvoiceListResponse response = new InputInvoiceListResponse(); try { response.InputInvoices = new List <InputInvoiceViewModel>(); if (request.LastUpdatedAt != null) { response.InputInvoices.AddRange(unitOfWork.GetInputInvoiceRepository() .GetInputInvoicesNewerThan(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToInputInvoiceViewModelList() ?? new List <InputInvoiceViewModel>()); } else { response.InputInvoices.AddRange(unitOfWork.GetInputInvoiceRepository() .GetInputInvoices(request.CompanyId) ?.ConvertToInputInvoiceViewModelList() ?? new List <InputInvoiceViewModel>()); } response.Success = true; } catch (Exception ex) { response.InputInvoices = new List <InputInvoiceViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public InputInvoiceListResponse Sync(SyncInputInvoiceRequest request) { InputInvoiceListResponse response = new InputInvoiceListResponse(); try { response = WpfApiHandler.SendToApi <SyncInputInvoiceRequest, InputInvoiceViewModel, InputInvoiceListResponse>(request, "Sync"); } catch (Exception ex) { response.InputInvoices = new List <InputInvoiceViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncInputInvoiceRequest request) { InputInvoiceListResponse response = new InputInvoiceListResponse(); try { response = this.inputInvoiceService.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(IInputInvoiceService inputInvoiceService, Action <int, int> callback = null) { try { SyncInputInvoiceRequest request = new SyncInputInvoiceRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; InputInvoiceListResponse response = inputInvoiceService.Sync(request); if (response.Success) { toSync = response?.InputInvoices?.Count ?? 0; var items = new List <InputInvoiceViewModel>(response.InputInvoices); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM InputInvoices 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; } }