Advertisement
OniOnyMan

Untitled

Aug 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq;
  5. using System.Web;
  6. using SimpleNotebook.BLL.Abstract;
  7. using SimpleNotebook.DI;
  8. using SimpleNotebook.Entities;
  9.  
  10. namespace SimpleNotebook.PL.ASP.Models
  11. {
  12.     public class NoteVM
  13.     {
  14.         public Guid Id { get; private set; }
  15.  
  16.         [Required]
  17.         [Display(Name = "First name")]
  18.         public string FirstName { get; private set; }
  19.  
  20.         [Required]
  21.         [Display(Name = "Last name")]
  22.         public string LastName { get; private set; }
  23.  
  24.         [Required]
  25.         [Display(Name = "Birth year")]      
  26.         public int BirthYear { get; private set; }
  27.  
  28.         [Required]
  29.         [Display(Name = "Phone number")]
  30.         [DataType(DataType.PhoneNumber)]
  31.         public string PhoneNumber { get; private set; }
  32.  
  33.         public NoteVM() { }
  34.  
  35.         public NoteVM(string firstName, string lastName, int birthYear, string phoneNumber)
  36.         {
  37.             Id = Guid.NewGuid();
  38.             FirstName = firstName;
  39.             LastName = lastName;
  40.             BirthYear = birthYear;
  41.             PhoneNumber = phoneNumber;
  42.         }
  43.  
  44.         public NoteVM(string firstName, string lastName, int birthYear)
  45.         {
  46.             Id = Guid.NewGuid();
  47.             FirstName = firstName;
  48.             LastName = lastName;
  49.             BirthYear = birthYear;
  50.         }
  51.  
  52.         public static explicit operator NoteVM(NoteDTO dto)
  53.         {
  54.             return new NoteVM
  55.             {
  56.                 Id = dto.Id,
  57.                 FirstName = dto.FirstName,
  58.                 LastName = dto.LastName,
  59.                 BirthYear = dto.BirthYear,
  60.                 PhoneNumber = dto.PhoneNumber
  61.             };
  62.         }
  63.  
  64.         public static explicit operator NoteDTO(NoteVM dto)
  65.         {
  66.             return new NoteDTO
  67.             {
  68.                 Id = dto.Id,
  69.                 FirstName = dto.FirstName,
  70.                 LastName = dto.LastName,
  71.                 BirthYear = dto.BirthYear,
  72.                 PhoneNumber = dto.PhoneNumber
  73.             };
  74.         }
  75.  
  76.         private static INoteBLL _noteBLO = Provider.NoteBLO;
  77.  
  78.         public static bool Add(NoteVM noteVM)
  79.         {
  80.             return _noteBLO.Add((NoteDTO)noteVM);
  81.         }
  82.  
  83.         public static bool Remove(Guid id)
  84.         {
  85.             return _noteBLO.Remove(id);
  86.         }
  87.  
  88.         public static NoteVM Get(Guid id)
  89.         {
  90.             return (NoteVM)_noteBLO.Get(id);
  91.         }
  92.  
  93.         public static IEnumerable<NoteVM> GetAll()
  94.         {
  95.             return _noteBLO.GetAll().Select(dto => (NoteVM)dto).ToArray();
  96.         }
  97.  
  98.         public static IEnumerable<NoteVM> Find(string query)
  99.         {
  100.             return _noteBLO.Find(query).Select(dto => (NoteVM)dto).ToArray();
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement