null checking

This commit is contained in:
Kyle Spearrin 2019-07-22 08:44:55 -04:00
parent 2062a284e3
commit c2108fdda0
2 changed files with 12 additions and 9 deletions

View File

@ -440,7 +440,7 @@ namespace Bit.App.Pages
EditMode ? AppResources.ItemUpdated : AppResources.NewItemCreated);
_messagingService.Send(EditMode ? "editedCipher" : "addedCipher", Cipher.Id);
if((Page as AddEditPage).FromAutofillFramework)
if(Page is AddEditPage page && page.FromAutofillFramework)
{
// Close and go back to app
_deviceActionService.CloseAutofill();

View File

@ -123,14 +123,14 @@ namespace Bit.iOS.Core.Controllers
}
*/
if(string.IsNullOrWhiteSpace(PasswordCell.TextField.Text))
if(string.IsNullOrWhiteSpace(PasswordCell?.TextField?.Text))
{
DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.Password), AppResources.Ok);
return;
}
if(string.IsNullOrWhiteSpace(NameCell.TextField.Text))
if(string.IsNullOrWhiteSpace(NameCell?.TextField?.Text))
{
DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.Name), AppResources.Ok);
@ -139,20 +139,23 @@ namespace Bit.iOS.Core.Controllers
var cipher = new CipherView
{
Name = string.IsNullOrWhiteSpace(NameCell.TextField.Text) ? null : NameCell.TextField.Text,
Notes = string.IsNullOrWhiteSpace(NotesCell.TextView.Text) ? null : NotesCell.TextView.Text,
Name = NameCell.TextField.Text,
Notes = string.IsNullOrWhiteSpace(NotesCell?.TextView?.Text) ? null : NotesCell.TextView.Text,
Favorite = FavoriteCell.Switch.On,
FolderId = FolderCell.SelectedIndex == 0 ? null : _folders.ElementAtOrDefault(FolderCell.SelectedIndex - 1)?.Id,
FolderId = FolderCell.SelectedIndex == 0 ?
null : _folders.ElementAtOrDefault(FolderCell.SelectedIndex - 1)?.Id,
Type = Bit.Core.Enums.CipherType.Login,
Login = new LoginView
{
Uris = null,
Username = string.IsNullOrWhiteSpace(UsernameCell.TextField.Text) ? null : UsernameCell.TextField.Text,
Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ? null : PasswordCell.TextField.Text,
Username = string.IsNullOrWhiteSpace(UsernameCell?.TextField?.Text) ?
null : UsernameCell.TextField.Text,
Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ?
null : PasswordCell.TextField.Text,
}
};
if(!string.IsNullOrWhiteSpace(UriCell.TextField.Text))
if(!string.IsNullOrWhiteSpace(UriCell?.TextField?.Text))
{
cipher.Login.Uris = new List<LoginUriView>
{