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 EmployeeResponse Create(EmployeeAttachmentViewModel attachment) { EmployeeResponse response = new EmployeeResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; try { insertCommand = AddCreateParameters(insertCommand, attachment); insertCommand.ExecuteNonQuery(); } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; return(response); } db.Close(); response.Success = true; return(response); } }
public EmployeeAttachmentResponse Create(EmployeeAttachmentViewModel EmployeeAttachment) { EmployeeAttachmentResponse response = new EmployeeAttachmentResponse(); try { response = WpfApiHandler.SendToApi <EmployeeAttachmentViewModel, EmployeeAttachmentResponse>(EmployeeAttachment, "Create"); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
private static EmployeeAttachmentViewModel Read(SqliteDataReader query) { int counter = 0; EmployeeAttachmentViewModel dbEntry = new EmployeeAttachmentViewModel(); dbEntry.Id = SQLiteHelper.GetInt(query, ref counter); dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter); dbEntry.Code = SQLiteHelper.GetString(query, ref counter); dbEntry.OK = SQLiteHelper.GetBoolean(query, ref counter); dbEntry.Employee = SQLiteHelper.GetEmployee(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); return(dbEntry); }
public static EmployeeAttachmentViewModel ConvertToEmployeeAttachmentViewModelLite(this EmployeeAttachment employeeAttachment) { EmployeeAttachmentViewModel EmployeeAttachmentViewModel = new EmployeeAttachmentViewModel() { Id = employeeAttachment.Id, Identifier = employeeAttachment.Identifier, Code = employeeAttachment.Code, OK = employeeAttachment.OK, IsActive = employeeAttachment.Active, UpdatedAt = employeeAttachment.UpdatedAt, CreatedAt = employeeAttachment.CreatedAt }; return(EmployeeAttachmentViewModel); }
public JsonResult Create([FromBody] EmployeeAttachmentViewModel c) { EmployeeAttachmentResponse response; try { response = this.employeeAttachmentService.Create(c); } catch (Exception ex) { response = null; Console.WriteLine(ex.Message); } return(Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented })); }
public EmployeeAttachmentResponse Create(EmployeeAttachmentViewModel EmployeeAttachment) { EmployeeAttachmentResponse response = new EmployeeAttachmentResponse(); try { response.EmployeeAttachment = unitOfWork.GetEmployeeAttachmentRepository().Create(EmployeeAttachment.ConvertToEmployeeAttachment()) .ConvertToEmployeeAttachmentViewModel(); unitOfWork.Save(); response.Success = true; } catch (Exception ex) { response = new EmployeeAttachmentResponse(); response.Success = false; response.Message = ex.Message; } return(response); }
private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, EmployeeAttachmentViewModel EmployeeAttachment) { insertCommand.Parameters.AddWithValue("@ServerId", EmployeeAttachment.Id); insertCommand.Parameters.AddWithValue("@Identifier", EmployeeAttachment.Identifier); insertCommand.Parameters.AddWithValue("@Code", ((object)EmployeeAttachment.Code) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@OK", ((object)EmployeeAttachment.OK) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@EmployeeId", ((object)EmployeeAttachment.Employee?.Id) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@EmployeeIdentifier", ((object)EmployeeAttachment.Employee?.Identifier) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@EmployeeCode", ((object)EmployeeAttachment.Employee?.Code) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@EmployeeName", ((object)EmployeeAttachment.Employee?.Name) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@EmployeeInternalCode", ((object)EmployeeAttachment.Employee?.EmployeeCode) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@IsSynced", EmployeeAttachment.IsSynced); insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)EmployeeAttachment.UpdatedAt) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@CreatedById", MainWindow.CurrentUser.Id); insertCommand.Parameters.AddWithValue("@CreatedByName", MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName); insertCommand.Parameters.AddWithValue("@CompanyId", MainWindow.CurrentCompany.Id); insertCommand.Parameters.AddWithValue("@CompanyName", MainWindow.CurrentCompany.CompanyName); return(insertCommand); }
public static EmployeeAttachment ConvertToEmployeeAttachment(this EmployeeAttachmentViewModel employeeAttachmentViewModel) { EmployeeAttachment EmployeeAttachment = new EmployeeAttachment() { Id = employeeAttachmentViewModel.Id, Identifier = employeeAttachmentViewModel.Identifier, Code = employeeAttachmentViewModel.Code, EmployeeId = employeeAttachmentViewModel.Employee?.Id ?? null, OK = employeeAttachmentViewModel.OK, Active = employeeAttachmentViewModel.IsActive, CreatedById = employeeAttachmentViewModel.CreatedBy?.Id ?? null, CompanyId = employeeAttachmentViewModel.Company?.Id ?? null, CreatedAt = employeeAttachmentViewModel.CreatedAt, UpdatedAt = employeeAttachmentViewModel.UpdatedAt }; return(EmployeeAttachment); }
public static EmployeeAttachmentViewModel ConvertToEmployeeAttachmentViewModel(this EmployeeAttachment employeeAttachment) { EmployeeAttachmentViewModel EmployeeAttachmentViewModel = new EmployeeAttachmentViewModel() { Id = employeeAttachment.Id, Identifier = employeeAttachment.Identifier, Code = employeeAttachment.Code, Employee = employeeAttachment.Employee?.ConvertToEmployeeViewModelLite(), OK = employeeAttachment.OK, IsActive = employeeAttachment.Active, CreatedBy = employeeAttachment.CreatedBy?.ConvertToUserViewModelLite(), Company = employeeAttachment.Company?.ConvertToCompanyViewModelLite(), UpdatedAt = employeeAttachment.UpdatedAt, CreatedAt = employeeAttachment.CreatedAt }; return(EmployeeAttachmentViewModel); }