public static PhysicalPersonItem ConvertToPhysicalPersonItem(this PhysicalPersonItemViewModel physicalPersonItemViewModel) { PhysicalPersonItem physicalPersonItem = new PhysicalPersonItem() { Id = physicalPersonItemViewModel.Id, Identifier = physicalPersonItemViewModel.Identifier, PhysicalPersonId = physicalPersonItemViewModel.PhysicalPerson?.Id ?? null, FamilyMemberId = physicalPersonItemViewModel.FamilyMember?.Id ?? null, Name = physicalPersonItemViewModel.Name, DateOfBirth = (DateTime)physicalPersonItemViewModel.DateOfBirth, EmbassyDate = physicalPersonItemViewModel.EmbassyDate, ItemStatus = physicalPersonItemViewModel.ItemStatus, CreatedById = physicalPersonItemViewModel.CreatedBy?.Id ?? null, CompanyId = physicalPersonItemViewModel.Company?.Id ?? null, CreatedAt = physicalPersonItemViewModel.CreatedAt, UpdatedAt = physicalPersonItemViewModel.UpdatedAt }; return(physicalPersonItem); }
public static List <PhysicalPersonProfessionViewModel> ConvertToPhysicalPersonProfessionViewModelList(this IEnumerable <PhysicalPersonProfession> PhysicalPersonItems) { List <PhysicalPersonProfessionViewModel> PhysicalPersonItemViewModels = new List <PhysicalPersonProfessionViewModel>(); foreach (PhysicalPersonProfession PhysicalPersonItem in PhysicalPersonItems) { PhysicalPersonItemViewModels.Add(PhysicalPersonItem.ConvertToPhysicalPersonProfessionViewModel()); } return(PhysicalPersonItemViewModels); }
public PhysicalPersonItem Delete(Guid identifier) { PhysicalPersonItem dbEntry = context.PhysicalPersonItems .Union(context.ChangeTracker.Entries() .Where(x => x.State == EntityState.Added && x.Entity.GetType() == typeof(PhysicalPersonItem)) .Select(x => x.Entity as PhysicalPersonItem)) .FirstOrDefault(x => x.Identifier == identifier); if (dbEntry != null) { dbEntry.Active = false; dbEntry.UpdatedAt = DateTime.Now; } return(dbEntry); }
public PhysicalPersonItem Create(PhysicalPersonItem PhysicalPersonItem) { if (context.PhysicalPersonItems.Where(x => x.Identifier != null && x.Identifier == PhysicalPersonItem.Identifier).Count() == 0) { PhysicalPersonItem.Id = 0; PhysicalPersonItem.Active = true; PhysicalPersonItem.UpdatedAt = DateTime.Now; PhysicalPersonItem.CreatedAt = DateTime.Now; context.PhysicalPersonItems.Add(PhysicalPersonItem); return(PhysicalPersonItem); } else { // Load item that will be updated PhysicalPersonItem dbEntry = context.PhysicalPersonItems .FirstOrDefault(x => x.Identifier == PhysicalPersonItem.Identifier && x.Active == true); if (dbEntry != null) { dbEntry.FamilyMemberId = PhysicalPersonItem.FamilyMemberId ?? null; dbEntry.CompanyId = PhysicalPersonItem.CompanyId ?? null; dbEntry.CreatedById = PhysicalPersonItem.CreatedById ?? null; // Set properties dbEntry.Name = PhysicalPersonItem.Name; dbEntry.DateOfBirth = PhysicalPersonItem.DateOfBirth; dbEntry.EmbassyDate = PhysicalPersonItem.EmbassyDate; dbEntry.ItemStatus = PhysicalPersonItem.ItemStatus; // Set timestamp dbEntry.UpdatedAt = DateTime.Now; } return(dbEntry); } }
public List <PhysicalPersonItem> GetPhysicalPersonItems(int companyId) { List <PhysicalPersonItem> PhysicalPersonItems = new List <PhysicalPersonItem>(); string queryString = "SELECT PhysicalPersonItemId, PhysicalPersonItemIdentifier, " + "PhysicalPersonId, PhysicalPersonIdentifier, PhysicalPersonCode, PhysicalPersonName, " + "FamilyMemberId, FamilyMemberIdentifier, FamilyMemberCode, FamilyMemberName, " + "Name, DateOfBirth, EmbassyDate, ItemStatus, " + "Active, UpdatedAt, CreatedById, CreatedByFirstName, CreatedByLastName, " + "CompanyId, CompanyName " + "FROM vPhysicalPersonItems " + "WHERE CompanyId = @CompanyId;"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = connection.CreateCommand(); command.CommandText = queryString; command.Parameters.Add(new SqlParameter("@CompanyId", companyId)); connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { PhysicalPersonItem physicalPersonItem; while (reader.Read()) { physicalPersonItem = new PhysicalPersonItem(); physicalPersonItem.Id = Int32.Parse(reader["PhysicalPersonItemId"].ToString()); physicalPersonItem.Identifier = Guid.Parse(reader["PhysicalPersonItemIdentifier"].ToString()); if (reader["PhysicalPersonId"] != DBNull.Value) { physicalPersonItem.PhysicalPerson = new PhysicalPerson(); physicalPersonItem.PhysicalPersonId = Int32.Parse(reader["PhysicalPersonId"].ToString()); physicalPersonItem.PhysicalPerson.Id = Int32.Parse(reader["PhysicalPersonId"].ToString()); physicalPersonItem.PhysicalPerson.Identifier = Guid.Parse(reader["PhysicalPersonIdentifier"].ToString()); physicalPersonItem.PhysicalPerson.Code = reader["PhysicalPersonCode"].ToString(); physicalPersonItem.PhysicalPerson.Name = reader["PhysicalPersonName"].ToString(); } if (reader["FamilyMemberId"] != DBNull.Value) { physicalPersonItem.FamilyMember = new FamilyMember(); physicalPersonItem.FamilyMemberId = Int32.Parse(reader["FamilyMemberId"].ToString()); physicalPersonItem.FamilyMember.Id = Int32.Parse(reader["FamilyMemberId"].ToString()); physicalPersonItem.FamilyMember.Identifier = Guid.Parse(reader["FamilyMemberIdentifier"].ToString()); physicalPersonItem.FamilyMember.Code = reader["FamilyMemberCode"].ToString(); physicalPersonItem.FamilyMember.Name = reader["FamilyMemberName"].ToString(); } if (reader["Name"] != DBNull.Value) { physicalPersonItem.Name = reader["Name"].ToString(); } if (reader["DateOfBirth"] != DBNull.Value) { physicalPersonItem.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString()); } if (reader["EmbassyDate"] != DBNull.Value) { physicalPersonItem.EmbassyDate = DateTime.Parse(reader["EmbassyDate"].ToString()); } if (reader["ItemStatus"] != DBNull.Value) { physicalPersonItem.ItemStatus = Int32.Parse(reader["ItemStatus"].ToString()); } physicalPersonItem.Active = bool.Parse(reader["Active"].ToString()); physicalPersonItem.UpdatedAt = DateTime.Parse(reader["UpdatedAt"].ToString()); if (reader["CreatedById"] != DBNull.Value) { physicalPersonItem.CreatedBy = new User(); physicalPersonItem.CreatedById = Int32.Parse(reader["CreatedById"].ToString()); physicalPersonItem.CreatedBy.Id = Int32.Parse(reader["CreatedById"].ToString()); physicalPersonItem.CreatedBy.FirstName = reader["CreatedByFirstName"]?.ToString(); physicalPersonItem.CreatedBy.LastName = reader["CreatedByLastName"]?.ToString(); } if (reader["CompanyId"] != DBNull.Value) { physicalPersonItem.Company = new Company(); physicalPersonItem.CompanyId = Int32.Parse(reader["CompanyId"].ToString()); physicalPersonItem.Company.Id = Int32.Parse(reader["CompanyId"].ToString()); physicalPersonItem.Company.Name = reader["CompanyName"].ToString(); } PhysicalPersonItems.Add(physicalPersonItem); } } } return(PhysicalPersonItems); //List<PhysicalPersonItem> PhysicalPersonItems = context.PhysicalPersonItems // .Include(x => x.PhysicalPerson) // .Include(x => x.FamilyMember) // .Include(x => x.Company) // .Include(x => x.CreatedBy) // .Where(x => x.Active == true && x.CompanyId == companyId) // .AsNoTracking() // .ToList(); //return PhysicalPersonItems; }
public static PhysicalPersonItemViewModel ConvertToPhysicalPersonItemViewModelLite(this PhysicalPersonItem physicalPersonItem) { PhysicalPersonItemViewModel physicalPersonItemViewModel = new PhysicalPersonItemViewModel() { Id = physicalPersonItem.Id, Identifier = physicalPersonItem.Identifier, Name = physicalPersonItem.Name, DateOfBirth = physicalPersonItem.DateOfBirth, EmbassyDate = physicalPersonItem.EmbassyDate, ItemStatus = physicalPersonItem.ItemStatus, IsActive = physicalPersonItem.Active, UpdatedAt = physicalPersonItem.UpdatedAt, CreatedAt = physicalPersonItem.CreatedAt }; return(physicalPersonItemViewModel); }
public static PhysicalPersonItemViewModel ConvertToPhysicalPersonItemViewModel(this PhysicalPersonItem physicalPersonItem) { PhysicalPersonItemViewModel physicalPersonItemViewModel = new PhysicalPersonItemViewModel() { Id = physicalPersonItem.Id, Identifier = physicalPersonItem.Identifier, PhysicalPerson = physicalPersonItem.PhysicalPerson?.ConvertToPhysicalPersonViewModelLite(), FamilyMember = physicalPersonItem.FamilyMember?.ConvertToFamilyMemberViewModelLite(), Name = physicalPersonItem.Name, DateOfBirth = physicalPersonItem.DateOfBirth, EmbassyDate = physicalPersonItem.EmbassyDate, ItemStatus = physicalPersonItem.ItemStatus, IsActive = physicalPersonItem.Active, CreatedBy = physicalPersonItem.CreatedBy?.ConvertToUserViewModelLite(), Company = physicalPersonItem.Company?.ConvertToCompanyViewModelLite(), UpdatedAt = physicalPersonItem.UpdatedAt, CreatedAt = physicalPersonItem.CreatedAt }; return(physicalPersonItemViewModel); }