shzxscmvc/Models/shoppingcart.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using shzxscmvc.Models;
using System.Web.WebPages;

namespace shzxscmvc.Models
{
    public class shoppingcart
    {
        string ShoppingCartId { get; set; }
        shzxscentiti shdb = new shzxscentiti();
        string cartId = HttpContext.Current.User.Identity.Name;

        public string getcartid()
        {
            string cartId = HttpContext.Current.User.Identity.Name;
            return cartId;
        }
        public static shoppingcart GetCart()
        {
            var cart = new shoppingcart();
            cart.ShoppingCartId = HttpContext.Current.User.Identity.Name;
            return cart;
        }

        public void AddItem(int Id, string bass, int quantity)
        {
            
            var cartItem = shdb.carts
                    .SingleOrDefault(c => c.goodsId == Id
                        && c.CartId == cartId);
            if (cartItem == null)
            {                
                cartItem = new cart { CartId = cartId, goodsId = Id, Count = quantity, bassess = bass, DateCreated=DateTime.Now };
                shdb.carts.Add(cartItem);
                
            }
            else
            {
                cartItem.Count += quantity;
            }
            shdb.SaveChanges();
        }

        public int RemoveLine(int goodsId)
        {
            var cartItem = shdb.carts.SingleOrDefault(c => c.CartId == cartId && c.goodsId == goodsId);
            int itemCount = 0;
            if (cartItem != null)
            {
                if (cartItem.Count > 1)
                {
                    cartItem.Count--;
                    itemCount = cartItem.Count;
后面还有 70 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。