當前位置: 首頁>>代碼示例>>C#>>正文


C# Cart.Remove方法代碼示例

本文整理匯總了C#中Cart.Remove方法的典型用法代碼示例。如果您正苦於以下問題:C# Cart.Remove方法的具體用法?C# Cart.Remove怎麽用?C# Cart.Remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cart的用法示例。


在下文中一共展示了Cart.Remove方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RemoveAlbumsFromCart

 private void RemoveAlbumsFromCart(IEnumerable<Guid> productsToRemove, Cart cart)
 {
     foreach (
         var product in productsToRemove.Select(productId => _albumRepository.FindBy(productId)).Where(product => product != null))
     {
         cart.Remove(product);
     }
 }
開發者ID:kduberstein,項目名稱:MvcMusicStore,代碼行數:8,代碼來源:CartService.cs

示例2: Generate

        public void Generate(ChartResultParameter par)
        {
            DateTime begin = DateTime.Now;
            HtmlTemplate index = new HtmlTemplate("index");
            string articlesString = "", cancellationsString = "", depositsString = "";
            string usersString = "";
            double sum = 0.0;

            result.Sales.Sort(par.SortOrder);
            result.Cancellations.Sort(par.SortOrder);

            index.Insert("datetime", DateTime.Now.ToString());
            index.Insert("version", Administration.Properties.Resources.Version);

            #region information
            index.Insert("profile", chart.Profile.Name);
            foreach (User u in chart.Users) usersString += u.Username + "<br />\r\n";
            usersString.Remove(usersString.Length - 8);
            index.Insert("user", usersString);
            index.Insert("cancellationsInvolved", par.InvolveCancellation ? "ja" : "nein");
            index.Insert("deletedArticlesShown", par.ShowDeletedArticles ? "ja" : "nein");
            index.Insert("sortedBy", par.SortOrder.ToString());
            #endregion

            #region articles
            HtmlTemplate articles = new HtmlTemplate("articlecollection");
            articles.Insert("header", "Artikel");
            foreach (ArticleCount ac in result.Sales.Container)
            {
                if (!par.ShowDeletedArticles && ac.Article.IsDeleted) continue;
                if (!par.ShowUnsoldArticles && ac.Count < 1) continue;

                HtmlTemplate tpl = new HtmlTemplate("article");
                tpl.Insert("name", ac.Article.Name);
                tpl.Insert("price", string.Format("{0:0.00 €}", ac.Article.Price));
                tpl.Insert("count", par.InvolveCancellation ?
                                    (ac.Count - result.Cancellations[ac.Article].Count).ToString() :
                                    ac.Count.ToString());
                tpl.Insert("sum", par.InvolveCancellation ?
                    string.Format("{0:0.00 €}", ac.Article.Price * (ac.Count - result.Cancellations[ac.Article].Count)) :
                    string.Format("{0:0.00 €}", ac.Article.Price * ac.Count));
                articlesString += tpl.Get();
            }

            articles.Insert("articles", articlesString);
            articles.Insert("articlescount", par.InvolveCancellation ?
                (result.Sales.Count - result.Cancellations.Count).ToString() :
                result.Sales.Count.ToString());
            sum = par.InvolveCancellation ? (result.Sales.Amount - result.Cancellations.Amount) : result.Sales.Amount;
            articles.Insert("articlessum", string.Format("{0:0.00 €}", sum));

            index.Insert("sales", articles.Get());
            #endregion

            #region deposits
            double depositSum = 0.0;
            int depositCount = 0;
            List<ArticleCount> deps = (from d in result.Sales.Container where d.Article.Deposit.DepositID != -1 select d as ArticleCount).ToList();
            List<ArticleCount> depcancs = (from d in result.Cancellations.Container where d.Article.Deposit.DepositID != -1 select d as ArticleCount).ToList();

            Cart depresult = new Cart();
            foreach (ArticleCount d in deps)
                depresult.Add(d);
            if (par.InvolveCancellation) // remove cancelled deposites
                foreach (ArticleCount d in depcancs)
                    depresult.Remove(d);

            // add returned deposites which are not children of depresult (never bought it, but returned it)
            List<DepositReturn> unbought = (from d in result.DepositReturns
                            where
                                (from a in depresult.Container select a.Article.Deposit).ToList<Deposit>().Contains(d.Deposit) == false
                            select d).ToList();
            foreach (DepositReturn d in unbought)
            {
                int count = d.Count;

                HtmlTemplate tpl = new HtmlTemplate("article");
                tpl.Insert("name", d.Deposit.Name);
                tpl.Insert("price", string.Format("{0:0.00 €}", d.Deposit.Amount));
                tpl.Insert("count", count.ToString());
                tpl.Insert("sum", string.Format("{0:0.00 €}", count * d.Deposit.Amount));

                depositSum -= count * d.Deposit.Amount;
                depositCount -= count;
                depositsString += tpl.Get();
            }

            // enumerate deposit objects
            foreach (ArticleCount d in depresult.Container)
            {
                int count = d.Count;

                // subtract returned deposites
                foreach (DepositReturn dr in (from ret in result.DepositReturns where ret.Deposit.DepositID == d.Article.Deposit.DepositID select ret).ToList())
                {
                    count -= dr.Count;
                }

                HtmlTemplate tpl = new HtmlTemplate("article");
                tpl.Insert("name", d.Article.Deposit.Name);
//.........這裏部分代碼省略.........
開發者ID:fhoner,項目名稱:Kasse,代碼行數:101,代碼來源:HtmlChartCreator.cs


注:本文中的Cart.Remove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。