Пример #1
0
        public async Task <ActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                if (Input?.Password != _config.Value.AdminPassword)
                {
                    ModelState.AddModelError("Input.Password", "Wrong password.");
                }
                else
                {
                    var uploadFileName = "";
                    if (Input.Recording != null)
                    {
                        var fileExt  = Path.GetExtension(Input.Recording.FileName).ToUpperInvariant();
                        var validExt = new[] { ".MP3", ".M4A", ".ZIP" };
                        if (!validExt.Contains(fileExt))
                        {
                            ModelState.AddModelError("Input.Recording", "File must be in MP3, M4A or ZIP format.");
                        }
                        else
                        {
                            var now = _dateService.Now;
                            uploadFileName = $"{now:yyyy-MM-dd} {Input.Email}{fileExt}";
                            await _formHelper.UploadFileAsync(Input.Recording, _config.Value.UploadRecordingsPath, uploadFileName).ConfigureAwait(false);
                        }
                    }

                    if (ModelState.IsValid)
                    {
                        var contact = await _ontraContacts.SelectAsync(Input.Email).ConfigureAwait(false);

                        if (contact?.Id == null)
                        {
                            ModelState.AddModelError("Input.Email", "Contact not found in Ontraport.");
                        }
                        else if (contact.CoachingCallsLeft <= 0)
                        {
                            ModelState.AddModelError("Input.Email", "Contact has no coaching calls left.");
                        }
                        else
                        {
                            await _ontraRecordings.CreateAsync(new ApiRecording()
                            {
                                ContactId = contact.Id,
                                FileName  = uploadFileName
                            }.GetChanges()).ConfigureAwait(false);

                            contact.CoachingCallsLeft -= 1;
                            contact.LastCoachingDate   = _dateTimeService.UtcNowOffset;
                            await _ontraContacts.UpdateAsync(contact.Id.Value, contact.GetChanges()).ConfigureAwait(false);

                            return(new LocalRedirectResult("/coaching-sent"));
                        }
                    }
                }
            }
            return(Page());
        }
Пример #2
0
        public async Task EditCompanyField(string oldName, string newName)
        {
            var contacts = await _ontraContacts.SelectAsync(
                new ApiSearchOptions().AddCondition(ApiContact.CompanyKey, "=", oldName));

            var tasks = contacts.Select(async x =>
            {
                x.Company = newName;
                return(await _ontraContacts.UpdateAsync(x.Id.Value, x.GetChanges()));
            });
            await Task.WhenAll(tasks);
        }
Пример #3
0
        /// <summary>
        /// Deletes the specified user from the user store.
        /// </summary>
        /// <param name="user">The user to delete.</param>
        /// <param name="cancellationToken">The CancellationToken used to propagate notifications that the operation should be canceled.</param>
        /// <returns>An IdentityResult containing the deletion result.</returns>
        /// <exception cref="System.Net.Http.HttpRequestException">An HTTP error occured while communicating with Ontraport.</exception>
        /// <exception cref="System.OperationCanceledException">The task timed out or was cancelled.</exception>
        public async Task <IdentityResult> DeleteAsync(TUser user, CancellationToken cancellationToken)
        {
            user.CheckNotNull(nameof(user));
            user.Id.CheckRange(nameof(user.Id), min: 1);

            // Remove password hash.
            var contact = new TContact()
            {
                IdentityPasswordHash         = string.Empty,
                IdentityAccessFailedCount    = 0,
                IdentityLockoutEnd           = null,
                IdentityLockoutEnabled       = false,
                IdentityTwoFactorEnabled     = false,
                IdentityEmailConfirmed       = false,
                IdentityPhoneNumberConfirmed = false,
                IdentitySecurityStamp        = string.Empty
                                               // keep phone number
            };

            // Remove roles.
            var roles = await GetRolesAsync(user, cancellationToken).ConfigureAwait(false);

            foreach (var item in roles.ToList())
            {
                await RemoveFromRoleAsync(user, item, cancellationToken).ConfigureAwait(false);
            }

            // Update contact.
            var newContact = await _ontraportContacts.UpdateAsync(user.Id, contact.GetChanges(), cancellationToken).ConfigureAwait(false);

            if (newContact == null)
            {
                var msg = "There is no account with ID {0}.".FormatInvariant(user.Id);
                return(IdentityResult.Failed(new IdentityError()
                {
                    Description = msg
                }));
            }
            return(IdentityResult.Success);
        }