public override Object GetUpdatedCompanyById(int CompanyId) { var company = _context.Companies.Include("ContactInfo") .Include("UserCompanies.User") .Where(p => p.id == CompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault(); BO.UpdateCompany boUpdateCompany = new BO.UpdateCompany(); if (company == null) { return(new BO.ErrorObject { ErrorMessage = "No record found for this company.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } else { boUpdateCompany = ConvertUpdateCompanySignUp <BO.UpdateCompany, Company>(company); } return(boUpdateCompany); }
public T ConvertUpdateCompanySignUp <T, U>(U entity) { Company company = entity as Company; if (company == null) { return(default(T)); } BO.UpdateCompany updateCompanyBO = new BO.UpdateCompany(); updateCompanyBO.Signup = new BO.Signup(); if (company != null) { if (company.IsDeleted.HasValue == false || (company.IsDeleted.HasValue == true && company.IsDeleted.Value == false)) { BO.Company boCompany = new BO.Company(); using (CompanyRepository sr = new CompanyRepository(_context)) { boCompany = sr.Convert <BO.Company, Company>(company); updateCompanyBO.Signup.company = boCompany; } } } if (company.ContactInfo != null) { BO.ContactInfo boContactInfo = new BO.ContactInfo(); boContactInfo.ID = company.ContactInfo.id; boContactInfo.CellPhone = company.ContactInfo.CellPhone; boContactInfo.EmailAddress = company.ContactInfo.EmailAddress; updateCompanyBO.Signup.contactInfo = boContactInfo; } if (company.UserCompanies != null) { BO.User lstUser = new BO.User(); if (company.UserCompanies.Count >= 1) { var item = company.UserCompanies.FirstOrDefault(); if (item.IsDeleted.HasValue == false || (item.IsDeleted.HasValue == true && item.IsDeleted.Value == false)) { var userDB = _context.Users.Where(p => p.id == item.UserID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault(); using (UserRepository sr = new UserRepository(_context)) { BO.User BOUser = new BO.User(); BOUser = sr.Convert <BO.User, User>(userDB); BOUser.UserCompanies = null; BOUser.ContactInfo = null; BOUser.AddressInfo = null; BOUser.Roles = null; lstUser = BOUser; } } } updateCompanyBO.Signup.user = lstUser; } return((T)(object)updateCompanyBO); }