protected void btnAdd_Click(object sender, EventArgs e) { PublisherBiz pBiz = new PublisherBiz(); lwg_Publisher p; if (string.IsNullOrEmpty(hdfID.Value)) { p = new lwg_Publisher(); lblNote.Text = "Insert error, please try again"; } else { p = pBiz.GetByID(int.Parse(hdfID.Value)); lblNote.Text = "Update error, please try again"; } if (p != null) { p.Name = txtName.Text; if (pBiz.SavePublisher(p)) { BindingPublisher(); txtName.Text = string.Empty; pnEditPublisher.Visible = false; pnListPublisher.Visible = true; return; } } lblNote.Visible = true; }
public bool SavePublisher(lwg_Publisher p) { if (p != null) { if (p.PublisherId > 0) { lwg_Publisher c = dbContext.lwg_Publisher.SingleOrDefault(ht => ht.PublisherId == p.PublisherId); if (c != null) { c.Name = p.Name; } else { return(false); } } else { if (dbContext.lwg_Publisher.Count() > 0) { p.PublisherId = dbContext.lwg_Publisher.OrderByDescending(pe => pe.PublisherId).First().PublisherId + 1; } else { p.PublisherId = 1; } dbContext.lwg_Publisher.Add(p); } dbContext.SaveChanges(); return(true); } return(false); }
protected void rptPublisher_ItemCommand(object source, RepeaterCommandEventArgs e) { PublisherBiz pBiz = new PublisherBiz(); lwg_Publisher p = pBiz.GetByID(int.Parse(e.CommandArgument.ToString())); if (e.CommandName.Equals("EDIT")) { if (p != null) { btnAdd.Text = "Update"; txtTitle.Text = "Update Publisher"; hdfID.Value = e.CommandArgument.ToString(); pnEditPublisher.Visible = true; pnListPublisher.Visible = false; txtName.Text = p.Name; } } else if (e.CommandName.Equals("DELETE")) { if (p != null) { if (pBiz.DeletePublisher(p)) { BindingPublisher(); } } } }
public bool DeletePublisher(lwg_Publisher p) { if (p != null) { List <lwg_CatalogPublisher> lst = dbContext.lwg_CatalogPublisher.Where(cg => cg.PublisherId == p.PublisherId).ToList(); if (lst != null && lst.Count > 0) { dbContext.lwg_CatalogPublisher.RemoveRange(lst); } dbContext.lwg_Publisher.Remove(p); dbContext.SaveChanges(); return(true); } return(false); }
public bool CheckAndInsertPublisher(string publisherName, int catalogID) { lwg_Publisher lwg = dbContext.lwg_Publisher.SingleOrDefault(o => o.Name.ToLower().Equals(publisherName.ToLower())); if (lwg == null) { lwg = new lwg_Publisher(); lwg.Name = publisherName; SavePublisher(lwg); } if (!dbContext.lwg_CatalogPublisher.Any(o => o.CatalogId == catalogID && o.PublisherId == lwg.PublisherId)) { lwg_CatalogPublisher catalogPublisher = new lwg_CatalogPublisher(); catalogPublisher.CatalogId = catalogID; catalogPublisher.PublisherId = lwg.PublisherId; dbContext.lwg_CatalogPublisher.Add(catalogPublisher); dbContext.SaveChanges(); return(true); } return(false); }