public bool Create(PublisherBindingModel model) { try { using (var libraryDb = new LibraryManagementEntities()) { // check duplicated var currentPublishers = libraryDb.Publishers.FirstOrDefault(s => s.Id == model.Id); if (currentPublishers != null) { throw new ArgumentNullException(); } // Insert db var publishersInfo = _entityMapper.Map <PublisherBindingModel, Publisher>(model); libraryDb.Publishers.Add(publishersInfo); libraryDb.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
public IActionResult Add(PublisherBindingModel model) { if (!ModelState.IsValid) { return(this.View(model)); } var mappedModel = this.mapper.Map <AddPublisherDTO>(model); this.publisherService.Add(mappedModel); return(this.RedirectToAction("All")); }
private void btnSave_Click(object sender, EventArgs e) { bool add = txtId.Text == "" ? false : true; if (!add) { PublisherBindingModel model = new PublisherBindingModel() { 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 { PublisherBindingModel model = new PublisherBindingModel() { 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); }
public bool Update(PublisherBindingModel model) { try { using (var libraryDb = new LibraryManagementEntities()) { // Check first get item var publishers = libraryDb.Publishers.FirstOrDefault(s => s.Id == model.Id); if (publishers == null) { throw new ArgumentNullException("No exist"); } publishers.Name = model.Name; libraryDb.SaveChanges(); return(true); } } catch (Exception) { return(false); } }