public static SpecialOfferProduct AssociateSpecialOfferWithProduct
            ([ContributedAction("Special Offers")] SpecialOffer offer,
            [ContributedAction("Special Offers")] Product product,
            IFunctionalContainer container)
        {
            //First check if association already exists
            IQueryable <SpecialOfferProduct> query = from sop in container.Instances <SpecialOfferProduct>()
                                                     where sop.SpecialOfferID == offer.SpecialOfferID &&
                                                     sop.ProductID == product.ProductID
                                                     select sop;

            if (query.Count() != 0)
            {
                var t = Container.NewTitleBuilder();
                t.Append(offer).Append(" is already associated with").Append(product);
                WarnUser(t.ToString());
                return(null);
            }
            var newSop = new SpecialOfferProduct();

            newSop.SpecialOffer = offer;
            newSop.Product      = product;
            //product.SpecialOfferProduct.Add(newSop);
            Persist(ref newSop);
            return(newSop);
        }
예제 #2
0
        public virtual SpecialOfferProduct BestSpecialOfferProduct(short quantity)
        {
            //reason for testing end date against 1/6/2004 is that in AW database, all offers terminate by 30/6/04
            var query = from obj in Container.Instances <SpecialOfferProduct>()
                        where obj.Product.ProductID == ProductID &&
                        obj.SpecialOffer.StartDate <= DateTime.Now &&
                        obj.SpecialOffer.EndDate >= new DateTime(2004, 6, 1) &&
                        obj.SpecialOffer.MinQty < quantity
                        orderby obj.SpecialOffer.DiscountPct descending
                        select obj;

            SpecialOfferProduct best = query.FirstOrDefault();

            if (best != null)
            {
                return(best);
            }
            SpecialOffer none = SpecialOfferRepository.NoDiscount();

            return(SpecialOfferRepository.AssociateSpecialOfferWithProduct(none, this));
        }
 /// <summary>
 /// Create a new SpecialOfferProduct object.
 /// </summary>
 /// <param name="specialOfferID">Initial value of the SpecialOfferID property.</param>
 /// <param name="productID">Initial value of the ProductID property.</param>
 /// <param name="rowguid">Initial value of the rowguid property.</param>
 /// <param name="modifiedDate">Initial value of the ModifiedDate property.</param>
 public static SpecialOfferProduct CreateSpecialOfferProduct(global::System.Int32 specialOfferID, global::System.Int32 productID, global::System.Guid rowguid, global::System.DateTime modifiedDate)
 {
     SpecialOfferProduct specialOfferProduct = new SpecialOfferProduct();
     specialOfferProduct.SpecialOfferID = specialOfferID;
     specialOfferProduct.ProductID = productID;
     specialOfferProduct.rowguid = rowguid;
     specialOfferProduct.ModifiedDate = modifiedDate;
     return specialOfferProduct;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the SpecialOfferProducts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSpecialOfferProducts(SpecialOfferProduct specialOfferProduct)
 {
     base.AddObject("SpecialOfferProducts", specialOfferProduct);
 }