public static PhysicalPersonDocument ConvertToPhysicalPersonDocument(this PhysicalPersonDocumentViewModel employeeDocumentViewModel) { PhysicalPersonDocument PhysicalPersonDocument = new PhysicalPersonDocument() { Id = employeeDocumentViewModel.Id, Identifier = employeeDocumentViewModel.Identifier, PhysicalPersonId = employeeDocumentViewModel.PhysicalPerson?.Id ?? null, Name = employeeDocumentViewModel.Name, CreateDate = employeeDocumentViewModel.CreateDate, Path = employeeDocumentViewModel.Path, ItemStatus = employeeDocumentViewModel.ItemStatus, Active = employeeDocumentViewModel.IsActive, CreatedById = employeeDocumentViewModel.CreatedBy?.Id ?? null, CompanyId = employeeDocumentViewModel.Company?.Id ?? null, CreatedAt = employeeDocumentViewModel.CreatedAt, UpdatedAt = employeeDocumentViewModel.UpdatedAt }; return(PhysicalPersonDocument); }
private static PhysicalPersonDocument Read(SqlDataReader reader) { PhysicalPersonDocument physicalPersonDocument = new PhysicalPersonDocument(); physicalPersonDocument.Id = Int32.Parse(reader["PhysicalPersonDocumentId"].ToString()); physicalPersonDocument.Identifier = Guid.Parse(reader["PhysicalPersonDocumentIdentifier"].ToString()); if (reader["PhysicalPersonId"] != DBNull.Value) { physicalPersonDocument.PhysicalPerson = new PhysicalPerson(); physicalPersonDocument.PhysicalPersonId = Int32.Parse(reader["PhysicalPersonId"].ToString()); physicalPersonDocument.PhysicalPerson.Id = Int32.Parse(reader["PhysicalPersonId"].ToString()); physicalPersonDocument.PhysicalPerson.Identifier = Guid.Parse(reader["PhysicalPersonIdentifier"].ToString()); physicalPersonDocument.PhysicalPerson.Code = reader["PhysicalPersonCode"].ToString(); physicalPersonDocument.PhysicalPerson.Name = reader["PhysicalPersonName"].ToString(); } if (reader["Name"] != DBNull.Value) { physicalPersonDocument.Name = reader["Name"].ToString(); } if (reader["CreateDate"] != DBNull.Value) { physicalPersonDocument.CreateDate = DateTime.Parse(reader["CreateDate"].ToString()); } if (reader["Path"] != DBNull.Value) { physicalPersonDocument.Path = reader["Path"].ToString(); } if (reader["ItemStatus"] != DBNull.Value) { physicalPersonDocument.ItemStatus = Int32.Parse(reader["ItemStatus"].ToString()); } physicalPersonDocument.Active = bool.Parse(reader["Active"].ToString()); physicalPersonDocument.UpdatedAt = DateTime.Parse(reader["UpdatedAt"].ToString()); if (reader["CreatedById"] != DBNull.Value) { physicalPersonDocument.CreatedBy = new User(); physicalPersonDocument.CreatedById = Int32.Parse(reader["CreatedById"].ToString()); physicalPersonDocument.CreatedBy.Id = Int32.Parse(reader["CreatedById"].ToString()); physicalPersonDocument.CreatedBy.FirstName = reader["CreatedByFirstName"]?.ToString(); physicalPersonDocument.CreatedBy.LastName = reader["CreatedByLastName"]?.ToString(); } if (reader["CompanyId"] != DBNull.Value) { physicalPersonDocument.Company = new Company(); physicalPersonDocument.CompanyId = Int32.Parse(reader["CompanyId"].ToString()); physicalPersonDocument.Company.Id = Int32.Parse(reader["CompanyId"].ToString()); physicalPersonDocument.Company.Name = reader["CompanyName"].ToString(); } return(physicalPersonDocument); }
public static List <PhysicalPersonDocumentViewModel> ConvertToPhysicalPersonDocumentViewModelList(this IEnumerable <PhysicalPersonDocument> employeeDocuments) { List <PhysicalPersonDocumentViewModel> PhysicalPersonDocumentViewModels = new List <PhysicalPersonDocumentViewModel>(); foreach (PhysicalPersonDocument PhysicalPersonDocument in employeeDocuments) { PhysicalPersonDocumentViewModels.Add(PhysicalPersonDocument.ConvertToPhysicalPersonDocumentViewModel()); } return(PhysicalPersonDocumentViewModels); }
public PhysicalPersonDocument Delete(Guid identifier) { PhysicalPersonDocument dbEntry = context.PhysicalPersonDocuments .Union(context.ChangeTracker.Entries() .Where(x => x.State == EntityState.Added && x.Entity.GetType() == typeof(PhysicalPersonDocument)) .Select(x => x.Entity as PhysicalPersonDocument)) .FirstOrDefault(x => x.Identifier == identifier); if (dbEntry != null) { dbEntry.Active = false; dbEntry.UpdatedAt = DateTime.Now; } return(dbEntry); }
public PhysicalPersonDocument Create(PhysicalPersonDocument physicalPersonDocument) { if (context.PhysicalPersonDocuments.Where(x => x.Identifier != null && x.Identifier == physicalPersonDocument.Identifier).Count() == 0) { physicalPersonDocument.Id = 0; physicalPersonDocument.Active = true; physicalPersonDocument.UpdatedAt = DateTime.Now; physicalPersonDocument.CreatedAt = DateTime.Now; context.PhysicalPersonDocuments.Add(physicalPersonDocument); return(physicalPersonDocument); } else { // Load PhysicalPersonDocument that will be updated PhysicalPersonDocument dbEntry = context.PhysicalPersonDocuments .FirstOrDefault(x => x.Identifier == physicalPersonDocument.Identifier && x.Active == true); if (dbEntry != null) { dbEntry.CompanyId = physicalPersonDocument.CompanyId ?? null; dbEntry.CreatedById = physicalPersonDocument.CreatedById ?? null; // Set properties dbEntry.Name = physicalPersonDocument.Name; dbEntry.CreateDate = physicalPersonDocument.CreateDate; dbEntry.Path = physicalPersonDocument.Path; dbEntry.ItemStatus = physicalPersonDocument.ItemStatus; // Set timestamp dbEntry.UpdatedAt = DateTime.Now; } return(dbEntry); } }
public static PhysicalPersonDocumentViewModel ConvertToPhysicalPersonDocumentViewModelLite(this PhysicalPersonDocument employeeDocument) { PhysicalPersonDocumentViewModel PhysicalPersonDocumentViewModel = new PhysicalPersonDocumentViewModel() { Id = employeeDocument.Id, Identifier = employeeDocument.Identifier, Name = employeeDocument.Name, CreateDate = employeeDocument.CreateDate, Path = employeeDocument.Path, ItemStatus = employeeDocument.ItemStatus, IsActive = employeeDocument.Active, UpdatedAt = employeeDocument.UpdatedAt, CreatedAt = employeeDocument.CreatedAt }; return(PhysicalPersonDocumentViewModel); }