Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. public class Location
  2. {
  3. private int _id;
  4. public int ID
  5. {
  6. get { return _id; }
  7. private set
  8. {
  9. if (value == default(int))
  10. throw new ArgumentNullException("ID");
  11. _id = value;
  12. }
  13. }
  14.  
  15. private string _name;
  16. public string Name
  17. {
  18. get { return _name; }
  19. set
  20. {
  21. if (string.IsNullOrWhiteSpace(value))
  22. throw new ArgumentNullException("Name");
  23. _name = value;
  24. }
  25. }
  26.  
  27. public string Description { get; set; }
  28.  
  29. private string _address;
  30. public string Address
  31. {
  32. get { return _address; }
  33. set
  34. {
  35. if (string.IsNullOrWhiteSpace(value))
  36. throw new ArgumentNullException("Address");
  37. _address = value;
  38.  
  39. GeoCoordinates = IoCContainerFactory.Current.GetInstance<Geocoder>().ConvertAddressToCoordinates(Address);
  40. }
  41. }
  42.  
  43. public Coordinates GeoCoordinates { get; private set; }
  44.  
  45. private Location() { }
  46.  
  47. public Location(string name, string address)
  48. {
  49. Name = name;
  50. Description = string.Empty;
  51. Address = address;
  52. }
  53.  
  54. public Location(int id, string name, string description, string address, Coordinates coordinates)
  55. {
  56. if (coordinates == null)
  57. throw new ArgumentNullException("GeoCoordinates");
  58.  
  59. ID = id;
  60. Name = name;
  61. Description = description;
  62. Address = address;
  63. }
  64.  
  65. public class Coordinates
  66. {
  67. public decimal Latitude { get; private set; }
  68. public decimal Longitude { get; private set; }
  69.  
  70. private Coordinates() { }
  71.  
  72. public Coordinates(decimal latitude, decimal longitude)
  73. : this()
  74. {
  75. Latitude = latitude;
  76. Longitude = longitude;
  77. }
  78.  
  79. public override bool Equals(object obj)
  80. {
  81. if (obj == null)
  82. return false;
  83. if (!(obj is Coordinates))
  84. return false;
  85. var coord = obj as Coordinates;
  86. return ((coord.Latitude == this.Latitude) &&
  87. (coord.Longitude == this.Longitude));
  88. }
  89.  
  90. public override string ToString()
  91. {
  92. return string.Format("Latitude: {0}, Longitude: {1}", Latitude.ToString(), Longitude.ToString());
  93. }
  94. }
  95. }
  96.  
  97. public class LocationViewModel
  98. {
  99. public int ID { get; set; }
  100. public string Name { get; set; }
  101. public string Description { get; set; }
  102. public string Address { get; set; }
  103. public decimal Latitude { get; set; }
  104. public decimal Longitude { get; set; }
  105. }
  106.  
  107. public class LocationCreateViewModel
  108. {
  109. public string Name { get; set; }
  110. public string Description { get; set; }
  111. public string Address { get; set; }
  112. }
  113.  
  114. public class LocationDetailsVieWModel
  115. {
  116. public int ID { get; set; }
  117. public string Name { get; set; }
  118. public string Description { get; set; }
  119. public string Address { get; set; }
  120. public decimal Latitude { get; set; }
  121. public decimal Longitude { get; set; }
  122. }
  123.  
  124. public class LocationCreateViewModel
  125. {
  126. [Required]
  127. public string Name { get; set; }
  128. public string Description { get; set; }
  129. [Required]
  130. public string Address { get; set; }
  131. }
  132.  
  133. public Location ToDomainModel();
  134.  
  135. public static ConstructFromDomainModel(int id);
  136. public static ConstructFromDomainModel(Location location);
  137.  
  138. public class CreateUser
  139. {
  140. [Required]
  141. public String FirstName { get; set; }
  142. [Required]
  143. public String LastName { get; set; }
  144. [Required]
  145. [DataType(DataType.EmailAddress)]
  146. public String Email { get; set; }
  147. [Required]
  148. [DataType(DataType.Password)]
  149. public String Password { get; set; }
  150. [Required]
  151. [DataType(DataType.Password)]
  152. public String VerifyPassword { get; set; }
  153. }
  154.  
  155. public class EditUser
  156. {
  157. [HiddenInput(DisplayValue = false)]
  158. public int Id { get; set; }
  159. [Required]
  160. public String FirstName { get; set; }
  161. [Required]
  162. public String LastName { get; set; }
  163. [Required]
  164. [DataType(DataType.EmailAddress)]
  165. public String Email { get; set; }
  166. }
  167.  
  168. public class DetailsUser
  169. {
  170. [HiddenInput(DisplayValue = true)]
  171. public int Id { get; set; }
  172. public String FirstName { get; set; }
  173. public String LastName { get; set; }
  174. public String Email { get; set; }
  175. public String Password { get { return "Not Shown"; } }
  176. }
  177.  
  178. var editUser= user.MapTo<EditUser>();
  179.  
  180. public class UserInformationViewModel
  181. {
  182. [Required]
  183. public String FirstName { get; set; }
  184. [Required]
  185. public String LastName { get; set; }
  186. }
  187.  
  188. public class UserContactDetailsViewModel
  189. {
  190. [Required]
  191. [DataType(DataType.EmailAddress)]
  192. public String Email { get; set; }
  193. }
  194.  
  195. public class UserPasswordViewModel
  196. {
  197. [DataType(DataType.Password)]
  198. public String Password { get; set; }
  199. [Required]
  200. [DataType(DataType.Password)]
  201. public String VerifyPassword { get; set; }
  202. }
  203.  
  204. public class CreateUserViewModel
  205. {
  206. private UserInformationViewModel _information;
  207.  
  208. public UserInformationViewModel Information
  209. {
  210. get { return _information ?? (_information = new UserInformationViewModel()); }
  211. set { _information = information; }
  212. }
  213.  
  214. private UserContactDetailsViewModel _contactDetails;
  215.  
  216. public UserContactDetailsViewModel ContactDetails
  217. {
  218. get { return _contactDetails ?? (_contactDetails = new UserContactDetailsViewModel()); }
  219. set { _contactDetails = information; }
  220. }
  221. private UserPasswordViewModel _password;
  222.  
  223. public UserPasswordViewModel Verification
  224. {
  225. get { return _password ?? (_password = new UserPasswordViewModel()); }
  226. set { _password = information; }
  227. }
  228. }
  229.  
  230. public class EditUserViewModel
  231. {
  232. [HiddenInput(DisplayValue = false)]
  233. [ReadOnly(true)]
  234. public int Id { get; set; }
  235.  
  236. private UserInformationViewModel _information;
  237. public UserInformationViewModel Information
  238. {
  239. get { return _information ?? (_information = new UserInformationViewModel()); }
  240. set { _information = information; }
  241. }
  242.  
  243. private UserContactDetailsViewModel _contactDetails;
  244. public UserContactDetailsViewModel ContactDetails
  245. {
  246. get { return _contactDetails ?? (_contactDetails = new UserContactDetailsViewModel()); }
  247. set { _contactDetails = information; }
  248. }
  249. }
  250.  
  251. // For details view I would use either inheritence or simply add the Verification attribute onto a new
  252. // class. Lets go with inheritence for now
  253. public class UserDetailsViewModel
  254. {
  255. private UserPasswordViewModel _password;
  256.  
  257. public UserPasswordViewModel Verification
  258. {
  259. get { return _password ?? (_password = new UserPasswordViewModel()); }
  260. set { _password = information; }
  261. }
  262. }
  263.  
  264. UserContactDetailsViewModel => _UserContactDetails.cshtml
  265. UserInformationViewModel => _UserInformation.cshtml
  266. UserPasswordViewModel => _UserNewPassword.cshtml
  267. UserPasswordViewModel => _UserEditPassword.cshtml
  268.  
  269. @Html.Partial("_UserInformation", Model.Information)
  270.  
  271. <input id = "Firstname" name="Firstname" type="text" /> // etc
  272.  
  273. <input id = "Information_Firstname" name="Information_Firstname" type="text" /> // etc
  274.  
  275. @Html.Partial("_UserInformation", model => model.Information)
  276.  
  277. <input id = "Information_Firstname" name="Information_Firstname" type="text" /> // etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement