Exemplo n.º 1
0
 private VMBooks GetClone(VMBooks book)
 {
     return(new VMBooks()
     {
         Author = book.Author, Book = book.Book
     });
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the MainViewModel class. Initializes DataFields
        /// </summary>
        public MainViewModel(IDataService dataService)
        {
            _book        = new VMBooks();
            Books        = dataService.GetBooks();
            _index       = 0;
            _dataService = dataService;

            Add = new RelayCommand(() =>
            {
                var add = GetClone(_book);
                Books.Add(add);
                _dataService.AddBook(add);
            });
            Remove = new RelayCommand(() =>
            {
                if (_index < Books.Count && _index >= 0)
                {
                    _dataService.RemoveBook(Books[Index]);
                    Books.RemoveAt(Index);
                }
            });

            Modify = new RelayCommand(() =>
            {
                GetClone(Book, Books[Index]);
                _dataService.ModifyBook(Books[Index]);
            });
        }
Exemplo n.º 3
0
        public void AddBook(VMBooks book)
        {
            var b = Mapper.Map <TEntity>(book);

            Entities.Add(b);
            _dataBase.SaveChanges();
            book.ID = b.ID;
        }
Exemplo n.º 4
0
        public void ModifyBook(VMBooks book)
        {
            var b = Entities.Find(book.ID);

            b.Author = book.Author;
            b.Book   = book.Book;
            _dataBase.SaveChanges();
            book.ID = b.ID;
        }
Exemplo n.º 5
0
 public void RemoveBook(VMBooks book)
 {
     Entities.Remove(Entities.Find(book.ID));
     _dataBase.SaveChanges();
 }
Exemplo n.º 6
0
 public void ModifyBook(VMBooks book)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public void RemoveBook(VMBooks book)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 private void GetClone(VMBooks from, VMBooks to)
 {
     to.Book   = from.Book;
     to.Author = from.Author;
 }