public ShipmentListResponse GetShipmentsNewerThan(int companyId, DateTime?lastUpdateTime) { ShipmentListResponse response = new ShipmentListResponse(); try { if (lastUpdateTime != null) { response.Shipments = unitOfWork.GetShipmentRepository() .GetShipmentsNewerThan(companyId, (DateTime)lastUpdateTime) .ConvertToShipmentViewModelList(); } else { response.Shipments = unitOfWork.GetShipmentRepository() .GetShipments(companyId) .ConvertToShipmentViewModelList(); } response.Success = true; } catch (Exception ex) { response.Shipments = new List <ShipmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ShipmentListResponse Sync(SyncShipmentRequest request) { ShipmentListResponse response = new ShipmentListResponse(); try { response.Shipments = new List <ShipmentViewModel>(); if (request.LastUpdatedAt != null) { response.Shipments.AddRange(unitOfWork.GetShipmentRepository() .GetShipmentsNewerThan(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToShipmentViewModelList() ?? new List <ShipmentViewModel>()); } else { response.Shipments.AddRange(unitOfWork.GetShipmentRepository() .GetShipments(request.CompanyId) ?.ConvertToShipmentViewModelList() ?? new List <ShipmentViewModel>()); } response.Success = true; } catch (Exception ex) { response.Shipments = new List <ShipmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ShipmentListResponse Sync(SyncShipmentRequest request) { ShipmentListResponse response = new ShipmentListResponse(); try { response = WpfApiHandler.SendToApi <SyncShipmentRequest, ShipmentViewModel, ShipmentListResponse>(request, "Sync"); } catch (Exception ex) { response.Shipments = new List <ShipmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ShipmentListResponse GetShipmentsForPopup(int companyId, string filterString) { ShipmentListResponse response = new ShipmentListResponse(); List <ShipmentViewModel> Shipments = new List <ShipmentViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Shipments " + "WHERE (@Code IS NULL OR @Code = '' OR Code LIKE @Code OR Code LIKE @Code) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage;", db); selectCommand.Parameters.AddWithValue("@Code", ((object)filterString) != null ? "%" + filterString + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", ((object)filterString) != null ? companyId : 0); selectCommand.Parameters.AddWithValue("@ItemsPerPage", 100); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { ShipmentViewModel dbEntry = Read(query); Shipments.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.Shipments = new List <ShipmentViewModel>(); return(response); } db.Close(); } response.Success = true; response.Shipments = Shipments; return(response); }
public JsonResult GetShipments(int companyId) { ShipmentListResponse response = new ShipmentListResponse(); try { response = shipmentService.GetShipments(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 })); }
public JsonResult Sync([FromBody] SyncShipmentRequest request) { ShipmentListResponse response = new ShipmentListResponse(); try { response = this.shipmentService.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 ShipmentListResponse GetShipments(int companyId) { ShipmentListResponse response = new ShipmentListResponse(); try { response.Shipments = unitOfWork.GetShipmentRepository().GetShipments(companyId) .ConvertToShipmentViewModelList(); response.Success = true; } catch (Exception ex) { response.Shipments = new List <ShipmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ShipmentListResponse GetShipments(int companyId) { ShipmentListResponse response = new ShipmentListResponse(); try { response = WpfApiHandler.GetFromApi <List <ShipmentViewModel>, ShipmentListResponse>("GetShipments", new Dictionary <string, string>() { { "CompanyId", companyId.ToString() } }); } catch (Exception ex) { response.Shipments = new List <ShipmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public void Sync(IShipmentService shipmentService, Action <int, int> callback = null) { try { SyncShipmentRequest request = new SyncShipmentRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; ShipmentListResponse response = shipmentService.Sync(request); if (response.Success) { toSync = response?.Shipments?.Count ?? 0; var items = new List <ShipmentViewModel>(response.Shipments); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM Shipments 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; } }
public ShipmentListResponse GetShipmentsByPage(int companyId, ShipmentViewModel ShipmentSearchObject, int currentPage = 1, int itemsPerPage = 50) { ShipmentListResponse response = new ShipmentListResponse(); List <ShipmentViewModel> Shipments = new List <ShipmentViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Shipments " + "WHERE (@Address IS NULL OR @Address = '' OR Address LIKE @Address) " + "AND (@Acceptor IS NULL OR @Acceptor = '' OR Acceptor LIKE @Acceptor) " + "AND (@ShipmentNumber IS NULL OR @ShipmentNumber = '' OR ShipmentNumber LIKE @ShipmentNumber) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage OFFSET @Offset;", db); selectCommand.Parameters.AddWithValue("@Address", ((object)ShipmentSearchObject.SearchBy_Address) != null ? "%" + ShipmentSearchObject.SearchBy_Address + "%" : ""); selectCommand.Parameters.AddWithValue("@Acceptor", ((object)ShipmentSearchObject.SearchBy_Acceptor) != null ? "%" + ShipmentSearchObject.SearchBy_Acceptor + "%" : ""); selectCommand.Parameters.AddWithValue("@ShipmentNumber", ((object)ShipmentSearchObject.SearchBy_ShipmentNumber) != null ? "%" + ShipmentSearchObject.SearchBy_ShipmentNumber + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage); selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { ShipmentViewModel dbEntry = Read(query); Shipments.Add(dbEntry); } selectCommand = new SqliteCommand( "SELECT Count(*) " + "FROM Shipments " + "WHERE (@Address IS NULL OR @Address = '' OR Address LIKE @Address) " + "AND (@Acceptor IS NULL OR @Acceptor = '' OR Acceptor LIKE @Acceptor) " + "AND (@ShipmentNumber IS NULL OR @ShipmentNumber = '' OR ShipmentNumber LIKE @ShipmentNumber) " + "AND CompanyId = @CompanyId;", db); selectCommand.Parameters.AddWithValue("@Address", ((object)ShipmentSearchObject.SearchBy_Address) != null ? "%" + ShipmentSearchObject.SearchBy_Address + "%" : ""); selectCommand.Parameters.AddWithValue("@Acceptor", ((object)ShipmentSearchObject.SearchBy_Acceptor) != null ? "%" + ShipmentSearchObject.SearchBy_Acceptor + "%" : ""); selectCommand.Parameters.AddWithValue("@ShipmentNumber", ((object)ShipmentSearchObject.SearchBy_ShipmentNumber) != null ? "%" + ShipmentSearchObject.SearchBy_ShipmentNumber + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); 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.Shipments = new List <ShipmentViewModel>(); return(response); } db.Close(); } response.Success = true; response.Shipments = Shipments; return(response); }