コード例 #1
0
        private TblLkpBrandSectionLink UpdateOrDeleteTblLkpBrandSectionLink(TblLkpBrandSectionLink newRow, bool save, int index, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                if (save)
                {
                    context.TblLkpBrandSectionLinks.AddObject(newRow);
                }
                else
                {
                    var oldRow = (from e in context.TblLkpBrandSectionLinks
                                  where e.TblLkpBrandSection == newRow.TblLkpBrandSection &&
                                  e.TblBrand == newRow.TblBrand

                                  select e).SingleOrDefault();
                    if (oldRow != null)
                    {
                        context.DeleteObject(oldRow);
                    }
                }
                context.SaveChanges();
                return(newRow);
            }
        }
コード例 #2
0
        private int FamilyCategory_UpdateOrDeleteTblLkpBrandSectionLink(string brand, int section, bool save)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                if (save)
                {
                    TblLkpBrandSectionLink newRow = new TblLkpBrandSectionLink();
                    newRow.TblBrand           = brand;
                    newRow.TblLkpBrandSection = section;
                    context.TblLkpBrandSectionLinks.AddObject(newRow);
                }
                else
                {
                    //Delete From TblLkpBrandSectionLink
                    var oldBrandSectionRow = (from e in context.TblLkpBrandSectionLinks
                                              where e.TblLkpBrandSection == section &&
                                              e.TblBrand == brand
                                              select e).SingleOrDefault();

                    if (oldBrandSectionRow != null)
                    {
                        context.DeleteObject(oldBrandSectionRow);
                    }
                    context.SaveChanges();

                    //Delete From TblLkpdirectionLink
                    var oldDirectionRow = (from e in context.TblLkpDirectionLinks
                                           where e.TblLkpBrandSection == section &&
                                           e.TblBrand == brand
                                           select e);

                    foreach (var row in oldDirectionRow)
                    {
                        if (row != null)
                        {
                            context.DeleteObject(row);
                        }
                    }
                    context.SaveChanges();

                    //Delete From TblLkpstyleCategoryLink
                    var oldCategoryRow = (from e in context.TblStyleCategoryLinks
                                          where e.TblLkpBrandSection == section &&
                                          e.TblBrand == brand
                                          select e);

                    foreach (var row in oldCategoryRow)
                    {
                        if (row != null)
                        {
                            context.DeleteObject(row);
                        }
                    }
                    context.SaveChanges();

                    //Delete From TblLkpFamilyCategoryLink
                    var oldFamilyRow = (from e in context.TblFamilyCategoryLinks
                                        where e.TblLkpBrandSection == section &&
                                        e.TblBrand == brand
                                        select e);

                    foreach (var row in oldFamilyRow)
                    {
                        if (row != null)
                        {
                            context.DeleteObject(row);
                        }
                    }
                    context.SaveChanges();

                    //Delete From TblLkpFamilyCategoryLink
                    var oldSubFamilyRow = (from e in context.TblSubFamilyCategoryLinks
                                           where e.TblLkpBrandSection == section &&
                                           e.TblBrand == brand
                                           select e);
                    foreach (var row in oldSubFamilyRow)
                    {
                        if (row != null)
                        {
                            context.DeleteObject(row);
                        }
                    }
                    context.SaveChanges();
                }
                return(context.SaveChanges());
            }
        }