public bool SaveInstrTitle(lwg_InstrTitle p) { if (p != null) { if (p.Id > 0) { lwg_InstrTitle c = dbContext.lwg_InstrTitle.SingleOrDefault(ht => ht.Id == p.Id); if (c != null) { c.Name = p.Name; c.TitleTypeId = p.TitleTypeId; } else { return(false); } } else { if (dbContext.lwg_InstrTitle.Count() > 0) { p.Id = dbContext.lwg_InstrTitle.OrderByDescending(pe => pe.Id).First().Id + 1; } else { p.Id = 1; } dbContext.lwg_InstrTitle.Add(p); } dbContext.SaveChanges(); return(true); } return(false); }
//protected void lnkbtnTitleTypeManage_Click(object sender, EventArgs e) //{ // BindingTitleType(); // pnListTitleType.Visible = true; // pnEditTitleType.Visible = false; // divInstrTitle.Attributes.Add("style", "display: none;"); // divTitleType.Attributes.Add("style", "display: block;"); //} protected void rptListrInstrTitle_ItemCommand(object source, RepeaterCommandEventArgs e) { CatalogTitleTypeBiz pBiz = new CatalogTitleTypeBiz(); lwg_InstrTitle p = pBiz.GetInstrTitleByID(int.Parse(e.CommandArgument.ToString())); if (e.CommandName.Equals("EDIT")) { if (p != null) { btnAddEditInstrTitle.Text = "Update"; lblTitleInstrTitle.Text = "Update InstrTitle"; HiddenField1.Value = e.CommandArgument.ToString(); pnEditInstrTitle.Visible = true; pnListInstrTitle.Visible = false; txtInstrTitleName.Text = p.Name; if (drpTitleType.Items.Count > 0) { drpTitleType.SelectedValue = p.TitleTypeId.ToString(); } } } else if (e.CommandName.Equals("DELETE")) { if (p != null) { if (pBiz.DeleteInstrTitle(p)) { BindingInstrTitle(); } } } }
protected void btnAddEditInstrTitle_Click(object sender, EventArgs e) { CatalogTitleTypeBiz pBiz = new CatalogTitleTypeBiz(); lwg_InstrTitle p; if (string.IsNullOrEmpty(HiddenField1.Value)) { p = new lwg_InstrTitle(); lblNoteAddeditInstrTitle.Text = "Insert error, please try again"; } else { p = pBiz.GetInstrTitleByID(int.Parse(HiddenField1.Value)); lblNoteAddeditInstrTitle.Text = "Update error, please try again"; } if (p != null) { p.Name = txtInstrTitleName.Text; if (drpTitleType.Items.Count > 0) { p.TitleTypeId = int.Parse(drpTitleType.SelectedValue); } if (pBiz.SaveInstrTitle(p)) { BindingInstrTitle(); txtInstrTitleName.Text = string.Empty; pnEditInstrTitle.Visible = false; pnListInstrTitle.Visible = true; return; } } lblNoteAddeditInstrTitle.Visible = true; }
public bool CheckAndInsertInstrTitle(string titleName, int catalogID, int titleTypeID) { try { lwg_InstrTitle lwg = context.lwg_InstrTitle.SingleOrDefault(o => o.Name.ToLower().Equals(titleName.ToLower()) && o.TitleTypeId == titleTypeID); if (lwg == null) { lwg = new lwg_InstrTitle(); lwg.TitleTypeId = titleTypeID; lwg.Name = titleName; CatalogTitleTypeBiz cBiz = new CatalogTitleTypeBiz(); cBiz.SaveInstrTitle(lwg); } if (!context.lwg_CatalogTitle.Any(o => o.CatalogId == catalogID && o.InstrTitleId == lwg.Id)) { lwg_CatalogTitle catalogTitle = new lwg_CatalogTitle(); catalogTitle.CatalogId = catalogID; catalogTitle.InstrTitleId = lwg.Id; context.lwg_CatalogTitle.Add(catalogTitle); context.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }
protected void rptListrInstrTitle_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { lwg_InstrTitle lwg = (lwg_InstrTitle)e.Item.DataItem; Literal ltrTitleType = (Literal)e.Item.FindControl("ltrTitleType"); ltrTitleType.Text = lwg.lwg_TitleType.Name; } }
public bool DeleteInstrTitle(lwg_InstrTitle p) { if (p != null) { List <lwg_CatalogTitle> lst = dbContext.lwg_CatalogTitle.Where(cg => cg.InstrTitleId == p.Id).ToList(); if (lst != null && lst.Count > 0) { dbContext.lwg_CatalogTitle.RemoveRange(lst); } dbContext.lwg_InstrTitle.Remove(p); dbContext.SaveChanges(); return(true); } return(false); }