Need help in creating the field "Customer Code" and "Product Code".
I am writing an online store application in Visual Studio (MVC). I use the approach of Code-first. I am new to this business and I understand everything.
For my project, these 2 fields are needed. The format of the field "Customer Code" is “XXXX-YYYY” where X is a number, YYYY is the year in which the customer is registered.
The field "Product Code" is the format “XX-XXXX-YYXX” where X is a number, Y is an uppercase letter of the English alphabet.
I read about getters and setters on MSDN, but I didn’t find anything similar. Tell me how to make them better example.
transferred from “answer” :
The entities Order and Item are already described, as well as others.
Customer code.
[Bind(Exclude = "OrderID")] public partial class Order { [ScaffoldColumn(false)] public int OrderID { get; set; } public string Code { get; set; } [DisplayName("Дата заказа")] [ScaffoldColumn(false)] public System.DateTime OrderDate { get; set; } [DisplayName("Дата доставки")] [ScaffoldColumn(false)] public System.DateTime OrderDateShiping { get; set; } [DisplayName("Имя пользователя")] [ScaffoldColumn(false)] public string UserName { get; set; } [Required(ErrorMessage = "Введите Ваше имя")] [DisplayName("Имя")] [StringLength(160)] public string FirstName { get; set; } [Required(ErrorMessage = "Введите Вашу фамилию")] [DisplayName("Фамилия")] [StringLength(160)] public string LastName { get; set; } [DisplayName("Адресс")] [Required(ErrorMessage = "Введите Ваш адресс")] [StringLength(70)] public string Address { get; set; } [DisplayName("Город")] [Required(ErrorMessage = "Введите Ваш город")] [StringLength(40)] public string City { get; set; } [DisplayName("Область")] [Required(ErrorMessage = "Введите область")] [StringLength(40)] public string State { get; set; } [Required(ErrorMessage = "Введите индекс")] [DisplayName("Индекс")] [StringLength(10)] public string PostalCode { get; set; } [DisplayName("Страна")] [Required(ErrorMessage = "Введите страну")] [StringLength(40)] public string Country { get; set; } [DisplayName("Номер телефона")] [Required(ErrorMessage = "Введите Ваш номер телефона")] [StringLength(24)] public string Phone { get; set; } [Required(ErrorMessage = "Введите Ваш Emal")] [DisplayName("Email")] [RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}", ErrorMessage = "Поле Email введено не корректно.")] [DataType(DataType.EmailAddress)] public string Email { get; set; } [DisplayName("Сумма")] [ScaffoldColumn(false)] public decimal Total { get; set; } public ICollection<OrderDetail> OrderDetails { get; set; } public User User { get; set; }
Product code.
[Bind(Exclude = "ItemID")] public partial class Item { [ScaffoldColumn(false)] public int ItemID { get; set; } [DisplayName("Наименование")] [Required(ErrorMessage = "Введите наименование")] [StringLength(160)] public string Title { get; set; } public string Code { get; set; } [DisplayName("Бренд")] public int BrandID { get; set; } [DisplayName("Категория")] public int CategoryID { get; set; } [DisplayName("Стоимость")] [Required(ErrorMessage = "Введите стомость")] [Range(0.01, 100.00, ErrorMessage = "Цена должна быть от 0.01 до 100.00")] public decimal Price { get; set; } [DisplayName("Логотип")] [StringLength(1024)] public string ItemArtUrl { get; set; } public virtual Category Category { get; set; } public virtual Brand Brand { get; set; } public virtual ICollection<OrderDetail> OrderDetails { get; set; }
StoreEntities code
public DbSet<Item> Items { get; set; } public DbSet<Category> Categorys { get; set; } public DbSet<Brand> Brands { get; set; } public DbSet<Cart> Carts { get; set; } public DbSet<Order> Orders { get; set; } public DbSet<OrderDetail> OrderDetails { get; set; }
All operations are also implemented. My problem is that you need to add the Code field, but I do not understand how to make it in this format. So I ask for help with this field, suggest how to do it, or if it is possible to give a similar example.