/// <summary> /// Get the company for the user, be they an employee or an owner /// </summary> /// <param name="userIdString"></param> /// <returns></returns> public CompanyUiDto GetUiDto_CompanyFromUserGuid(string userIdString) { Guid userId = GuidHelper.GetGuid(userIdString); CompanyUiDto returnValue = null; var companyFromOwnerUserId = GetCompanyFromOwnerUserGuid(userIdString); var companyFromEmployeeUserId = GetCompanyAndThisEmployeeFromEmployeeProfessionalUserId(userIdString); Company dbCompany = null; if (companyFromEmployeeUserId != null) { dbCompany = companyFromEmployeeUserId; } else if (companyFromOwnerUserId != null) { dbCompany = companyFromOwnerUserId; } if (dbCompany != null) { returnValue = _mapper.Map <Company, CompanyUiDto>(dbCompany); } if (companyFromOwnerUserId != null) { returnValue.UILoadOnly_IsUserCompanyOwner = true; } return(returnValue); }
public CompanyProfessionalVm(IProfessionalQueries professionalQueries, ICompanyQueries companyQueries, string userId) { _professionalQueries = professionalQueries; _companyQueries = companyQueries; Professional = _professionalQueries.GetUiDto_ProfessionalFromUserGuid(userId); Company = _companyQueries.GetUiDto_CompanyFromUserGuid(userId); }
/// <summary> /// In the case that we have used the key to get a company (it could be used for other things) /// Get the company from the Key. /// </summary> /// <param name="specialKey"></param> /// <returns></returns> public CompanyUiDto GetUiDto_LinkingKey_GetCompany(string specialKey) { CompanyUiDto returnValue = null; Company company = LinkingKey_GetCompany(specialKey); if (company != null) { returnValue = _mapper.Map <Company, CompanyUiDto>(company); } return(returnValue); }
public async Task <ActionResult> Edit([Bind(Include = "CompanyId,CompanyIndex,CompanyName,AddressLine1,AddressLine2,TownCity,County,Postcode,MainContactName,MainContactEmail,MainContactTel,SecondaryContactName,SecondaryContactEmail,SecondaryContactTel,IsApproved,ApprovedDate,BannedDate,BannedReason,Notes,ApiLiveKey,ApiTestKey,IsDeleted")] CompanyUiDto company) { if (ModelState.IsValid) { // New company ownership set up in this method. _companyQueries.AddOrUpdateCompanyFromDto(User.Identity.GetUserId(), company); return(RedirectToAction("Index", "Appointments")); } else { return(View(company)); } }
public void AddOrUpdateCompanyFromDto(string requestorUserId, CompanyUiDto companyDto) { Guid userId = GuidHelper.GetGuid(requestorUserId); //1. Make sure the user has the rights to do this. Are the company owner, // or is there no company for this pro? var dbCompany = GetCompanyFromOwnerUserGuid(requestorUserId); var companyByCompanyId = _unitOfWork.CompaniesRepository.GetByGuid(companyDto.CompanyId); // validate (make sure company id's haven't changed, which would sneakily switch ownership) if (dbCompany != null && companyByCompanyId != null && dbCompany.CompanyId != companyByCompanyId.CompanyId) { throw new InvalidOperationException("Only the company owner can update company details."); } bool isInsert = false; if (dbCompany == null) { // new company setup, add it AND ADD OWNERSHIP! dbCompany = new Company(); dbCompany.CompanyId = Guid.NewGuid(); dbCompany.Owner = _unitOfWork.ProfessionalsRepository.Get(i => i.ProfessionalUserId == userId).FirstOrDefault(); isInsert = true; } dbCompany.CompanyName = companyDto.CompanyName; dbCompany.AddressLine1 = companyDto.AddressLine1; dbCompany.AddressLine2 = companyDto.AddressLine2; dbCompany.TownCity = companyDto.TownCity; dbCompany.County = companyDto.County; dbCompany.Postcode = companyDto.Postcode; dbCompany.MainContactName = companyDto.MainContactName; dbCompany.MainContactEmail = companyDto.MainContactEmail; dbCompany.MainContactTel = companyDto.MainContactTel; dbCompany.SecondaryContactName = companyDto.SecondaryContactName; dbCompany.SecondaryContactEmail = companyDto.SecondaryContactEmail; dbCompany.SecondaryContactTel = companyDto.SecondaryContactTel; if (isInsert) { _unitOfWork.CompaniesRepository.Insert(dbCompany); } else { _unitOfWork.CompaniesRepository.Update(dbCompany); } _unitOfWork.Save(); }