Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Location
- {
- private int _id;
- public int ID
- {
- get { return _id; }
- private set
- {
- if (value == default(int))
- throw new ArgumentNullException("ID");
- _id = value;
- }
- }
- private string _name;
- public string Name
- {
- get { return _name; }
- set
- {
- if (string.IsNullOrWhiteSpace(value))
- throw new ArgumentNullException("Name");
- _name = value;
- }
- }
- public string Description { get; set; }
- private string _address;
- public string Address
- {
- get { return _address; }
- set
- {
- if (string.IsNullOrWhiteSpace(value))
- throw new ArgumentNullException("Address");
- _address = value;
- GeoCoordinates = IoCContainerFactory.Current.GetInstance<Geocoder>().ConvertAddressToCoordinates(Address);
- }
- }
- public Coordinates GeoCoordinates { get; private set; }
- private Location() { }
- public Location(string name, string address)
- {
- Name = name;
- Description = string.Empty;
- Address = address;
- }
- public Location(int id, string name, string description, string address, Coordinates coordinates)
- {
- if (coordinates == null)
- throw new ArgumentNullException("GeoCoordinates");
- ID = id;
- Name = name;
- Description = description;
- Address = address;
- }
- public class Coordinates
- {
- public decimal Latitude { get; private set; }
- public decimal Longitude { get; private set; }
- private Coordinates() { }
- public Coordinates(decimal latitude, decimal longitude)
- : this()
- {
- Latitude = latitude;
- Longitude = longitude;
- }
- public override bool Equals(object obj)
- {
- if (obj == null)
- return false;
- if (!(obj is Coordinates))
- return false;
- var coord = obj as Coordinates;
- return ((coord.Latitude == this.Latitude) &&
- (coord.Longitude == this.Longitude));
- }
- public override string ToString()
- {
- return string.Format("Latitude: {0}, Longitude: {1}", Latitude.ToString(), Longitude.ToString());
- }
- }
- }
- public class LocationViewModel
- {
- public int ID { get; set; }
- public string Name { get; set; }
- public string Description { get; set; }
- public string Address { get; set; }
- public decimal Latitude { get; set; }
- public decimal Longitude { get; set; }
- }
- public class LocationCreateViewModel
- {
- public string Name { get; set; }
- public string Description { get; set; }
- public string Address { get; set; }
- }
- public class LocationDetailsVieWModel
- {
- public int ID { get; set; }
- public string Name { get; set; }
- public string Description { get; set; }
- public string Address { get; set; }
- public decimal Latitude { get; set; }
- public decimal Longitude { get; set; }
- }
- public class LocationCreateViewModel
- {
- [Required]
- public string Name { get; set; }
- public string Description { get; set; }
- [Required]
- public string Address { get; set; }
- }
- public Location ToDomainModel();
- public static ConstructFromDomainModel(int id);
- public static ConstructFromDomainModel(Location location);
- public class CreateUser
- {
- [Required]
- public String FirstName { get; set; }
- [Required]
- public String LastName { get; set; }
- [Required]
- [DataType(DataType.EmailAddress)]
- public String Email { get; set; }
- [Required]
- [DataType(DataType.Password)]
- public String Password { get; set; }
- [Required]
- [DataType(DataType.Password)]
- public String VerifyPassword { get; set; }
- }
- public class EditUser
- {
- [HiddenInput(DisplayValue = false)]
- public int Id { get; set; }
- [Required]
- public String FirstName { get; set; }
- [Required]
- public String LastName { get; set; }
- [Required]
- [DataType(DataType.EmailAddress)]
- public String Email { get; set; }
- }
- public class DetailsUser
- {
- [HiddenInput(DisplayValue = true)]
- public int Id { get; set; }
- public String FirstName { get; set; }
- public String LastName { get; set; }
- public String Email { get; set; }
- public String Password { get { return "Not Shown"; } }
- }
- var editUser= user.MapTo<EditUser>();
- public class UserInformationViewModel
- {
- [Required]
- public String FirstName { get; set; }
- [Required]
- public String LastName { get; set; }
- }
- public class UserContactDetailsViewModel
- {
- [Required]
- [DataType(DataType.EmailAddress)]
- public String Email { get; set; }
- }
- public class UserPasswordViewModel
- {
- [DataType(DataType.Password)]
- public String Password { get; set; }
- [Required]
- [DataType(DataType.Password)]
- public String VerifyPassword { get; set; }
- }
- public class CreateUserViewModel
- {
- private UserInformationViewModel _information;
- public UserInformationViewModel Information
- {
- get { return _information ?? (_information = new UserInformationViewModel()); }
- set { _information = information; }
- }
- private UserContactDetailsViewModel _contactDetails;
- public UserContactDetailsViewModel ContactDetails
- {
- get { return _contactDetails ?? (_contactDetails = new UserContactDetailsViewModel()); }
- set { _contactDetails = information; }
- }
- private UserPasswordViewModel _password;
- public UserPasswordViewModel Verification
- {
- get { return _password ?? (_password = new UserPasswordViewModel()); }
- set { _password = information; }
- }
- }
- public class EditUserViewModel
- {
- [HiddenInput(DisplayValue = false)]
- [ReadOnly(true)]
- public int Id { get; set; }
- private UserInformationViewModel _information;
- public UserInformationViewModel Information
- {
- get { return _information ?? (_information = new UserInformationViewModel()); }
- set { _information = information; }
- }
- private UserContactDetailsViewModel _contactDetails;
- public UserContactDetailsViewModel ContactDetails
- {
- get { return _contactDetails ?? (_contactDetails = new UserContactDetailsViewModel()); }
- set { _contactDetails = information; }
- }
- }
- // For details view I would use either inheritence or simply add the Verification attribute onto a new
- // class. Lets go with inheritence for now
- public class UserDetailsViewModel
- {
- private UserPasswordViewModel _password;
- public UserPasswordViewModel Verification
- {
- get { return _password ?? (_password = new UserPasswordViewModel()); }
- set { _password = information; }
- }
- }
- UserContactDetailsViewModel => _UserContactDetails.cshtml
- UserInformationViewModel => _UserInformation.cshtml
- UserPasswordViewModel => _UserNewPassword.cshtml
- UserPasswordViewModel => _UserEditPassword.cshtml
- @Html.Partial("_UserInformation", Model.Information)
- <input id = "Firstname" name="Firstname" type="text" /> // etc
- <input id = "Information_Firstname" name="Information_Firstname" type="text" /> // etc
- @Html.Partial("_UserInformation", model => model.Information)
- <input id = "Information_Firstname" name="Information_Firstname" type="text" /> // etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement