public PhysicalPersonAttachmentListResponse CreateList(List <PhysicalPersonAttachmentViewModel> PhysicalPersonAttachment) { PhysicalPersonAttachmentListResponse response = new PhysicalPersonAttachmentListResponse(); try { response.PhysicalPersonAttachments = new List <PhysicalPersonAttachmentViewModel>(); foreach (var item in PhysicalPersonAttachment) { var attachment = unitOfWork.GetPhysicalPersonAttachmentRepository().Create(item.ConvertToPhysicalPersonAttachment()) .ConvertToPhysicalPersonAttachmentViewModel(); response.PhysicalPersonAttachments.Add(attachment); } unitOfWork.Save(); response.Success = true; } catch (Exception ex) { response = new PhysicalPersonAttachmentListResponse(); response.Success = false; response.Message = ex.Message; } return(response); }
public PhysicalPersonAttachmentListResponse Sync(SyncPhysicalPersonAttachmentRequest request) { PhysicalPersonAttachmentListResponse response = new PhysicalPersonAttachmentListResponse(); try { if (request.LastUpdatedAt != null) { response.PhysicalPersonAttachments = unitOfWork.GetPhysicalPersonAttachmentRepository() .GetPhysicalPersonAttachmentsNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) .ConvertToPhysicalPersonAttachmentViewModelList(); } else { response.PhysicalPersonAttachments = unitOfWork.GetPhysicalPersonAttachmentRepository() .GetPhysicalPersonAttachments(request.CompanyId) .ConvertToPhysicalPersonAttachmentViewModelList(); } response.Success = true; } catch (Exception ex) { response = new PhysicalPersonAttachmentListResponse(); response.PhysicalPersonAttachments = new List <PhysicalPersonAttachmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public PhysicalPersonAttachmentListResponse GetPhysicalPersonAttachmentsByPhysicalPerson(int companyId, Guid PhysicalPersonIdentifier) { PhysicalPersonAttachmentListResponse response = new PhysicalPersonAttachmentListResponse(); List <PhysicalPersonAttachmentViewModel> PhysicalPersonAttachments = new List <PhysicalPersonAttachmentViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + @"FROM PhysicalPersonAttachments att WHERE (@PhysicalPersonIdentifier IS NULL OR @PhysicalPersonIdentifier = '' OR att.PhysicalPersonIdentifier LIKE @PhysicalPersonIdentifier) AND att.CompanyId = @CompanyId ORDER BY att.Id ASC ", db); selectCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", ((object)PhysicalPersonIdentifier) ?? DBNull.Value); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { PhysicalPersonAttachmentViewModel dbEntry = Read(query); PhysicalPersonAttachments.Add(dbEntry); } response.PhysicalPersonAttachments = PhysicalPersonAttachments; selectCommand = new SqliteCommand( @"SELECT Count(*) FROM PhysicalPersonAttachments att WHERE(@PhysicalPersonIdentifier IS NULL OR @PhysicalPersonIdentifier = '' OR att.PhysicalPersonIdentifier LIKE @PhysicalPersonIdentifier) AND att.CompanyId = @CompanyId ORDER BY att.IsSynced, att.Id DESC", db); selectCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", ((object)PhysicalPersonIdentifier) ?? 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.PhysicalPersonAttachments = new List <PhysicalPersonAttachmentViewModel>(); return(response); } db.Close(); } response.Success = true; response.PhysicalPersonAttachments = PhysicalPersonAttachments; return(response); }
public PhysicalPersonAttachmentListResponse CreateList(List <PhysicalPersonAttachmentViewModel> PhysicalPersonAttachment) { PhysicalPersonAttachmentListResponse response = new PhysicalPersonAttachmentListResponse(); try { response = WpfApiHandler.SendToApi <List <PhysicalPersonAttachmentViewModel>, PhysicalPersonAttachmentListResponse>(PhysicalPersonAttachment, "CreateList"); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public PhysicalPersonAttachmentListResponse Sync(SyncPhysicalPersonAttachmentRequest request) { PhysicalPersonAttachmentListResponse response = new PhysicalPersonAttachmentListResponse(); try { response = WpfApiHandler.SendToApi <SyncPhysicalPersonAttachmentRequest, PhysicalPersonAttachmentViewModel, PhysicalPersonAttachmentListResponse>(request, "Sync"); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public PhysicalPersonAttachmentListResponse GetPhysicalPersonAttachments(int companyId) { PhysicalPersonAttachmentListResponse response = new PhysicalPersonAttachmentListResponse(); try { response = WpfApiHandler.GetFromApi <PhysicalPersonAttachmentViewModel, PhysicalPersonAttachmentListResponse>("GetPhysicalPersonAttachments", new Dictionary <string, string>() { { "CompanyId", companyId.ToString() } }); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncPhysicalPersonAttachmentRequest request) { PhysicalPersonAttachmentListResponse response = new PhysicalPersonAttachmentListResponse(); try { response = this.PhysicalPersonAttachmentService.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 PhysicalPersonAttachmentListResponse GetPhysicalPersonAttachments(int companyId) { PhysicalPersonAttachmentListResponse response = new PhysicalPersonAttachmentListResponse(); try { response.PhysicalPersonAttachments = unitOfWork.GetPhysicalPersonAttachmentRepository() .GetPhysicalPersonAttachments(companyId) .ConvertToPhysicalPersonAttachmentViewModelList(); response.Success = true; } catch (Exception ex) { response = new PhysicalPersonAttachmentListResponse(); response.PhysicalPersonAttachments = new List <PhysicalPersonAttachmentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public void Sync(IPhysicalPersonAttachmentService PhysicalPersonAttachmentService, Action <int, int> callback = null) { try { SyncPhysicalPersonAttachmentRequest request = new SyncPhysicalPersonAttachmentRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; PhysicalPersonAttachmentListResponse response = PhysicalPersonAttachmentService.Sync(request); if (response.Success) { toSync = response?.PhysicalPersonAttachments?.Count ?? 0; List <PhysicalPersonAttachmentViewModel> PhysicalPersonsFromDB = response.PhysicalPersonAttachments; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM PhysicalPersonAttachments WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var PhysicalPerson in PhysicalPersonsFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", PhysicalPerson.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (PhysicalPerson.IsActive) { PhysicalPerson.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, PhysicalPerson); 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; } }