Bitwarden-app-android-iphon.../src/Core/Models/View/IdentityView.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

174 lines
6.6 KiB
C#
Raw Normal View History

2019-04-12 22:39:20 +02:00
using System.Collections.Generic;
using Bit.Core.Enums;
using Bit.Core.Models.Domain;
2019-04-12 22:39:20 +02:00
namespace Bit.Core.Models.View
{
public class IdentityView : ItemView
2019-04-12 22:39:20 +02:00
{
2019-04-16 13:43:56 +02:00
private string _firstName;
private string _lastName;
private string _subTitle;
2019-04-12 22:39:20 +02:00
public IdentityView() { }
public IdentityView(Identity i) { }
public string Title { get; set; }
2019-04-16 13:43:56 +02:00
public string FirstName
{
get => _firstName;
set
{
_firstName = value;
_subTitle = null;
}
}
2019-04-12 22:39:20 +02:00
public string MiddleName { get; set; }
2019-04-16 13:43:56 +02:00
public string LastName
{
get => _lastName;
set
{
_lastName = value;
_subTitle = null;
}
}
2019-04-12 22:39:20 +02:00
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Company { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string SSN { get; set; }
public string Username { get; set; }
public string PassportNumber { get; set; }
public string LicenseNumber { get; set; }
public override string SubTitle
2019-04-16 13:43:56 +02:00
{
get
{
if (_subTitle == null && (FirstName != null || LastName != null))
2019-04-16 13:43:56 +02:00
{
_subTitle = string.Empty;
if (FirstName != null)
2019-04-16 13:43:56 +02:00
{
_subTitle = FirstName;
}
if (LastName != null)
2019-04-16 13:43:56 +02:00
{
if (_subTitle != string.Empty)
2019-04-16 13:43:56 +02:00
{
_subTitle += " ";
}
_subTitle += LastName;
}
}
return _subTitle;
}
}
public string FullName
{
get
{
if (!string.IsNullOrWhiteSpace(Title) || !string.IsNullOrWhiteSpace(FirstName) ||
2019-04-29 15:31:44 +02:00
!string.IsNullOrWhiteSpace(MiddleName) || !string.IsNullOrWhiteSpace(LastName))
2019-04-16 13:43:56 +02:00
{
var name = string.Empty;
if (!string.IsNullOrWhiteSpace(Title))
2019-04-16 13:43:56 +02:00
{
name = string.Concat(name, Title, " ");
}
if (!string.IsNullOrWhiteSpace(FirstName))
2019-04-16 13:43:56 +02:00
{
name = string.Concat(name, FirstName, " ");
}
if (!string.IsNullOrWhiteSpace(MiddleName))
2019-04-16 13:43:56 +02:00
{
name = string.Concat(name, MiddleName, " ");
}
if (!string.IsNullOrWhiteSpace(LastName))
2019-04-16 13:43:56 +02:00
{
name = string.Concat(name, LastName);
}
return name.Trim();
}
return null;
}
}
public string FullAddress
{
get
{
var address = Address1;
if (!string.IsNullOrWhiteSpace(Address2))
2019-04-16 13:43:56 +02:00
{
if (!string.IsNullOrWhiteSpace(address))
2019-04-16 13:43:56 +02:00
{
address += ", ";
}
address += Address2;
}
if (!string.IsNullOrWhiteSpace(Address3))
2019-04-16 13:43:56 +02:00
{
if (!string.IsNullOrWhiteSpace(address))
2019-04-16 13:43:56 +02:00
{
address += ", ";
}
address += Address3;
}
return address;
}
}
2019-04-29 16:20:29 +02:00
public string FullAddressPart2
{
get
{
if (string.IsNullOrWhiteSpace(City) && string.IsNullOrWhiteSpace(State) &&
2019-04-29 16:20:29 +02:00
string.IsNullOrWhiteSpace(PostalCode))
{
return null;
}
var city = string.IsNullOrWhiteSpace(City) ? "-" : City;
var state = string.IsNullOrWhiteSpace(State) ? "-" : State;
var postalCode = string.IsNullOrWhiteSpace(PostalCode) ? "-" : PostalCode;
return string.Format("{0}, {1}, {2}", city, state, postalCode);
}
}
public override List<KeyValuePair<string, LinkedIdType>> LinkedFieldOptions
{
get => new List<KeyValuePair<string, LinkedIdType>>()
{
new KeyValuePair<string, LinkedIdType>("Title", LinkedIdType.Identity_Title),
new KeyValuePair<string, LinkedIdType>("MiddleName", LinkedIdType.Identity_MiddleName),
new KeyValuePair<string, LinkedIdType>("Address1", LinkedIdType.Identity_Address1),
new KeyValuePair<string, LinkedIdType>("Address2", LinkedIdType.Identity_Address2),
new KeyValuePair<string, LinkedIdType>("Address3", LinkedIdType.Identity_Address3),
new KeyValuePair<string, LinkedIdType>("CityTown", LinkedIdType.Identity_City),
new KeyValuePair<string, LinkedIdType>("StateProvince", LinkedIdType.Identity_State),
new KeyValuePair<string, LinkedIdType>("ZipPostalCode", LinkedIdType.Identity_PostalCode),
new KeyValuePair<string, LinkedIdType>("Country", LinkedIdType.Identity_Country),
new KeyValuePair<string, LinkedIdType>("Company", LinkedIdType.Identity_Company),
new KeyValuePair<string, LinkedIdType>("Email", LinkedIdType.Identity_Email),
new KeyValuePair<string, LinkedIdType>("Phone", LinkedIdType.Identity_Phone),
new KeyValuePair<string, LinkedIdType>("SSN", LinkedIdType.Identity_Ssn),
new KeyValuePair<string, LinkedIdType>("Username", LinkedIdType.Identity_Username),
new KeyValuePair<string, LinkedIdType>("PassportNumber", LinkedIdType.Identity_PassportNumber),
new KeyValuePair<string, LinkedIdType>("LicenseNumber", LinkedIdType.Identity_LicenseNumber),
new KeyValuePair<string, LinkedIdType>("FirstName", LinkedIdType.Identity_FirstName),
new KeyValuePair<string, LinkedIdType>("LastName", LinkedIdType.Identity_LastName),
new KeyValuePair<string, LinkedIdType>("FullName", LinkedIdType.Identity_FullName),
};
}
2019-04-12 22:39:20 +02:00
}
}