Example #1
0
        public async Task ReadAllTeamStatus(PerformContext context)
        {
            foreach (var team in db.Teams.ToList())
            {
                var number = await exclusiveTaskFactory.StartNew(() =>
                {
                    using (var helper = new ATHelper(team.ComPort)) return(helper.GetForwardedPhoneNumber());
                });

                var state = await db.ForwardingStates.OrderByDescending(s => s.When).FirstOrDefaultAsync();

                if (state?.RawPhoneNumber == number)
                {
                    continue;
                }

                var newState = new ForwardingState
                {
                    Team                = team,
                    When                = DateTimeOffset.Now,
                    RawPhoneNumber      = number,
                    DetectedPhoneNumber = db.UserPhoneNumbers
                                          .FirstOrDefault(p => p.Value == number)
                };

                db.ForwardingStates.Add(newState);
                db.SaveChanges();
            }
        }
Example #2
0
            public void Handle(Command message)
            {
                var user = new DAL.User {
                    DisplayName = message.DisplayName, Login = message.Login
                };

                db.Users.Add(user);
                db.SaveChanges();

                if (message.PrimaryEmailAddress != null)
                {
                    user.PrimaryEmailAddress =
                        new UserEmailAddress {
                        User = user, Value = message.PrimaryEmailAddress, IsVerified = true
                    };
                }

                if (message.PrimaryPhoneNumber != null)
                {
                    user.PrimaryPhoneNumber = new UserPhoneNumber
                    {
                        User       = user,
                        Label      = "Primary",
                        Value      = message.PrimaryPhoneNumber,
                        IsVerified = true
                    };
                }
            }
        public void Handle(AddPhoneNumberCommand message)
        {
            var user        = db.Users.WhereUserLoginIs(message.UserName).Single();
            var phoneNumber = Mapper.Map <UserPhoneNumber>(message.PhoneNumber);
            var code        = VerificationCodeManager.GenerateCode();

            phoneNumber.VerificationToken = VerificationCodeManager.GetHash(phoneNumber.Value + code);

            user.PhoneNumbers.Add(Mapper.Map <UserPhoneNumber>(message.PhoneNumber));
            db.SaveChanges();
        }
        public void Handle(AddEmailAddressCommand message)
        {
            var user         = db.Users.WhereUserLoginIs(message.UserName).Single();
            var emailAddress = new UserEmailAddress {
                Value = message.EmailAddress
            };
            var code = VerificationCodeManager.GenerateCode();

            emailAddress.VerificationToken = VerificationCodeManager.GetHash(emailAddress.Value + code);

            user.EmailAddresses.Add(emailAddress);
            db.SaveChanges();

            var urlCommand = new VerifyEmailAddressCommand
            {
                Id = emailAddress.Id,
                VerificationCode = code
            };

            var url = message.VerificationUrlBuilder(urlCommand);

            mailer.EmailVerificationCode(emailAddress.Value, user.Login, url);
        }