public ConstructionSiteCalculationListResponse GetConstructionSiteCalculationsNewerThen(int companyId, DateTime?lastUpdateTime) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); try { if (lastUpdateTime != null) { response.ConstructionSiteCalculations = unitOfWork.GetConstructionSiteCalculationRepository() .GetConstructionSiteCalculationsNewerThen(companyId, (DateTime)lastUpdateTime) .ConvertToConstructionSiteCalculationViewModelList(); } else { response.ConstructionSiteCalculations = unitOfWork.GetConstructionSiteCalculationRepository() .GetConstructionSiteCalculations(companyId) .ConvertToConstructionSiteCalculationViewModelList(); } response.Success = true; } catch (Exception ex) { response.ConstructionSiteCalculations = new List <ConstructionSiteCalculationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ConstructionSiteCalculationListResponse Sync(SyncConstructionSiteCalculationRequest request) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); try { response.ConstructionSiteCalculations = new List <ConstructionSiteCalculationViewModel>(); if (request.LastUpdatedAt != null) { response.ConstructionSiteCalculations.AddRange(unitOfWork.GetConstructionSiteCalculationRepository() .GetConstructionSiteCalculationsNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToConstructionSiteCalculationViewModelList() ?? new List <ConstructionSiteCalculationViewModel>()); } else { response.ConstructionSiteCalculations.AddRange(unitOfWork.GetConstructionSiteCalculationRepository() .GetConstructionSiteCalculations(request.CompanyId) ?.ConvertToConstructionSiteCalculationViewModelList() ?? new List <ConstructionSiteCalculationViewModel>()); } unitOfWork.Save(); response.Success = true; } catch (Exception ex) { response.ConstructionSiteCalculations = new List <ConstructionSiteCalculationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ConstructionSiteCalculationListResponse Sync(SyncConstructionSiteCalculationRequest request) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); try { response = WpfApiHandler.SendToApi <SyncConstructionSiteCalculationRequest, ConstructionSiteCalculationViewModel, ConstructionSiteCalculationListResponse>(request, "Sync"); } catch (Exception ex) { response.ConstructionSiteCalculations = new List <ConstructionSiteCalculationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ConstructionSiteCalculationListResponse GetConstructionSiteCalculations(int companyId) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("CompanyID", companyId.ToString()); response = WpfApiHandler.GetFromApi <List <ConstructionSiteCalculationViewModel>, ConstructionSiteCalculationListResponse>("GetConstructionSiteCalculations", parameters); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncConstructionSiteCalculationRequest request) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); try { response = this.ConstructionSiteCalculationService.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 JsonResult GetConstructionSiteCalculationsNewerThen(int CompanyId, DateTime?lastUpdateTime) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); try { response = ConstructionSiteCalculationService.GetConstructionSiteCalculationsNewerThen(CompanyId, lastUpdateTime); } 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 ConstructionSiteCalculationListResponse GetConstructionSiteCalculationsNewerThen(int companyId, DateTime?lastUpdateTime) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); try { response = WpfApiHandler.GetFromApi <List <ConstructionSiteCalculationViewModel>, ConstructionSiteCalculationListResponse>("GetConstructionSiteCalculationsNewerThen", new Dictionary <string, string>() { { "CompanyId", companyId.ToString() }, { "LastUpdateTime", lastUpdateTime.ToString() } }); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public ConstructionSiteCalculationListResponse GetConstructionSiteCalculations(int companyId) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); try { response.ConstructionSiteCalculations = unitOfWork.GetConstructionSiteCalculationRepository() .GetConstructionSiteCalculations(companyId) .ConvertToConstructionSiteCalculationViewModelList(); response.Success = true; } catch (Exception ex) { response.ConstructionSiteCalculations = new List <ConstructionSiteCalculationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public ConstructionSiteCalculationListResponse GetConstructionSiteCalculationsByConstructionSite(int companyId, Guid ConstructionSiteIdentifier) { ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); List <ConstructionSiteCalculationViewModel> ConstructionSiteCalculations = new List <ConstructionSiteCalculationViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM ConstructionSiteCalculations " + "WHERE ConstructionSiteIdentifier = @ConstructionSiteIdentifier " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC;", db); selectCommand.Parameters.AddWithValue("@ConstructionSiteIdentifier", ConstructionSiteIdentifier); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { ConstructionSiteCalculationViewModel dbEntry = Read(query); ConstructionSiteCalculations.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.ConstructionSiteCalculations = new List <ConstructionSiteCalculationViewModel>(); return(response); } db.Close(); } response.Success = true; response.ConstructionSiteCalculations = ConstructionSiteCalculations; return(response); }
//public ConstructionSiteCalculationListResponse GetUnSyncedItems(int companyId) //{ // ConstructionSiteCalculationListResponse response = new ConstructionSiteCalculationListResponse(); // List<ConstructionSiteCalculationViewModel> viewModels = new List<ConstructionSiteCalculationViewModel>(); // using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) // { // db.Open(); // try // { // SqliteCommand selectCommand = new SqliteCommand( // SqlCommandSelectPart + // "FROM ConstructionSiteCalculations " + // "WHERE CompanyId = @CompanyId AND IsSynced = 0 " + // "ORDER BY Id DESC;", db); // selectCommand.Parameters.AddWithValue("@CompanyId", companyId); // SqliteDataReader query = selectCommand.ExecuteReader(); // while (query.Read()) // { // int counter = 0; // ConstructionSiteCalculationViewModel dbEntry = new ConstructionSiteCalculationViewModel(); // dbEntry.Id = SQLiteHelper.GetInt(query, ref counter); // dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter); // dbEntry.ConstructionSite = SQLiteHelper.GetConstructionSite(query, ref counter); // dbEntry.NumOfEmployees = SQLiteHelper.GetInt(query, ref counter); // dbEntry.EmployeePrice = SQLiteHelper.GetDecimal(query, ref counter); // dbEntry.NumOfMonths = SQLiteHelper.GetInt(query, ref counter); // dbEntry.OldValue = SQLiteHelper.GetDecimal(query, ref counter); // dbEntry.NewValue = SQLiteHelper.GetDecimal(query, ref counter); // dbEntry.ValueDifference = SQLiteHelper.GetDecimal(query, ref counter); // dbEntry.PlusMinus = SQLiteHelper.GetString(query, ref counter); // dbEntry.IsSynced = SQLiteHelper.GetBoolean(query, ref counter); // dbEntry.UpdatedAt = SQLiteHelper.GetDateTime(query, ref counter); // dbEntry.CreatedBy = SQLiteHelper.GetCreatedBy(query, ref counter); // dbEntry.Company = SQLiteHelper.GetCompany(query, ref counter); // viewModels.Add(dbEntry); // } // } // catch (SqliteException error) // { // MainWindow.ErrorMessage = error.Message; // response.Success = false; // response.Message = error.Message; // response.ConstructionSiteCalculations = new List<ConstructionSiteCalculationViewModel>(); // return response; // } // db.Close(); // } // response.Success = true; // response.ConstructionSiteCalculations = viewModels; // return response; //} #endregion #region Sync public void Sync(IConstructionSiteCalculationService ConstructionSiteCalculationService, Action <int, int> callback = null) { try { SyncConstructionSiteCalculationRequest request = new SyncConstructionSiteCalculationRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; ConstructionSiteCalculationListResponse response = ConstructionSiteCalculationService.Sync(request); if (response.Success) { toSync = response?.ConstructionSiteCalculations?.Count ?? 0; List <ConstructionSiteCalculationViewModel> items = response.ConstructionSiteCalculations; using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM ConstructionSiteCalculations 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; } }