public EmployeeNoteListResponse Sync(SyncEmployeeNoteRequest request) { EmployeeNoteListResponse response = new EmployeeNoteListResponse(); try { response.EmployeeNotes = new List <EmployeeNoteViewModel>(); if (request.LastUpdatedAt != null) { response.EmployeeNotes.AddRange(unitOfWork.GetEmployeeNoteRepository() .GetEmployeeNotesNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToEmployeeNoteViewModelList() ?? new List <EmployeeNoteViewModel>()); } else { response.EmployeeNotes.AddRange(unitOfWork.GetEmployeeNoteRepository() .GetEmployeeNotes(request.CompanyId) ?.ConvertToEmployeeNoteViewModelList() ?? new List <EmployeeNoteViewModel>()); } response.Success = true; } catch (Exception ex) { response.EmployeeNotes = new List <EmployeeNoteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public EmployeeNoteListResponse Sync(SyncEmployeeNoteRequest request) { EmployeeNoteListResponse response = new EmployeeNoteListResponse(); try { response = WpfApiHandler.SendToApi <SyncEmployeeNoteRequest, EmployeeNoteViewModel, EmployeeNoteListResponse>(request, "Sync"); } catch (Exception ex) { response.EmployeeNotes = new List <EmployeeNoteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncEmployeeNoteRequest request) { EmployeeNoteListResponse response = new EmployeeNoteListResponse(); try { response = this.EmployeeNoteService.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 EmployeeNoteListResponse GetEmployeeNotesByEmployee(int companyId, Guid EmployeeIdentifier) { EmployeeNoteListResponse response = new EmployeeNoteListResponse(); List <EmployeeNoteViewModel> EmployeeNotes = new List <EmployeeNoteViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM EmployeeNotes " + "WHERE EmployeeIdentifier = @EmployeeIdentifier " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC;", db); selectCommand.Parameters.AddWithValue("@EmployeeIdentifier", EmployeeIdentifier); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { EmployeeNoteViewModel dbEntry = Read(query); EmployeeNotes.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.EmployeeNotes = new List <EmployeeNoteViewModel>(); return(response); } db.Close(); } response.Success = true; response.EmployeeNotes = EmployeeNotes; return(response); }
public void Sync(IEmployeeNoteService EmployeeNoteService, Action <int, int> callback = null) { try { SyncEmployeeNoteRequest request = new SyncEmployeeNoteRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; EmployeeNoteListResponse response = EmployeeNoteService.Sync(request); if (response.Success) { toSync = response?.EmployeeNotes?.Count ?? 0; List <EmployeeNoteViewModel> employeeNotesFromDB = response.EmployeeNotes; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM EmployeeNotes WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var employeeNote in employeeNotesFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", employeeNote.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (employeeNote.IsActive) { employeeNote.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, employeeNote); 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; } }