Example #1
0
        public async Task AddFavoriteUserAsync(long ownerId, long userId)
        {
            var exists = await ExistsFavoriteUserAsync(ownerId, userId);

            SystemContract.Require(
                !exists,
                "登録済みのお気に入りユーザ, ownerId: {0}, userId: {1}", ownerId.ToString(), userId.ToString()
                );

            /// update statistics data
            //{
            //    var statisticsQuery = _refsContext.RefListStatistics.Where(s => s.RefListId == userId);
            //    var storedRefListStatistics = await statisticsQuery.SingleAsync();

            //    var favCountQuery = _refsContext.Favorites.AsNoTracking();
            //    var favCount = await favCountQuery.CountAsync(s => s.RefListId == userId);
            //    storedRefListStatistics.FavoriteCount = favCount + 1;
            //}

            var fav = FavoriteFactory.CreateForUser(ownerId, userId);

            _refsContext.Favorites.Add(fav);

            await _refsContext.SaveChangesAsync();
        }
        /// <summary>
        /// news a account
        /// </summary>
        /// <param name="favoriteDTO"></param>
        /// <returns></returns>
        public FavoriteDTO AddNewFavorite(FavoriteDTO favoriteDTO)
        {
            //check preconditions
            if (favoriteDTO == null)
            {
                throw new ArgumentException(Messages.warning_CannotAddFavoriteWithEmptyInformation);
            }

            //Create the entity and the required associated data
            var favorite = FavoriteFactory.CreateFavorite(favoriteDTO.AccountId, favoriteDTO.SpecwayId);

            //save entity
            SaveFavorite(favorite);

            //return the data with id and assigned default values
            return(favorite.ProjectedAs <FavoriteDTO>());
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string action = HYRequest.GetQueryString("action");

                UserModel  userInfo = this.LoginUser;
                OrderModel myorder  = OrderFactory.GetCartOrder(userInfo.uid);



                if (action == "addtocart")       //添加到购物车
                {
                    #region ==addtocart==
                    int pid      = HYRequest.GetFormInt("pid", 0);
                    int buycount = HYRequest.GetFormInt("buycount", 0);
                    int itemflag = HYRequest.GetFormInt("itemflag", 0);

                    OrderModel myof = myorder;
                    if (myof == null)
                    {
                        myof              = new OrderModel();
                        myof.orderno      = Utils.GenerateOutTradeNo(this.LoginUser.uid);
                        myof.uid          = userInfo.uid;
                        myof.customername = userInfo.fullname;
                        myof.tel          = userInfo.tel;
                        myof.address      = userInfo.address;
                    }

                    ProductModel p  = ProductFactory.Get(pid);
                    OrderProduct op = new OrderProduct();
                    op.count       = buycount;
                    op.productinfo = p;
                    op.price       = p.price;

                    //判断是否有属性
                    if (itemflag > 0)
                    {
                        int tmpflag = 1;
                        foreach (KeyValuePair <string, decimal> kvp in p.itempricelist)
                        {
                            if (itemflag == tmpflag)
                            {
                                op.item  = kvp.Key;
                                op.price = kvp.Value;
                                break;
                            }
                            tmpflag++;
                        }
                    }

                    CheckIsAdd(myof.productlist, op);

                    if (myorder == null)
                    {
                        OrderFactory.Add(myof);
                    }
                    else
                    {
                        OrderFactory.Update(myof);
                    }

                    string json = "{\"shopcount\":" + myof.productlist.Count + ",\"error\":0}";
                    Response.Write(json);
                    Response.Flush();
                    Response.End();
                    return;

                    #endregion
                }
                else if (action == "addtofav")   //添加到收藏夹
                {
                    #region ==addtofav==
                    int  pid   = HYRequest.GetFormInt("pid", 0);
                    bool isfav = FavoriteFactory.IsFavorite(this.LoginUser.uid, pid);
                    if (!isfav)
                    {
                        FavoriteModel fm = new FavoriteModel();
                        fm.product   = ProductFactory.Get(pid);
                        fm.uid       = this.LoginUser.uid;
                        fm.productid = pid;

                        FavoriteFactory.Add(fm);
                    }
                    string json = "{\"favtip\":\"已收藏\",\"error\":0}";
                    Response.Write(json);
                    Response.Flush();
                    Response.End();
                    return;

                    #endregion
                }
                else if (action == "delfav")     //删除收藏夹
                {
                    int fid = HYRequest.GetFormInt("fid", 0);
                    FavoriteFactory.Delete(fid);
                }
            }
        }