/// <summary> /// Adds the user as share holder. /// </summary> /// <param name="model">The model.</param> /// <param name="currentUserId">The current user identifier.</param> /// <returns></returns> /// <exception cref="FormatException">Invalid shareholder type</exception> /// <exception cref="EntityNotFoundException">Company {model.CompanyId} not found</exception> public async Task <Shareholder> AddUserAsShareHolder(ShareHolderAddUserModel model, string currentUserId) { var id = Guid.Parse(currentUserId); if (!new List <string> { RefShareholderTypeCode.Founders, RefShareholderTypeCode.Shareholders, RefShareholderTypeCode.Employees } .Contains(model.ShareholderType)) { throw new FormatException("Invalid shareholder type"); } var company = _companyRepository.GetManyAsNoTracking(x => x.AdminProfileId == id && x.CompanyId == model.CompanyId); if (company == null) { throw new EntityNotFoundException($"Company {model.CompanyId} not found"); } var shareholder = new Shareholder { CompanyId = model.CompanyId, UserProfileId = model.UserId, ShareholderTypeCode = model.ShareholderType }; var inserted = _shareholderRepository.Insert(shareholder).Entity; await _unitOfWork.CommitAsync(); return(inserted); }
public async Task <Shareholder> AddUserAsShareholder([FromBody] ShareHolderAddUserModel model) { var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; return(await _shareholderService.AddUserAsShareHolder(model, userId)); }