PageRenderTime 54ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/sipsorcery-core/SIPSorcery.CRM/ThirtySevenSignals/Person.cs

https://github.com/thecc4re/sipsorcery-mono
C# | 112 lines | 58 code | 19 blank | 35 comment | 0 complexity | 5adbe24e152991e2b5d3d37d0ebf0762 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. // ============================================================================
  2. // FileName: Person.cs
  3. //
  4. // Description:
  5. // Represents a Person object for the 37 Signals contact management system Highrise.
  6. //
  7. // Author(s):
  8. // Aaron Clauson
  9. //
  10. // History:
  11. // 13 Feb 2011 Aaron Clauson Created.
  12. //
  13. // License:
  14. // This software is licensed under the BSD License http://www.opensource.org/licenses/bsd-license.php
  15. //
  16. // Copyright (c) 2011 Aaron Clauson (aaron@sipsorcery.com), SIP Sorcery Pty Ltd
  17. // All rights reserved.
  18. //
  19. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that
  20. // the following conditions are met:
  21. //
  22. // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  23. // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  24. // disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of SIP Sorcery Ltd.
  25. // nor the names of its contributors may be used to endorse or promote products derived from this software without specific
  26. // prior written permission.
  27. //
  28. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  29. // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  30. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  31. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  32. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. // POSSIBILITY OF SUCH DAMAGE.
  35. // ============================================================================
  36. using System;
  37. using System.Collections.Generic;
  38. using System.Linq;
  39. using System.Text;
  40. using System.Xml.Serialization;
  41. namespace SIPSorcery.CRM.ThirtySevenSignals
  42. {
  43. [XmlRootAttribute("person", Namespace = "", IsNullable = false)]
  44. public class Person
  45. {
  46. public const string DATETIME_STRING_FORMAT = "yyyy-MM-ddTHH:mm:ssZ";
  47. public const string AVATAR_URL_FORMAT = "{0}/avatars/person/{1}/{2}-large.png";
  48. [XmlElement("id")]
  49. public int ID { get; set; }
  50. [XmlElement("author-id")]
  51. public int AuthorID { get; set; }
  52. [XmlElement("first-name")]
  53. public string FirstName { get; set; }
  54. [XmlElement("last-name")]
  55. public string LastName { get; set; }
  56. [XmlElement("title")]
  57. public string Title { get; set; }
  58. [XmlElement("background")]
  59. public string Background { get; set; }
  60. [XmlElement("company-id")]
  61. public int? CompanyID { get; set; }
  62. [XmlElement("created-at")]
  63. public string CreatedAtStr { get; set; }
  64. [XmlIgnore]
  65. public DateTimeOffset CreatedAt
  66. {
  67. get { return DateTimeOffset.Parse(CreatedAtStr); }
  68. set { CreatedAtStr = value.ToUniversalTime().ToString(DATETIME_STRING_FORMAT); }
  69. }
  70. [XmlElement("updated-at")]
  71. public string UpdatedAtStr { get; set; }
  72. [XmlIgnore]
  73. public DateTimeOffset UpdatedAt
  74. {
  75. get { return DateTimeOffset.Parse(UpdatedAtStr); }
  76. set { UpdatedAtStr = value.ToUniversalTime().ToString(DATETIME_STRING_FORMAT); }
  77. }
  78. [XmlElement("visible-to")]
  79. public string VisibleTo { get; set; }
  80. [XmlElement("owner-id", IsNullable=true)]
  81. public int? OwnerID { get; set; }
  82. [XmlElement("group-id", IsNullable = true)]
  83. public int? GroupID { get; set; }
  84. [XmlElement("contact-data")]
  85. public ContactData ContactData { get; set; }
  86. [XmlIgnore]
  87. public string AvatarURL { get; private set; }
  88. public void SetAvatarURL(string url)
  89. {
  90. AvatarURL = String.Format(AVATAR_URL_FORMAT, url, (ID / 10000).ToString(), (ID % 10000).ToString());
  91. }
  92. }
  93. }