コード例 #1
0
        public void SetConnectionToCache(PartnerConnection model)
        {
            var data = GetConnectionsForUser(model.UserId);

            data.Add(model);
            _cache.Remove($"Connections.{model.UserId}");
            _cache.Memoize($"Connections.{model.UserId}", () => { return(data); }, DateTime.UtcNow.TimeToMidnight());
        }
コード例 #2
0
        internal bool Upsert(ref PartnerConnection model)
        {
            //TODO - finish saving partner details
            var serviceId = model.Service.Id;
            var userId    = model.UserId;

            var partnerConnection = _context.PartnerConnections.Where(x => x.Service.Id == serviceId && x.UserId == userId).FirstOrDefault();

            if (partnerConnection != null)
            {
                //TODO - at the moment we dont need to edit so return false
                //partnerConnection.Service = model.Service;
                //partnerConnection.UserId = model.UserId;
                //_context.PartnerConnections.Update(partnerConnection);
                //_context.SaveChanges();
                return(false);
            }
            else
            {
                _context.PartnerConnections.Add(model);
                _context.SaveChanges();
                return(true);
            }
        }
コード例 #3
0
        // GET: PartnerConnectController/Details/5
        public ActionResult Details(int id)
        {
            var service = _serviceRepository.FindById(id);
            var url     = service.ConnectUrl;
            var claim   = User.FindFirst(ClaimTypes.NameIdentifier);
            var userId  = Guid.Parse(claim.Value);
            var company = _companyRepository.FindByUserId(userId);

            if (company == null)
            {
                //user has not completed registration
                return(RedirectToAction("Company", "Home", new { returnUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}" }));
            }

            var connect = new PartnerConnection()
            {
                Service   = service,
                UserId    = userId,
                Timestamp = DateTime.UtcNow
            };

            var newConnect = _partnerConnectionRepository.Upsert(ref connect);

            if (newConnect)
            {
                //add to cache
                _partnerConnectionsService.SetConnectionToCache(connect);
                if (service.PartnerSignupType == DataHelpers.PartnerSignupType.Email)
                {
                    //send email to user
                    var email      = _configuration["OverrideConnectionEmails"] != "" ? _configuration["OverrideConnectionEmails"] : connect.Service.Partner.MainContactEmail;
                    var mike       = _configuration["OverrideConnectionEmails"] != "" ? _configuration["OverrideConnectionEmails"] : "*****@*****.**";
                    var recipients = new List <string>()
                    {
                        email, User.Identity.Name, mike
                    };
                    var greeting = $"Hi {connect.Service.Partner.MainContactInformalName},";
                    var body     = $"I'd like to introduce you to {company.ContactFirstName} from {company.Name} who is interested in exploring the rates you offer to Crowd Order's users.";

                    var greeting2 = $"Hi {company.ContactFirstName},";
                    var body2     = $"Please meet {connect.Service.Partner.MainContact} from {connect.Service.Partner.Name} who is well placed to talk you through their offering in more detail. " +
                                    $"I'm sure {connect.Service.Partner.MainContactInformalName}  will reach out shortly to introduce themselves properly and thanks again for using Crowd Order. ";


                    var dynamicTemplateData = new EmailTemplateData
                    {
                        Subject   = "Connection request",
                        Greeting  = greeting,
                        Body      = body,
                        Greeting2 = greeting2,
                        Body2     = body2
                    };

                    ((EmailSender)_emailSender).SendEmailAsync(recipients, dynamicTemplateData, EmailSender.EmailTemplate.ConnectionEmail);
                }
            }

            var model = new PartnerConnectionVM()
            {
                PartnerConnection = connect, Suggestions = _siteDataService.GetSuggestedService(3, 0, connect.Service.Id)
            };

            return(View(model));
        }