コード例 #1
0
        public List<BRAND> Search(BRAND Brand, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, SortDirection SortDirection)
        {
            var result = Context.BRAND.AsQueryable();
            if (Brand != null)
            {
                if (!String.IsNullOrEmpty(Brand.Name))
                {
                    result = result.Where(b => b.Name.Contains(Brand.Name));
                }

                if (!String.IsNullOrEmpty(Brand.ShowName))
                {
                    result = result.Where(b => b.ShowName.Contains(Brand.ShowName));
                }

                if (!String.IsNullOrEmpty(Brand.Description))
                {
                    result = result.Where(b => b.Description.Contains(Brand.Description));
                }

                if (!String.IsNullOrEmpty(Brand.Email))
                {
                    result = result.Where(b => b.Email.Contains(Brand.Email));
                }
            }
            TotalRecords = result.Count();

            GenericSorterCaller<BRAND> sorter = new GenericSorterCaller<BRAND>();
            result = sorter.Sort(result, string.IsNullOrEmpty(OrderExp) ? DEFAULT_ORDER_EXP : OrderExp, SortDirection);

            // pagination
            return result.Skip(PageIndex * PageSize).Take(PageSize).ToList();
        }
コード例 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                //Save Brand
                BRAND br = new BRAND();
                br.Name = txtName.Text;
                br.ShowName = txtShowName.Text;
                br.Website = txt_web.Text;
                br.Telephone = txt_tel.Text;
                br.Email = txtEmail.Text;
                br.Description = txtDesc.Text;
                br.Contact = txt_contact.Text;
                br.Shop = chkShop.Checked;
                br.Address = txtAddress.Text;

                int id = 0;
                lblErrors.Visible = true;
                lblErrors.ForeColor = Color.Green;
                string operation = String.Empty;

                try
                {
                    if (!String.IsNullOrWhiteSpace(ID.Value) && Int32.TryParse(ID.Value, out id) && id != 0)
                    {
                        br.ID = id;
                        ApplicationContext.Current.Brands.Update(br);
                        operation = "updated";
                    }
                    else
                    {
                        ApplicationContext.Current.Brands.Insert(br);
                        operation = "inserted";
                        ID.Value = br.ID.ToString();
                    }
                    lblErrors.Text = "Brand " + operation + " correctly.";
                }
                catch (Exception ex)
                {
                    // TODO log error
                    lblErrors.ForeColor = Color.Red;
                    lblErrors.Text = "Error occurred: " + ex.Message;
                }
            }
        }
コード例 #3
0
        private void FixupBRAND(BRAND previousValue)
        {
            if (previousValue != null && previousValue.CAMPAIGN.Contains(this))
            {
                previousValue.CAMPAIGN.Remove(this);
            }

            if (BRAND != null)
            {
                if (!BRAND.CAMPAIGN.Contains(this))
                {
                    BRAND.CAMPAIGN.Add(this);
                }
                if (BrandID != BRAND.ID)
                {
                    BrandID = BRAND.ID;
                }
            }
        }
コード例 #4
0
 public void Delete(BRAND delBrand)
 {
     Context.BRAND.Attach(delBrand);
     Context.DeleteObject(delBrand);
     //Context.SaveChanges();
 }
コード例 #5
0
 public void DeleteById(int id)
 {
     BRAND obj = new BRAND() { ID = id };
     Delete(obj);
 }
コード例 #6
0
 public void Insert(BRAND newBrand)
 {
     Context.BRAND.AddObject(newBrand);
     //Context.SaveChanges();
 }
コード例 #7
0
 public void Update(BRAND upBrand)
 {
     Context.BRAND.Attach(upBrand);
     Context.ObjectStateManager.ChangeObjectState(upBrand, System.Data.EntityState.Modified);
     //int countRowUpdate = Context.SaveChanges();
 }
コード例 #8
0
     private void FixupBRAND(BRAND previousValue)
     {
         if (previousValue != null && previousValue.CAMPAIGN.Contains(this))
         {
             previousValue.CAMPAIGN.Remove(this);
         }
 
         if (BRAND != null)
         {
             if (!BRAND.CAMPAIGN.Contains(this))
             {
                 BRAND.CAMPAIGN.Add(this);
             }
             if (BrandID != BRAND.ID)
             {
                 BrandID = BRAND.ID;
             }
         }
     }
コード例 #9
0
 public void Delete(BRAND Brand)
 {
     _brandDAO.Delete(Brand);
     Context.SaveChanges();
 }
コード例 #10
0
 public void Update(BRAND Brand)
 {
     _brandDAO.Update(Brand);
     Context.SaveChanges();
 }
コード例 #11
0
 public void Insert(BRAND Brand)
 {
     _brandDAO.Insert(Brand);
     Context.SaveChanges();
 }
コード例 #12
0
 public List<BRAND> Search(BRAND Brand, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection)
 {
     return _brandDAO.Search(Brand, PageSize, PageIndex, out TotalRecords, OrderExp, SortDirection);
 }