Ejemplo n.º 1
0
        public bool Create(BookShelfBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // check duplicated
                    var currentBookshelf = libraryDb.BookShelves.FirstOrDefault(s => s.Id == model.Id);
                    if (currentBookshelf != null)
                    {
                        throw new ArgumentNullException();
                    }
                    // Insert db
                    var bookshelfInfo = _entityMapper.Map <BookShelfBindingModel, BookShelf>(model);
                    libraryDb.BookShelves.Add(bookshelfInfo);
                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool add = txtId.Text == "" ? false : true;

            if (!add)
            {
                BookShelfBindingModel model = new BookShelfBindingModel()
                {
                    Name = txtName.Text
                };

                if (manager.Create(model))
                {
                    add = false;
                    MessageBox.Show("Thêm mới thành công !", "Thông báo");
                }
                else
                {
                    MessageBox.Show("Thêm mới không thành công!. Liên hệ với quản trị viên.", "Thông báo");
                }
            }
            else
            {
                BookShelfBindingModel model = new BookShelfBindingModel()
                {
                    Id   = int.Parse(txtId.Text),
                    Name = txtName.Text
                };

                if (manager.Update(model))
                {
                    MessageBox.Show("Sửa thành công !", "Thông báo");
                }
                else
                {
                    MessageBox.Show("Sửa không thành công!. Liên hệ với quản trị viên.", "Thông báo");
                }
            }

            LoadData(Searching, PageIndex, PageSize);
        }
Ejemplo n.º 3
0
 public bool Update(BookShelfBindingModel model)
 {
     try
     {
         using (var libraryDb = new LibraryManagementEntities())
         {
             // Check first get item
             var bookshelf = libraryDb.BookShelves.FirstOrDefault(s => s.Id == model.Id);
             if (bookshelf == null)
             {
                 throw new ArgumentNullException("No exist");
             }
             bookshelf.Name = model.Name;
             libraryDb.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }