コード例 #1
0
 public static ShoppingItem Load(WishList wishList)
 {
     ShoppingItem shoppingItem = new ShoppingItem();
     shoppingItem.ProductEntity = wishList.Product;
     shoppingItem.DurationInMonths = wishList.Duration;
     shoppingItem.Quantity = wishList.Quantity;
     shoppingItem.WishListItemId = wishList.WishListID;
     shoppingItem.VersionEntity =  wishList.Version;
     shoppingItem.ProductDetailEntity = wishList.ProductDetail;
     return shoppingItem;
 }
コード例 #2
0
 /// <summary>
 /// Create a new WishList object.
 /// </summary>
 /// <param name="wishListID">Initial value of the WishListID property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 /// <param name="productID">Initial value of the ProductID property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="duration">Initial value of the Duration property.</param>
 public static WishList CreateWishList(global::System.Int32 wishListID, global::System.Int32 userID, global::System.Int32 productID, global::System.Int32 quantity, global::System.Int32 duration)
 {
     WishList wishList = new WishList();
     wishList.WishListID = wishListID;
     wishList.UserID = userID;
     wishList.ProductID = productID;
     wishList.Quantity = quantity;
     wishList.Duration = duration;
     return wishList;
 }
コード例 #3
0
        protected void rptItems_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName.Equals("Remove"))
            {
                List<ShoppingItem> trolley = GetShoppingTrolley();
                trolley.RemoveAt(int.Parse(e.CommandArgument.ToString()));
                Session[WebConstants.Session.TROLLEY] = trolley;
                BindRepeater();
            }
            else if (e.CommandName.Equals("Save"))
            {
                if (LoggedIsUser != null)
                {
                    try
                    {
                        int index = int.Parse(e.CommandArgument.ToString());
                        ShoppingItem currentItem = GetShoppingTrolley()[index];
                        //Save record for current user

                        WishList wishList = null;
                        if (currentItem.ProductDetailEntity != null)
                        {
                            wishList = (from wl in DatabaseContext.WishLists
                                        where wl.UserID == LoggedIsUser.UserID
                                        && wl.ProductID == currentItem.ProductEntity.ProductID
                                        && wl.ProductDetailID == currentItem.ProductDetailEntity.ProductDetailID
                                        && wl.VersionID == currentItem.VersionEntity.VersionID
                                        select wl).FirstOrDefault();
                        }
                        else
                        {
                            wishList = (from wl in DatabaseContext.WishLists
                                        where wl.UserID == LoggedIsUser.UserID
                                        && wl.ProductID == currentItem.ProductEntity.ProductID
                                        && wl.ProductDetailID == null
                                        && wl.VersionID == currentItem.VersionEntity.VersionID
                                        select wl).FirstOrDefault();
                        }

                        if (wishList != null)
                        {
                            wishList.Quantity += currentItem.Quantity;
                            DatabaseContext.SaveChanges();
                        }
                        else
                        {
                            wishList = new WishList();
                            wishList.Duration = currentItem.DurationInMonths;
                            if (currentItem.ProductDetailEntity != null)
                            {
                                wishList.ProductDetailID = currentItem.ProductDetailEntity.ProductDetailID;
                            }
                            wishList.ProductID = currentItem.ProductEntity.ProductID;
                            wishList.Quantity = currentItem.Quantity;
                            wishList.UserID = LoggedIsUser.UserID;
                            wishList.VersionID = currentItem.VersionEntity.VersionID;

                            DatabaseContext.AddToWishLists(wishList);
                            DatabaseContext.SaveChanges();
                        }
                        GetShoppingTrolley().RemoveAt(index);
                        SetSuccessMessage("Item successfully added to your wishlist");
                        BindRepeater();
                    }
                    catch (FormatException ex)
                    {
                        SetErrorMessage("Quantity must be integer");
                    }
                }
                else
                {
                    RedirectToLogin();
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the WishLists EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToWishLists(WishList wishList)
 {
     base.AddObject("WishLists", wishList);
 }