public EmployeeAttachmentListResponse CreateList(List <EmployeeAttachmentViewModel> EmployeeAttachment) { EmployeeAttachmentListResponse response = new EmployeeAttachmentListResponse(); try { response.EmployeeAttachments = new List <EmployeeAttachmentViewModel>(); foreach (var item in EmployeeAttachment) { var attachment = unitOfWork.GetEmployeeAttachmentRepository().Create(item.ConvertToEmployeeAttachment()) .ConvertToEmployeeAttachmentViewModel(); response.EmployeeAttachments.Add(attachment); } unitOfWork.Save(); response.Success = true; } catch (Exception ex) { response = new EmployeeAttachmentListResponse(); response.Success = false; response.Message = ex.Message; } return(response); }
public EmployeeAttachmentListResponse GetEmployeeAttachmentsByEmployee(int companyId, Guid employeeIdentifier) { EmployeeAttachmentListResponse response = new EmployeeAttachmentListResponse(); List <EmployeeAttachmentViewModel> EmployeeAttachments = new List <EmployeeAttachmentViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + @"FROM EmployeeAttachments att WHERE (@EmployeeIdentifier IS NULL OR @EmployeeIdentifier = '' OR att.EmployeeIdentifier LIKE @EmployeeIdentifier) AND att.CompanyId = @CompanyId ORDER BY att.Id ASC ", db); selectCommand.Parameters.AddWithValue("@EmployeeIdentifier", ((object)employeeIdentifier) ?? DBNull.Value); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { EmployeeAttachmentViewModel dbEntry = Read(query); EmployeeAttachments.Add(dbEntry); } response.EmployeeAttachments = EmployeeAttachments; selectCommand = new SqliteCommand( @"SELECT Count(*) FROM EmployeeAttachments att WHERE(@EmployeeIdentifier IS NULL OR @EmployeeIdentifier = '' OR att.EmployeeIdentifier LIKE @EmployeeIdentifier) AND att.CompanyId = @CompanyId ORDER BY att.IsSynced, att.Id DESC", db); selectCommand.Parameters.AddWithValue("@EmployeeIdentifier", ((object)employeeIdentifier) ?? DBNull.Value); 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.EmployeeAttachments = new List <EmployeeAttachmentViewModel>(); return(response); } db.Close(); } response.Success = true; response.EmployeeAttachments = EmployeeAttachments; return(response); }
public EmployeeAttachmentListResponse Sync(SyncEmployeeAttachmentRequest request) { EmployeeAttachmentListResponse response = new EmployeeAttachmentListResponse(); try { if (request.LastUpdatedAt != null) { response.EmployeeAttachments = unitOfWork.GetEmployeeAttachmentRepository() .GetEmployeeAttachmentsNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) .ConvertToEmployeeAttachmentViewModelList(); } else { response.EmployeeAttachments = unitOfWork.GetEmployeeAttachmentRepository() .GetEmployeeAttachments(request.CompanyId) .ConvertToEmployeeAttachmentViewModelList(); } response.Success = true; } catch (Exception ex) { response = new EmployeeAttachmentListResponse(); response.EmployeeAttachments = new List <EmployeeAttachmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public EmployeeAttachmentListResponse CreateList(List <EmployeeAttachmentViewModel> EmployeeAttachment) { EmployeeAttachmentListResponse response = new EmployeeAttachmentListResponse(); try { response = WpfApiHandler.SendToApi <List <EmployeeAttachmentViewModel>, EmployeeAttachmentListResponse>(EmployeeAttachment, "CreateList"); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public EmployeeAttachmentListResponse Sync(SyncEmployeeAttachmentRequest request) { EmployeeAttachmentListResponse response = new EmployeeAttachmentListResponse(); try { response = WpfApiHandler.SendToApi <SyncEmployeeAttachmentRequest, EmployeeAttachmentViewModel, EmployeeAttachmentListResponse>(request, "Sync"); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public EmployeeAttachmentListResponse GetEmployeeAttachments(int companyId) { EmployeeAttachmentListResponse response = new EmployeeAttachmentListResponse(); try { response = WpfApiHandler.GetFromApi <EmployeeAttachmentViewModel, EmployeeAttachmentListResponse>("GetEmployeeAttachments", new Dictionary <string, string>() { { "CompanyId", companyId.ToString() } }); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncEmployeeAttachmentRequest request) { EmployeeAttachmentListResponse response = new EmployeeAttachmentListResponse(); try { response = this.employeeAttachmentService.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 EmployeeAttachmentListResponse GetEmployeeAttachments(int companyId) { EmployeeAttachmentListResponse response = new EmployeeAttachmentListResponse(); try { response.EmployeeAttachments = unitOfWork.GetEmployeeAttachmentRepository() .GetEmployeeAttachments(companyId) .ConvertToEmployeeAttachmentViewModelList(); response.Success = true; } catch (Exception ex) { response = new EmployeeAttachmentListResponse(); response.EmployeeAttachments = new List <EmployeeAttachmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public void Sync(IEmployeeAttachmentService EmployeeAttachmentService, Action <int, int> callback = null) { try { SyncEmployeeAttachmentRequest request = new SyncEmployeeAttachmentRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; EmployeeAttachmentListResponse response = EmployeeAttachmentService.Sync(request); if (response.Success) { toSync = response?.EmployeeAttachments?.Count ?? 0; List <EmployeeAttachmentViewModel> employeesFromDB = response.EmployeeAttachments; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM EmployeeAttachments WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var employee in employeesFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", employee.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (employee.IsActive) { employee.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, employee); 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; } }