Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Web;
- using SimpleNotebook.BLL.Abstract;
- using SimpleNotebook.DI;
- using SimpleNotebook.Entities;
- namespace SimpleNotebook.PL.ASP.Models
- {
- public class NoteVM
- {
- public Guid Id { get; private set; }
- [Required]
- [Display(Name = "First name")]
- public string FirstName { get; private set; }
- [Required]
- [Display(Name = "Last name")]
- public string LastName { get; private set; }
- [Required]
- [Display(Name = "Birth year")]
- public int BirthYear { get; private set; }
- [Required]
- [Display(Name = "Phone number")]
- [DataType(DataType.PhoneNumber)]
- public string PhoneNumber { get; private set; }
- public NoteVM() { }
- public NoteVM(string firstName, string lastName, int birthYear, string phoneNumber)
- {
- Id = Guid.NewGuid();
- FirstName = firstName;
- LastName = lastName;
- BirthYear = birthYear;
- PhoneNumber = phoneNumber;
- }
- public NoteVM(string firstName, string lastName, int birthYear)
- {
- Id = Guid.NewGuid();
- FirstName = firstName;
- LastName = lastName;
- BirthYear = birthYear;
- }
- public static explicit operator NoteVM(NoteDTO dto)
- {
- return new NoteVM
- {
- Id = dto.Id,
- FirstName = dto.FirstName,
- LastName = dto.LastName,
- BirthYear = dto.BirthYear,
- PhoneNumber = dto.PhoneNumber
- };
- }
- public static explicit operator NoteDTO(NoteVM dto)
- {
- return new NoteDTO
- {
- Id = dto.Id,
- FirstName = dto.FirstName,
- LastName = dto.LastName,
- BirthYear = dto.BirthYear,
- PhoneNumber = dto.PhoneNumber
- };
- }
- private static INoteBLL _noteBLO = Provider.NoteBLO;
- public static bool Add(NoteVM noteVM)
- {
- return _noteBLO.Add((NoteDTO)noteVM);
- }
- public static bool Remove(Guid id)
- {
- return _noteBLO.Remove(id);
- }
- public static NoteVM Get(Guid id)
- {
- return (NoteVM)_noteBLO.Get(id);
- }
- public static IEnumerable<NoteVM> GetAll()
- {
- return _noteBLO.GetAll().Select(dto => (NoteVM)dto).ToArray();
- }
- public static IEnumerable<NoteVM> Find(string query)
- {
- return _noteBLO.Find(query).Select(dto => (NoteVM)dto).ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement