Beispiel #1
0
 public bool SaveReprintSource(lwg_ReprintSource i)
 {
     if (i != null)
     {
         if (i.ReprintSourceId > 0)
         {
             lwg_ReprintSource c = dbContext.lwg_ReprintSource.SingleOrDefault(it => it.ReprintSourceId == i.ReprintSourceId);
             if (c != null)
             {
                 c.Name = i.Name;
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             if (dbContext.lwg_ReprintSource.Count() > 0)
             {
                 i.ReprintSourceId = dbContext.lwg_ReprintSource.OrderByDescending(pe => pe.ReprintSourceId).First().ReprintSourceId + 1;
             }
             else
             {
                 i.ReprintSourceId = 1;
             }
             dbContext.lwg_ReprintSource.Add(i);
         }
         dbContext.SaveChanges();
         return(true);
     }
     return(false);
 }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ReprintSourceBiz  pBiz = new ReprintSourceBiz();
            lwg_ReprintSource p;

            if (string.IsNullOrEmpty(hdfID.Value))
            {
                p            = new lwg_ReprintSource();
                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.SaveReprintSource(p))
                {
                    BindingReprintSource();
                    txtName.Text = string.Empty;
                    pnEditReprintSource.Visible = false;
                    pnListReprintSource.Visible = true;
                    return;
                }
            }
            lblNote.Visible = true;
        }
        protected void rptReprintSource_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            ReprintSourceBiz  pBiz = new ReprintSourceBiz();
            lwg_ReprintSource p    = pBiz.GetByID(int.Parse(e.CommandArgument.ToString()));

            if (e.CommandName.Equals("EDIT"))
            {
                if (p != null)
                {
                    btnAdd.Text   = "Update";
                    txtTitle.Text = "Update Reprint Source";
                    hdfID.Value   = e.CommandArgument.ToString();
                    pnEditReprintSource.Visible = true;
                    pnListReprintSource.Visible = false;
                    txtName.Text = p.Name;
                }
            }
            else if (e.CommandName.Equals("DELETE"))
            {
                if (p != null)
                {
                    if (pBiz.DeleteReprintSource(p))
                    {
                        BindingReprintSource();
                    }
                }
            }
        }
Beispiel #4
0
 public bool DeleteReprintSource(lwg_ReprintSource i)
 {
     if (i != null)
     {
         if (!dbContext.lwg_Catalog.Any(cl => cl.ReprintSourceId == i.ReprintSourceId))
         {
             dbContext.lwg_ReprintSource.Remove(i);
             dbContext.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
Beispiel #5
0
        public bool CheckAndInsertRepringSource(string reprinteSourceName, int catalogID)
        {
            lwg_ReprintSource lwg = dbContext.lwg_ReprintSource.SingleOrDefault(o => o.Name.ToLower().Equals(reprinteSourceName.ToLower()));

            if (lwg == null)
            {
                lwg      = new lwg_ReprintSource();
                lwg.Name = reprinteSourceName;
                SaveReprintSource(lwg);
            }
            if (!dbContext.lwg_ReprintSourceMapping.Any(o => o.CatalogID == catalogID && o.ReprintSourceID == lwg.ReprintSourceId))
            {
                lwg_ReprintSourceMapping reprintSourceMapping = new lwg_ReprintSourceMapping();
                reprintSourceMapping.ReprintSourceID = lwg.ReprintSourceId;
                reprintSourceMapping.CatalogID       = catalogID;
                dbContext.lwg_ReprintSourceMapping.Add(reprintSourceMapping);
                dbContext.SaveChanges();
                return(true);
            }
            return(false);
        }