Exemplo n.º 1
0
        /// <summary>
        /// Make a comment for a product
        /// </summary>
        /// <param name="userID">进行评论的用户</param>
        /// <param name="product">要评论的商品对象</param>
        /// <param name="level">评价的星级</param>
        /// <param name="content">评论的内容</param>
        /// <returns>是否评论成功,成功返回true,否则返回false</returns>
        public static bool CommentProduct(int userID, int productID, EvaluteGrade level, string content)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                ProductCommentItem productComment = new ProductCommentItem();
                productComment.UserID      = userID;
                productComment.ProductID   = productID;
                productComment.Grade       = level;
                productComment.Content     = content;
                productComment.CommentTime = DateTime.Now;
                context.ProductCommentItems.Add(productComment);

                return(context.SaveChanges() > 0);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update user info
        /// </summary>
        /// <param name="user">要更新的用户的ID</param>
        /// <returns>是否成功更新, true:更新成功, false:更新失败</returns>
        public static bool UpdateUserInfo(UserItem user)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                UserItem old = context.UserItems.Find(user.UserID);
                if (old != null)
                {
                    old.UserName = user.UserName;
                    old.Email    = user.Email;
                    return(context.SaveChanges() > 0);
                }

                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a new favorite for user
        /// </summary>
        /// <param name="userID">添加收藏夹项的用户</param>
        /// <param name="productID">添加的商品</param>
        /// <returns>成功收藏返回true,否则返回false</returns>
        public static bool AddNewFavorite(int userID, int productID)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                FavoriteItem favorite = context.FavoriteItems.FirstOrDefault(f => (f.UserID == userID && f.ProductID == productID));
                if (favorite != null)
                {
                    favorite.FavoriteTime = DateTime.Now;
                }
                else
                {
                    context.FavoriteItems.Add(favorite);
                }

                return(context.SaveChanges() > 0);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the paged product list on saling.
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public static List <SaledProductItem> GetPagedSaledProducts(int pageIndex, int pageSize, out int totalCount)
        {
            if (allSaledProducts == null || allSaledProducts.Count == 0)
            {
                using (SolemartDBContext context = new SolemartDBContext())
                {
                    var q = from p in context.SaledProductItems.Include("Product")
                            orderby p.ProductID
                            select p;
                    totalCount       = q.Count();
                    allSaledProducts = q.Skip(pageIndex * pageSize).Take(pageSize).ToList();
                }
            }

            totalCount = allSaledProducts.Count;
            return(allSaledProducts);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shipping the product
        /// </summary>
        /// <param name="productIDs">要出货的商品列表</param>
        /// <returns>出货成功返回true,否则返回false</returns>
        public static bool ShippingProducts(IEnumerable <OrderDetailItem> items)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                foreach (OrderDetailItem item in items)
                {
                    ProductItem product = context.ProductItems.Find(item.ProductID);
                    if (product != null && product.ReserveCount >= item.Amount)
                    {
                        product.ReserveCount -= item.Amount;
                        product.StockCount   -= item.Amount;
                    }
                }

                return(context.SaveChanges() > 0);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Add an image to the product
 /// </summary>
 /// <param name="image"></param>
 /// <returns>是否添加成功</returns>
 public static bool AddNewImageToProduct(ProductImageItem image)
 {
     using (SolemartDBContext context = new SolemartDBContext())
     {
         image.AddTime = DateTime.Now;
         context.ProductImageItems.Add(image);
         if (context.SaveChanges() > 0)
         {
             if (allProductLogoImages != null)
             {
                 allProductLogoImages.Clear();
             }
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 7
0
 public void VendorItemTest()
 {
     using (SolemartDBContext context = new SolemartDBContext())
     {
         context.ClearTableData(typeof(VendorItem));
         VendorItem vendor = new VendorItem {
             VendorName = "vendor_01", Address = "address_01", ContactName = "测试名", Evaluation = "", ExtContent = "", VendorEmail = "*****@*****.**", VendorPhone = "88888888", VendorUrl = "http://test.com"
         };
         context.VendorItems.Add(vendor);
         Assert.IsTrue(context.SaveChanges() > 0);
         vendor = context.VendorItems.Find(1);
         Assert.IsNotNull(vendor);
         Assert.AreEqual <string>("vendor_01", vendor.VendorName);
         Assert.AreEqual <string>("测试名", vendor.ContactName);
         context.ClearTableData(typeof(VendorItem));
         Assert.AreEqual <int>(0, context.VendorItems.Count());
     }
 }
Exemplo n.º 8
0
        /// <summary>更新了品牌的LOGO图片
        /// </summary>
        /// <param name="newBrand">要更新的品牌</param>
        /// <returns>是否更新成功</returns>
        public static bool UpdateBrandItem(BrandItem newBrand)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                BrandItem oldBrand = context.BrandItems.Find(newBrand.BrandID);
                if (oldBrand != null)
                {
                    oldBrand.ZhName      = newBrand.ZhName;
                    oldBrand.EnName      = newBrand.EnName;
                    oldBrand.BrandLogo   = newBrand.BrandLogo;
                    oldBrand.BrandUrl    = newBrand.BrandUrl;
                    oldBrand.Description = newBrand.Description;
                    return(context.SaveChanges() > 0);
                }

                return(false);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Set the username
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public bool SetUserName(string username)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                UserItem tempUserItem = context.UserItems.Find(userItem.UserID);
                if (tempUserItem != null)
                {
                    tempUserItem.UserName = username;
                }

                if (context.SaveChanges() > 0)
                {
                    userItem.UserName = username;
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Modify the the product information
        /// </summary>
        /// <param name="product">The modified product item</param>
        /// <returns>是否修改成功</returns>
        public static bool ModifyProductInfo(ProductItem product)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                ProductItem oldProduct = context.ProductItems.Find(product.ProductID);
                if (oldProduct == null)
                {
                    return(false);
                }

                if (!string.IsNullOrWhiteSpace(product.ProductName))
                {
                    oldProduct.ProductName = product.ProductName;
                }
                if (!string.IsNullOrWhiteSpace(product.Unit))
                {
                    oldProduct.Unit = product.Unit;
                }
                if (!string.IsNullOrWhiteSpace(product.Specification))
                {
                    oldProduct.Specification = product.Specification;
                }
                if (!string.IsNullOrWhiteSpace(product.Description))
                {
                    oldProduct.Description = product.Description;
                }
                if (!string.IsNullOrWhiteSpace(product.ProducingArea))
                {
                    oldProduct.ProducingArea = product.ProducingArea;
                }
                oldProduct.CategoryID = product.CategoryID;

                if (context.SaveChanges() > 0)
                {
                    if (allSaledProducts != null)
                    {
                        allSaledProducts.Clear();
                    }
                    return(true);
                }
                return(false);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Set the username
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool SetEmail(string email)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                UserItem tempUserItem = context.UserItems.Find(userItem.UserID);
                if (tempUserItem != null)
                {
                    tempUserItem.Email = email;
                }

                if (context.SaveChanges() > 0)
                {
                    userItem.Email = email;
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 12
0
        public bool SetBirthDay(DateTime birthDay)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                UserAppendInfoItem tempUserItem = context.UserAppendInfoItems.FirstOrDefault(u => u.UserID == userItem.UserID);
                if (tempUserItem != null)
                {
                    tempUserItem.BirthDay = birthDay;
                }

                if (context.SaveChanges() > 0)
                {
                    userItem.AppendInfo.BirthDay = birthDay;
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Set the user head Image
        /// </summary>
        /// <param name="imgUrl"></param>
        /// <returns></returns>
        public bool SetHeadImage(string imgUrl)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                UserAppendInfoItem tempUserItem = context.UserAppendInfoItems.FirstOrDefault(u => u.UserID == userItem.UserID);
                if (tempUserItem != null)
                {
                    tempUserItem.HeadImageUrl = imgUrl;
                }

                if (context.SaveChanges() > 0)
                {
                    userItem.AppendInfo.HeadImageUrl = imgUrl;
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Add a new qq user
        /// </summary>
        /// <param name="openid">用户名</param>
        /// <returns>成功注册返回新注册的用户对象,否则返回null</returns>
        public static UserItem AddNewQQUser(string openid, string nickname)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                int userid = context.RegisterNewQQUser(nickname, "", "", DateTime.Now);
                if (userid > 0)
                {
                    context.UserAppendInfoItems.Add(new UserAppendInfoItem {
                        UserID = userid, BirthDay = new DateTime(1970, 1, 1), Address = "", Phone = "", Sex = SystemUtil.Sex.Unknown
                    });
                    context.SaveChanges();
                    return(new UserItem {
                        UserID = userid, UserName = nickname, Email = "", Roles = Role.NormalUser.ToString(), LoginType = SystemUtil.LoginType.QQ
                    });
                }

                return(null);
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Delete a image of the product
 /// </summary>
 /// <param name="pid">要删除图片的商品ID</param>
 /// <param name="imageID">删除的图片的ID</param>
 /// <returns>删除成功返回true,否则返回false</returns>
 public static bool DeleteProductImage(int productID, int imageID)
 {
     using (SolemartDBContext context = new SolemartDBContext())
     {
         ProductImageItem image = context.ProductImageItems.FirstOrDefault(i => (i.ProductID == productID && i.ImageID == imageID));
         if (image != null)
         {
             context.ProductImageItems.Remove(image);
             if (context.SaveChanges() > 0)
             {
                 if (allProductLogoImages != null)
                 {
                     allProductLogoImages.Clear();
                 }
                 return(true);
             }
         }
         return(false);
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Take off the product for saling
        /// </summary>
        /// <param name="productID">要下架的商品的ID</param>
        /// <returns>是否下架成功</returns>
        public static bool TakeOffSaling(int productID)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                SaledProductItem saledProductItem = context.SaledProductItems.Find(productID);
                if (saledProductItem != null)
                {
                    context.SaledProductItems.Remove(saledProductItem);
                    if (context.SaveChanges() > 0)
                    {
                        if (allSaledProducts != null)
                        {
                            allSaledProducts.Clear();
                        }
                        return(true);
                    }
                }

                return(false);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Drawback the recommend product.
        /// </summary>
        /// <param name="productID">The product id</param>
        /// <returns></returns>
        public static bool DrawbackTop(int productID)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                SaledProductItem saledProductItem = context.SaledProductItems.Find(productID);
                if (saledProductItem != null)
                {
                    saledProductItem.SetTop = false;
                    if (context.SaveChanges() > 0)
                    {
                        if (allSaledProducts != null)
                        {
                            allSaledProducts.Clear();
                        }
                        return(true);
                    }
                }

                return(false);
            }
        }
Exemplo n.º 18
0
        /// <summary>保存用户的送货地址信息
        /// </summary>
        /// <param name="addressItem">保存的送货地址信息</param>
        /// <returns>保存成功返回true,否则返回false</returns>
        public static bool SaveSendAddressInfoForUser(SendAddressItem addressItem)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                SendAddressItem address = context.SendAddressItems.Find(addressItem.UserID);
                if (address != null)
                {
                    address.Phone       = addressItem.Phone;
                    address.PostCode    = addressItem.PostCode;
                    address.Receiver    = addressItem.Receiver;
                    address.PaymentType = addressItem.PaymentType;
                    address.Address     = addressItem.Address;
                    address.DeliverWay  = addressItem.DeliverWay;
                }
                else
                {
                    context.SendAddressItems.Add(addressItem);
                }

                return(context.SaveChanges() > 0);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Set the user's new address
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public bool SetSex(Sex sex)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                UserAppendInfoItem tempUserItem = context.UserAppendInfoItems.FirstOrDefault(u => u.UserID == userItem.UserID);
                if (tempUserItem != null)
                {
                    tempUserItem.Sex = sex;
                }

                if (context.SaveChanges() > 0)
                {
                    if (userItem.AppendInfo != null)
                    {
                        userItem.AppendInfo.Sex = sex;
                    }
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Generate a new order
        /// </summary>
        /// <param name="orderItem">该订单的产品列表</param>
        /// <returns>return true if success, or false</returns>
        public static bool NewOrder(OrderItem orderItem)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                orderItem.OrderTime = DateTime.Now;
                context.OrderItems.Add(orderItem);

                foreach (OrderDetailItem odi in orderItem.OrderDetails)
                {
                    //要进行订单号关联
                    odi.OrderID = orderItem.OrderID;
                    context.OrderDetailItems.Add(odi);

                    ProductItem product = context.ProductItems.Find(odi.ProductID);
                    if (product != null)
                    {
                        product.ReserveCount += odi.Amount;
                    }
                }

                return(context.SaveChanges() > 0);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Load the category list.
        /// </summary>
        private void LoadCategoryList()
        {
            if (categoryList == null)
            {
                categoryList = new List <CategoryItem>();
            }

            //Clear the list first.
            categoryList.Clear();

            //Save the list get from the DataProvider
            using (SolemartDBContext context = new SolemartDBContext())
            {
                List <CategoryItem> nostackCategoryList = context.CategoryItems.ToList();

                foreach (CategoryItem category in nostackCategoryList)
                {
                    string cate_name = category.CategoryName;

                    if (category.ParentCategoryID == null)
                    {
                        categoryList.Add(category);    //只添加顶级的类别到列表中
                    }

                    //The subcategory auto include.
                    //else
                    //{
                    //    CategoryItem parentCategory = GetCategoryInList(nostackCategoryList, category.ParentCategoryID);
                    //    if (parentCategory.SubCategories == null)
                    //    {
                    //        parentCategory.SubCategories = new List<CategoryItem>();
                    //    }
                    //    parentCategory.SubCategories.Add(category);
                    //}
                }
            }
        }
Exemplo n.º 22
0
 public void DbInitializeTest()
 {
     using (SolemartDBContext context = new SolemartDBContext())
     {
         Assert.IsNotNull(context.AdviserItems);
         Assert.IsNotNull(context.BrandItems);
         Assert.IsNotNull(context.BulletinItems);
         Assert.IsNotNull(context.CartItems);
         Assert.IsNotNull(context.CategoryItems);
         Assert.IsNotNull(context.FavoriteItems);
         Assert.IsNotNull(context.InStockItems);
         Assert.IsNotNull(context.OrderDetailItems);
         Assert.IsNotNull(context.OrderItems);
         Assert.IsNotNull(context.PriceHistoryItems);
         Assert.IsNotNull(context.ProductCommentItems);
         Assert.IsNotNull(context.ProductImageItems);
         Assert.IsNotNull(context.ProductItems);
         Assert.IsNotNull(context.SaledProductItems);
         Assert.IsNotNull(context.SendAddressItems);
         Assert.IsNotNull(context.UserAppendInfoItems);
         Assert.IsNotNull(context.UserItems);
         Assert.IsNotNull(context.VendorItems);
     }
 }
Exemplo n.º 23
0
        /// <summary>用户在QQ登录后的处理
        /// </summary>
        /// <param name="openid">QQ登录使用的openid</param>
        /// <param name="nickname">用户QQ登录的昵称</param>
        /// <returns>登录成功,返回一个用户对象代表当前登录的用户</returns>
        public static UserItem OnQQLogin(string openid, string nickname)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                UserItem user = context.UserItems.FirstOrDefault(u => u.OpenID == openid);
                if (user != null)
                {
                    return(user);
                }
                user           = new UserItem();
                user.OpenID    = openid;
                user.UserName  = nickname;
                user.LoginType = SystemUtil.LoginType.QQ;
                user.RegTime   = DateTime.Now;
                user.Email     = "*****@*****.**";
                context.UserItems.Add(user);
                if (context.SaveChanges() > 0)
                {
                    return(user);
                }

                return(null);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// 使用openID的用户,如微信用户等
        /// </summary>
        /// <param name="openID">The user's openid of third part</param>
        /// <param name="type">The login type</param>
        public SolemartUser(string openID, LoginType type)
        {
            using (SolemartDBContext context = new SolemartDBContext())
            {
                UserItem useritem = context.UserItems.FirstOrDefault(u => (u.LoginType == type && u.OpenID == openID));

                //如果useritem为空,用户曾经登陆过,直接取数据库中的数据
                if (useritem != null)
                {
                    Log.Instance.WriteLog(string.Format("the user[openid:[{0}], type:[{1}]] has login before.", openID, type));
                    this.userItem          = useritem;
                    useritem.LastLoginTime = DateTime.Now;
                    //不管是不是匿名用户,都用购物车
                    cart = GetUserCart();
                    context.SaveChanges();
                }
                else
                {
                    Log.Instance.WriteLog(string.Format("the user[openid:[{0}], type:[{1}]] is first login.", openID, type));
                    this.userItem = new UserItem {
                        OpenID = openID, LoginType = type, Roles = Role.NormalUser.RoleID.ToString(), RegTime = DateTime.Now, LastLoginTime = DateTime.Now
                    };
                    context.UserItems.Add(this.userItem);
                    context.UserAppendInfoItems.Add(new UserAppendInfoItem {
                        UserID = this.userItem.UserID, BirthDay = new DateTime(1970, 1, 1), Address = "", Phone = "", Sex = SystemUtil.Sex.Unknown
                    });
                    cart = new Cart(this);
                    //写入数据库
                    if (context.SaveChanges() <= 0)
                    {
                        Log.Instance.WriteWarn(string.Format("SolemartUser save failed. userid[{0}]", this.userItem.UserID));
                    }
                }
                isAnonymous = false;
            }
        }