TourIAm/TIAMWebApp/Shared/Models/ClientSide/UI/WizardModels/TransferDestinationWizardMo...

107 lines
4.3 KiB
C#

using AyCode.Entities.Locations;
using AyCode.Interfaces.TimeStampInfo;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TIAM.Core.Enums;
using TIAM.Entities.Addresses;
using TIAM.Entities.Transfers;
using TIAM.Resources;
namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
{
public class TransferDestinationWizardModel
{
[DataType(DataType.Text)]
[Display(Name = ResourceKeys.TransferDestinationId, ResourceType = typeof(TIAMResources))]
public string Id { get; set; }
//[Required(ErrorMessage = "The Username value should be specified.")]
[Required(ErrorMessage = "The Destination name should be specified.")]
[DataType(DataType.Text)]
[Display(Name = ResourceKeys.DestinationName, ResourceType = typeof(TIAMResources))]
public string Name { get; set; }
[Required(ErrorMessage = "The Destination info should be specified.")]
[DataType(DataType.MultilineText)]
[Display(Name = ResourceKeys.DestinationInfo, ResourceType = typeof(TIAMResources))]
public string Description { get; set; }
[Required(ErrorMessage = "The address should be specified.")]
[DataType(DataType.Text)]
[Display(Name = ResourceKeys.DestinationAddress, ResourceType = typeof(TIAMResources))]
public string AddressString { get; set; }
[Required(ErrorMessage = "The price should be specified.")]
[DataType("Price")]
[Display(Name = ResourceKeys.Price, ResourceType = typeof(TIAMResources))]
public double Price { get; set; }
public PriceType PriceType { get; set; }
public Address Address { get; set; }
//[DataType("Latitude")]
//[Display(Name = "Destination latitude")]
//public double Latitude { get; set; }
//[DataType("Longitude")]
//[Display(Name = "Destination longitude")]
//public double Longitude { get; set; }
public TransferDestinationWizardModel() { }
public TransferDestinationWizardModel(string name, string description, string addressString, double price, PriceType priceType, Address address) :this(Guid.NewGuid(), name, description, addressString, price, priceType, address)
{ }
public TransferDestinationWizardModel(Guid id, string name, string description, string addressString, double price, PriceType priceType, Address address)
{
Id = id.ToString();
Name = name;
Description = description;
AddressString = addressString;
Price = price;
PriceType = priceType;
Address = address;
}
public static TransferDestination CopyToTransferDestination(TransferDestinationWizardModel model)
=> CopyToTransferDestination(model, new TransferDestination());
public static TransferDestination CopyToTransferDestination(TransferDestinationWizardModel model, TransferDestination destination)
{
destination.Id = Guid.Parse(model.Id);
destination.Name = model.Name;
destination.Description = model.Description;
destination.AddressString = model.AddressString;
destination.Price = model.Price;
destination.Price2 = model.Price;
destination.Price3 = model.Price;
destination.PriceType = model.PriceType;
destination.Address = model.Address;
if (destination.Address == null)
{
var addressId = Guid.NewGuid();
destination.Address = new Address();
destination.AddressId = addressId;
destination.Address.Id = addressId;
}
Random rand = new Random();
int range = 42;
destination.Address.AddressText = model.AddressString;
destination.Address.Longitude = rand.NextDouble() * range;
destination.Address.Latitude = rand.NextDouble() * range;
return destination;
}
}
}