예제 #1
0
        public LinkingKeyUiDto CreateLinkingKey_AddProfessionalToCompany(string userIdString, string linkToEmailAddress, DateTime expiry)
        {
            LinkingKeyUiDto returnValue  = null;
            var             companyOwner = _companyQueries.GetCompanyFromOwnerUserGuid(userIdString);
            var             professional = _professionalQueries.GetProfessionalFromUserGuid(userIdString);

            if (companyOwner == null)
            {
                throw new InvalidOperationException("Only a company owner can add a key");
            }

            LinkingKey linkingKey = new LinkingKey();

            linkingKey.CreatedDateTime          = DateTime.Now;
            linkingKey.AvailableForEmailAddress = linkToEmailAddress.ToLower().Trim();
            linkingKey.ExpiryDateTime           = expiry;

            linkingKey.Owner         = professional;
            linkingKey.FromTableName = "Professional";
            linkingKey.FromTablePK   = ""; /* they might not have signed up to our service yet. */

            linkingKey.ToTableName = "Company";
            linkingKey.ToTablePK   = companyOwner.CompanyId.ToString();

            linkingKey.SpecialKey = Helpers.SpecialKeyGenerator.CreateSpecialKey();


            _unitOfWork.LinkingKeyRepository.Insert(linkingKey);
            _unitOfWork.Save();


            returnValue = _mapper.Map <LinkingKey, LinkingKeyUiDto>(linkingKey);

            return(returnValue);
        }
예제 #2
0
        public async Task <ActionResult> CreateCompanyProKey([Bind(Include = "AvailableForEmailAddress")] LinkingKeyUiDto linkingKey)
        {
            var propertyToValidate = ModelState["AvailableForEmailAddress"];

            if (propertyToValidate != null && !propertyToValidate.Errors.Any())
            {
                var expiry = DateTime.Now.AddDays(3);
                _linkingKeyQueries.CreateLinkingKey_AddProfessionalToCompany(User.Identity.GetUserId(), linkingKey.AvailableForEmailAddress, expiry);

                return(RedirectToAction("Index"));
            }

            return(View(linkingKey));
        }