Viswanatha Swamy 811874b76a
Swamy/remove unused using and refactor the code (#1555)
* Removed Unused Using and Reorganized the Using

* Removed unused using, Reorganized using, moved the class to separate file, removed commented code in Catalog.API

* Revert "Removed unused using, Reorganized using, moved the class to separate file, removed commented code in Catalog.API"

This reverts commit 34241c430619b3b0bbeaabafa44c078c859237c4.

* Removed unused using and reorganized the using inside "Services" folder

* Removed Unused using and reoganized the using

* Refactor Webhooks.API

* Removed unused using and reorganized using inside Catalog.API

* Refactoring

* Removed unsed using

* Added line break just to differentiate between the messages

* Removed unused usings

* Simple Refactoring
2020-12-23 15:19:36 +05:30

104 lines
3.0 KiB
C#

using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.eShopOnContainers.WebMVC.ViewModels.Annotations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using WebMVC.Services.ModelDTOs;
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; }
public string Description { 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; }
public List<SelectListItem> ActionCodeSelectList =>
GetActionCodesByCurrentState();
// 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);
}
private List<SelectListItem> GetActionCodesByCurrentState()
{
var actions = new List<OrderProcessAction>();
switch (Status?.ToLower())
{
case "paid":
actions.Add(OrderProcessAction.Ship);
break;
}
var result = new List<SelectListItem>();
actions.ForEach(action =>
{
result.Add(new SelectListItem { Text = action.Name, Value = action.Code });
});
return result;
}
}
public enum CardType
{
AMEX = 1
}
}