예제 #1
0
 public bool SaveSeries(lwg_Series p)
 {
     if (p != null)
     {
         if (p.SeriesId > 0)
         {
             lwg_Series c = dbContext.lwg_Series.SingleOrDefault(ht => ht.SeriesId == p.SeriesId);
             if (c != null)
             {
                 c.Name = p.Name;
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             if (dbContext.lwg_Series.Count() > 0)
             {
                 p.SeriesId = dbContext.lwg_Series.OrderByDescending(pe => pe.SeriesId).First().SeriesId + 1;
             }
             else
             {
                 p.SeriesId = 1;
             }
             dbContext.lwg_Series.Add(p);
         }
         dbContext.SaveChanges();
         return(true);
     }
     return(false);
 }
예제 #2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            SeriesBiz  pBiz = new SeriesBiz();
            lwg_Series p;

            if (string.IsNullOrEmpty(hdfID.Value))
            {
                p            = new lwg_Series();
                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.SaveSeries(p))
                {
                    rptSeries.DataSource = pBiz.GetListSeries();
                    rptSeries.DataBind();
                    txtName.Text         = string.Empty;
                    pnEditSeries.Visible = false;
                    pnListSeries.Visible = true;
                    return;
                }
            }
            lblNote.Visible = true;
        }
예제 #3
0
        protected void rptSeries_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            SeriesBiz  pBiz = new SeriesBiz();
            lwg_Series p    = pBiz.GetByID(int.Parse(e.CommandArgument.ToString()));

            if (e.CommandName.Equals("EDIT"))
            {
                if (p != null)
                {
                    btnAdd.Text          = "Update";
                    txtTitle.Text        = "Update Series";
                    hdfID.Value          = e.CommandArgument.ToString();
                    pnEditSeries.Visible = true;
                    pnListSeries.Visible = false;
                    txtName.Text         = p.Name;
                }
            }
            else if (e.CommandName.Equals("DELETE"))
            {
                if (p != null)
                {
                    if (pBiz.DeleteSeries(p))
                    {
                        BindingSeries();
                    }
                }
            }
        }
예제 #4
0
 public bool DeleteSeries(lwg_Series p)
 {
     if (p != null)
     {
         if (!dbContext.lwg_Catalog.Any(cl => cl.SeriesId == p.SeriesId))
         {
             dbContext.lwg_Series.Remove(p);
             dbContext.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
예제 #5
0
        public bool CheckAndInsertSeries(string seriesName, int catalogID)
        {
            lwg_Series lwg = dbContext.lwg_Series.SingleOrDefault(o => o.Name.ToLower().Equals(seriesName.ToLower()));

            if (lwg == null)
            {
                lwg      = new lwg_Series();
                lwg.Name = seriesName;
                SaveSeries(lwg);
            }
            if (!dbContext.lwg_SeriesMapping.Any(o => o.CatalogID == catalogID && o.SeriesID == lwg.SeriesId))
            {
                lwg_SeriesMapping seriesMapping = new lwg_SeriesMapping();
                seriesMapping.CatalogID = catalogID;
                seriesMapping.SeriesID  = lwg.SeriesId;
                dbContext.lwg_SeriesMapping.Add(seriesMapping);
                dbContext.SaveChanges();
                return(true);
            }
            return(false);
        }