public List <ModelBookStore.UserItem> Search(ModelBookStore.UserItem objModelUserItem)
        {
            var UserItemlist = (from objItems in TBSEntities.UserItems
                                where objItems.id == objModelUserItem.id && objItems.UserId == objModelUserItem.UserId
                                select objItems
                                //select new Role { id = objItems.id, UserId = objItems.Name }
                                ).ToList();

            ModelBookStore.UserItem        ModlelUsertemObj;
            List <ModelBookStore.UserItem> objlist = new List <ModelBookStore.UserItem>();

            foreach (var Useritem in UserItemlist)
            {
                ModlelUsertemObj                = new ModelBookStore.UserItem();
                ModlelUsertemObj.id             = Useritem.id;
                ModlelUsertemObj.UserId         = Convert.ToInt32(Useritem.UserId);
                ModlelUsertemObj.ItemId         = Convert.ToInt32(Useritem.ItemId);
                ModlelUsertemObj.DateOfPurchase = Convert.ToDateTime(Useritem.DateOfPurchase);
                ModlelUsertemObj.NoOfItems      = Convert.ToInt32(Useritem.NoOfItems);



                objlist.Add(ModlelUsertemObj);
            }

            return(objlist);
        }
        public void Delete(ModelBookStore.UserItem objModelUserItem)
        {
            UserItem _SelectUserItemToDeleteRow = TBSEntities.UserItems.Where(x => x.id == objModelUserItem.id).Select(x => x).FirstOrDefault();

            TBSEntities.UserItems.Remove(_SelectUserItemToDeleteRow);
            TBSEntities.SaveChanges();
        }
        public void Add(ModelBookStore.UserItem objModelUserItem)
        {
            UserItem objUserItem = new UserItem()
            {
                UserId         = objModelUserItem.UserId,
                DateOfPurchase = objModelUserItem.DateOfPurchase,
                ItemId         = objModelUserItem.ItemId,
                NoOfItems      = objModelUserItem.NoOfItems,
                DiscAmmount    = objModelUserItem.DiscAmmount,
                NetAmount      = objModelUserItem.NetAmount
            };

            TBSEntities.UserItems.Add(objUserItem);
            TBSEntities.SaveChanges();
        }
        public List <ModelBookStore.UserItem> Load()
        {
            var UserItemlist = (from objUserItems in TBSEntities.UserItems
                                join objCustomer in TBSEntities.UserDetails on objUserItems.UserId equals objCustomer.id
                                join objItem in TBSEntities.Items on objUserItems.ItemId equals objItem.id

                                // select objUserItems
                                select new
            {
                id = objUserItems.id,
                UserId = objUserItems.UserId,
                ItemId = objUserItems.ItemId,
                CustomerName = objCustomer.FirstName,
                ItemName = objItem.Name,
                DateOfPurchase = objUserItems.DateOfPurchase,

                NoOfItems = objUserItems.NoOfItems,
                DiscAmmount = objUserItems.DiscAmmount,
                NetAmount = objUserItems.NetAmount
            }
                                ).ToList();

            ModelBookStore.UserItem        ModlelUsertemObj;
            List <ModelBookStore.UserItem> objlist = new List <ModelBookStore.UserItem>();

            foreach (var UseritemLst in UserItemlist)
            {
                ModlelUsertemObj                = new ModelBookStore.UserItem();
                ModlelUsertemObj.id             = UseritemLst.id;
                ModlelUsertemObj.UserId         = Convert.ToInt32(UseritemLst.UserId);
                ModlelUsertemObj.ItemId         = Convert.ToInt32(UseritemLst.ItemId);
                ModlelUsertemObj.CustomerName   = UseritemLst.CustomerName;
                ModlelUsertemObj.ItemName       = UseritemLst.ItemName;
                ModlelUsertemObj.DateOfPurchase = Convert.ToDateTime(UseritemLst.DateOfPurchase);
                ModlelUsertemObj.NoOfItems      = Convert.ToInt32(UseritemLst.NoOfItems);
                ModlelUsertemObj.DiscAmmount    = Convert.ToDecimal(UseritemLst.DiscAmmount);
                ModlelUsertemObj.NetAmount      = Convert.ToDecimal(UseritemLst.NetAmount);


                objlist.Add(ModlelUsertemObj);
            }

            return(objlist);
        }
        public void Update(ModelBookStore.UserItem objModelUserItem)
        {
            UserItem _SelectUserItemrow = TBSEntities.UserItems.Where(x => x.id == objModelUserItem.id).Select(x => x).FirstOrDefault();

            if (_SelectUserItemrow == null)
            {
                Add(objModelUserItem);
            }

            else
            {
                _SelectUserItemrow.ItemId         = objModelUserItem.ItemId;
                _SelectUserItemrow.UserId         = objModelUserItem.UserId;
                _SelectUserItemrow.DateOfPurchase = objModelUserItem.DateOfPurchase;
                _SelectUserItemrow.DiscAmmount    = objModelUserItem.DiscAmmount;
                _SelectUserItemrow.NetAmount      = objModelUserItem.NetAmount;
                _SelectUserItemrow.NoOfItems      = objModelUserItem.NoOfItems;

                TBSEntities.SaveChanges();
            }
        }