Controllers/AccountController: Replace single line methods with expression bodied members. Includes constructor, C# 7 feature. Controllers/CatalogController: Remove unnecessary ToString() call. Replace single line methods with expression bodied members. Extensions/HttpClientExtensions: Replace single line methods with expression bodied members. Extensions/SessionExtensions: Replace single line methods with expression bodied members. Services/BasketService: Remove unnecessary ToString() calls. Add ?? to simplify conditional initialization Use TryGetValue and out variable initialization to simplify Quantity calculation Services/CatalogService: Use Value<T> generic method instead of dynamic types. There is a lot of overhead for dynamic and it seems overkill here. Services/IdentityParser: Use the pattern matching is expression. Refactor the LINQ queries to enumerate the collection (and create an enumerator) only once. The previous code had 3 enumerations. Services/Utilities/HttpApiClient: Remove the 'async' modifier and 'await' statements from methods where the only asynchronous statement is the final statement of the method, and the task from the underlying method can be returned. Services/Utilities/HttpApiClientWrapper: Use expression bodied members where applicable. Remove the 'async' modifier and 'await' statements from methods where the only asynchronous statement is the final statement of the method, and the task from the underlying method can be returned. ViewComponents/Cart: Use expression bodied members where applicable. ViewComponents/CartList: Use expression bodied members where applicable. Remove the 'async' modifier and 'await' statements from methods where the only asynchronous statement is the final statement of the method, and the task from the underlying method can be returned. ViewModels/Annotations/CardExpiration: Use the out variable initializer to simplify the validation of the card expiration date. ViewModels/Basket: Use property initializer syntax instead of constructor body ViewModels/CatalogViewModels/IndexViewModel: Use expression bodied property to return the calculated 'Disabled' property ViewModels/Order: Use property initializer syntax.
80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using Microsoft.eShopOnContainers.WebMVC.ViewModels.Annotations;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels
|
|
{
|
|
public class Order
|
|
{
|
|
public string OrderNumber {get;set;}
|
|
|
|
public DateTime Date {get;set;}
|
|
|
|
public string Status { get; set; }
|
|
|
|
public decimal Total {get;set;}
|
|
|
|
[Required]
|
|
public string City { get; set; }
|
|
[Required]
|
|
public string Street { get; set; }
|
|
[Required]
|
|
public string State { get; set; }
|
|
[Required]
|
|
public string Country { get; set; }
|
|
|
|
public string ZipCode { get; set; }
|
|
[Required]
|
|
[DisplayName("Card number")]
|
|
public string CardNumber { get; set; }
|
|
[Required]
|
|
[DisplayName("Cardholder name")]
|
|
public string CardHolderName { get; set; }
|
|
|
|
public DateTime CardExpiration { get; set; }
|
|
[RegularExpression(@"(0[1-9]|1[0-2])\/[0-9]{2}", ErrorMessage = "Expiration should match a valid MM/YY value")]
|
|
[CardExpiration(ErrorMessage = "The card is expired"), Required]
|
|
[DisplayName("Card expiration")]
|
|
public string CardExpirationShort { get; set; }
|
|
[Required]
|
|
[DisplayName("Card security number")]
|
|
public string CardSecurityNumber { get; set; }
|
|
|
|
public int CardTypeId { get; set; }
|
|
|
|
public string Buyer { get; set; }
|
|
|
|
// See the property initializer syntax below. This
|
|
// initializes the compiler generated field for this
|
|
// auto-implemented property.
|
|
public List<OrderItem> OrderItems { get; } = new List<OrderItem>();
|
|
|
|
[Required]
|
|
public Guid RequestId { get; set; }
|
|
|
|
|
|
public void CardExpirationShortFormat()
|
|
{
|
|
CardExpirationShort = CardExpiration.ToString("MM/yy");
|
|
}
|
|
|
|
public void CardExpirationApiFormat()
|
|
{
|
|
var month = CardExpirationShort.Split('/')[0];
|
|
var year = $"20{CardExpirationShort.Split('/')[1]}";
|
|
|
|
CardExpiration = new DateTime(int.Parse(year), int.Parse(month), 1);
|
|
}
|
|
}
|
|
|
|
public enum CardType
|
|
{
|
|
AMEX = 1
|
|
}
|
|
}
|