public ConstructionSiteListResponse GetConstructionSitesNewerThen(int companyId, DateTime?lastUpdateTime) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); try { if (lastUpdateTime != null) { response.ConstructionSites = unitOfWork.GetConstructionSiteRepository() .GetConstructionSitesNewerThen(companyId, (DateTime)lastUpdateTime) .ConvertToConstructionSiteViewModelList(); } else { response.ConstructionSites = unitOfWork.GetConstructionSiteRepository() .GetConstructionSites(companyId) .ConvertToConstructionSiteViewModelList(); } response.Success = true; } catch (Exception ex) { response.ConstructionSites = new List <ConstructionSiteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ConstructionSiteListResponse Sync(SyncConstructionSiteRequest request) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); try { response.ConstructionSites = new List <ConstructionSiteViewModel>(); if (request.LastUpdatedAt != null) { response.ConstructionSites.AddRange(unitOfWork.GetConstructionSiteRepository() .GetConstructionSitesNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToConstructionSiteViewModelList() ?? new List <ConstructionSiteViewModel>()); } else { response.ConstructionSites.AddRange(unitOfWork.GetConstructionSiteRepository() .GetConstructionSites(request.CompanyId) ?.ConvertToConstructionSiteViewModelList() ?? new List <ConstructionSiteViewModel>()); } response.Success = true; } catch (Exception ex) { response.ConstructionSites = new List <ConstructionSiteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ConstructionSiteListResponse GetConstructionSitesForPopup(int companyId, string filterString) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); List <ConstructionSiteViewModel> ConstructionSites = new List <ConstructionSiteViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM ConstructionSites " + "WHERE (@Code IS NULL OR @Code = '' OR InternalCode LIKE @Code) " + "AND (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@ShortName IS NULL OR @ShortName = '' OR ShortName LIKE @ShortName) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage;", db); selectCommand.Parameters.AddWithValue("@Code", ((object)filterString) != null ? "%" + filterString + "%" : ""); selectCommand.Parameters.AddWithValue("@Name", ((object)filterString) != null ? "%" + filterString + "%" : ""); selectCommand.Parameters.AddWithValue("@ShortName", ((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()) { ConstructionSiteViewModel dbEntry = Read(query); ConstructionSites.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.ConstructionSites = new List <ConstructionSiteViewModel>(); return(response); } db.Close(); } response.Success = true; response.ConstructionSites = ConstructionSites; return(response); }
public ConstructionSiteListResponse Sync(SyncConstructionSiteRequest request) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); try { response = WpfApiHandler.SendToApi <SyncConstructionSiteRequest, ConstructionSiteViewModel, ConstructionSiteListResponse>(request, "Sync"); } catch (Exception ex) { response.ConstructionSites = new List <ConstructionSiteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ConstructionSiteListResponse GetConstructionSites(int companyId) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); try { response.ConstructionSites = unitOfWork.GetConstructionSiteRepository().GetConstructionSites(companyId) .ConvertToConstructionSiteViewModelList(); response.Success = true; } catch (Exception ex) { response.ConstructionSites = new List <ConstructionSiteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult GetConstructionSites(int companyId) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); try { response = constructionSiteService.GetConstructionSites(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] SyncConstructionSiteRequest request) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); try { response = this.constructionSiteService.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 ConstructionSiteListResponse GetConstructionSites(int companyId) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); try { response = WpfApiHandler.GetFromApi <List <ConstructionSiteViewModel>, ConstructionSiteListResponse>("GetConstructionSites", new Dictionary <string, string>() { { "CompanyId", companyId.ToString() } }); } catch (Exception ex) { response.ConstructionSites = new List <ConstructionSiteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public void Sync(IConstructionSiteService constructionSiteService, Action <int, int> callback = null) { try { SyncConstructionSiteRequest request = new SyncConstructionSiteRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; ConstructionSiteListResponse response = constructionSiteService.Sync(request); if (response.Success) { toSync = response?.ConstructionSites?.Count ?? 0; var items = new List <ConstructionSiteViewModel>(response.ConstructionSites); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM ConstructionSites 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 ConstructionSiteListResponse GetConstructionSitesByPage(int companyId, ConstructionSiteViewModel constructionSiteSearchObject, int currentPage = 1, int itemsPerPage = 50) { ConstructionSiteListResponse response = new ConstructionSiteListResponse(); List <ConstructionSiteViewModel> ConstructionSites = new List <ConstructionSiteViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM ConstructionSites " + "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@City IS NULL OR @City = '' OR CityName LIKE @City) " + "AND (@InternalCode IS NULL OR @InternalCode = '' OR InternalCode LIKE @InternalCode) " + "AND (@BusinessPartnerName IS NULL OR @BusinessPartnerName = '' OR BusinessPartnerName LIKE @BusinessPartnerName) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage OFFSET @Offset;", db); selectCommand.Parameters.AddWithValue("@Name", ((object)constructionSiteSearchObject.Search_Name) != null ? "%" + constructionSiteSearchObject.Search_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@City", ((object)constructionSiteSearchObject.Search_City) != null ? "%" + constructionSiteSearchObject.Search_City + "%" : ""); selectCommand.Parameters.AddWithValue("@InternalCode", ((object)constructionSiteSearchObject.Search_InternalCode) != null ? "%" + constructionSiteSearchObject.Search_InternalCode + "%" : ""); selectCommand.Parameters.AddWithValue("@BusinessPartnerName", ((object)constructionSiteSearchObject.Search_BusinessPartnerName) != null ? "%" + constructionSiteSearchObject.Search_BusinessPartnerName + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage); selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { ConstructionSiteViewModel dbEntry = Read(query); ConstructionSites.Add(dbEntry); } selectCommand = new SqliteCommand( "SELECT Count(*) " + "FROM ConstructionSites " + "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@City IS NULL OR @City = '' OR CityName LIKE @City) " + "AND (@InternalCode IS NULL OR @InternalCode = '' OR InternalCode LIKE @InternalCode) " + "AND (@BusinessPartnerName IS NULL OR @BusinessPartnerName = '' OR BusinessPartnerName LIKE @BusinessPartnerName) " + "AND CompanyId = @CompanyId;", db); selectCommand.Parameters.AddWithValue("@Name", ((object)constructionSiteSearchObject.Search_Name) != null ? "%" + constructionSiteSearchObject.Search_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@City", ((object)constructionSiteSearchObject.Search_City) != null ? "%" + constructionSiteSearchObject.Search_City + "%" : ""); selectCommand.Parameters.AddWithValue("@InternalCode", ((object)constructionSiteSearchObject.Search_InternalCode) != null ? "%" + constructionSiteSearchObject.Search_InternalCode + "%" : ""); selectCommand.Parameters.AddWithValue("@BusinessPartnerName", ((object)constructionSiteSearchObject.Search_BusinessPartnerName) != null ? "%" + constructionSiteSearchObject.Search_BusinessPartnerName + "%" : ""); 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.ConstructionSites = new List <ConstructionSiteViewModel>(); return(response); } db.Close(); } response.Success = true; response.ConstructionSites = ConstructionSites; return(response); }