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);
        }
Beispiel #2
0
        public static (SpecialOffer, SpecialOffer) CreateMultipleSpecialOffers(

            string description,
            [Mask("P")] decimal discountPct,
            string type,
            string category,
            int minQty,
            DateTime startDate
            )
        {
            var so = new SpecialOffer() with
            {
                Description = description,
                DiscountPct = discountPct,
                Type        = type,
                Category    = category,
                MinQty      = minQty,
                //Deliberately created non-current so they don't show up
                //in Current Special Offers (but can be viewed via All Special Offers)
                StartDate = startDate,
                EndDate   = new DateTime(2003, 12, 31)
            };

            return(so, so);
        }
        public static SpecialOffer CreateNewSpecialOffer()
        {
            var obj = new SpecialOffer();

            //set up any parameters
            //MakePersistent();
            return(obj);
        }
        public SpecialOffer NoDiscount() {
            if (_noDiscount == null) {
                IQueryable<SpecialOffer> query = from obj in Instances<SpecialOffer>()
                    where obj.SpecialOfferID == 1
                    select obj;

                _noDiscount = query.FirstOrDefault();
            }
            return _noDiscount;
        }
        public SpecialOffer NoDiscount()
        {
            if (_noDiscount == null)
            {
                IQueryable <SpecialOffer> query = from obj in Instances <SpecialOffer>()
                                                  where obj.SpecialOfferID == 1
                                                  select obj;

                _noDiscount = query.FirstOrDefault();
            }
            return(_noDiscount);
        }
 public static SpecialOffer_Edit CreateFrom(SpecialOffer x)
 => new SpecialOffer_Edit
 {
     Category       = x.Category,
     Description    = x.Description,
     DiscountPct    = x.DiscountPct,
     EndDate        = x.EndDate,
     MaxQty         = x.MaxQty,
     MinQty         = x.MinQty,
     SpecialOfferID = x.SpecialOfferID,
     StartDate      = x.StartDate,
     Type           = x.Type
 };
Beispiel #7
0
        public SpecialOfferProduct AssociateSpecialOfferWithProduct(SpecialOffer offer, Product product) {
            //First check if association already exists
            IQueryable<SpecialOfferProduct> query = from sop in Instances<SpecialOfferProduct>()
                                                    where sop.SpecialOfferID == offer.SpecialOfferID &&
                                                          sop.ProductID == product.ProductID
                                                    select sop;

            if (query.Count() != 0) {
                var t = new TitleBuilder();
                t.Append(offer).Append(" is already associated with").Append(product);
                WarnUser(t.ToString());
                return null;
            }
            var newSop = NewTransientInstance<SpecialOfferProduct>();
            newSop.SpecialOffer = offer;
            newSop.Product = product;
            //product.SpecialOfferProduct.Add(newSop);
            Persist(ref newSop);
            return newSop;
        }
        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));
        }
        public static void CreateMultipleSpecialOffers(
            string description,
            [Mask("P")] decimal discountPct,
            string type,
            string category,
            int minQty,
            DateTime startDate
            )
        {
            var so = new SpecialOffer();

            so.Description = description;
            so.DiscountPct = discountPct;
            so.Type        = type;
            so.Category    = category;
            so.MinQty      = minQty;
            //Deliberately created non-current so they don't show up
            //in Current Special Offers (but can be viewed via All Special Offers)
            so.StartDate = startDate;
            so.EndDate   = new DateTime(2003, 12, 31);
            Container.Persist(ref so);
        }
 public static SpecialOffer Updating(SpecialOffer x, [Injected] DateTime now) => x with
 /// <summary>
 /// Deprecated Method for adding a new object to the SpecialOffers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSpecialOffers(SpecialOffer specialOffer)
 {
     base.AddObject("SpecialOffers", specialOffer);
 }
 /// <summary>
 /// Create a new SpecialOffer object.
 /// </summary>
 /// <param name="specialOfferID">Initial value of the SpecialOfferID property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="discountPct">Initial value of the DiscountPct property.</param>
 /// <param name="type">Initial value of the Type property.</param>
 /// <param name="category">Initial value of the Category property.</param>
 /// <param name="startDate">Initial value of the StartDate property.</param>
 /// <param name="endDate">Initial value of the EndDate property.</param>
 /// <param name="minQty">Initial value of the MinQty property.</param>
 /// <param name="rowguid">Initial value of the rowguid property.</param>
 /// <param name="modifiedDate">Initial value of the ModifiedDate property.</param>
 public static SpecialOffer CreateSpecialOffer(global::System.Int32 specialOfferID, global::System.String description, global::System.Decimal discountPct, global::System.String type, global::System.String category, global::System.DateTime startDate, global::System.DateTime endDate, global::System.Int32 minQty, global::System.Guid rowguid, global::System.DateTime modifiedDate)
 {
     SpecialOffer specialOffer = new SpecialOffer();
     specialOffer.SpecialOfferID = specialOfferID;
     specialOffer.Description = description;
     specialOffer.DiscountPct = discountPct;
     specialOffer.Type = type;
     specialOffer.Category = category;
     specialOffer.StartDate = startDate;
     specialOffer.EndDate = endDate;
     specialOffer.MinQty = minQty;
     specialOffer.rowguid = rowguid;
     specialOffer.ModifiedDate = modifiedDate;
     return specialOffer;
 }
Beispiel #13
0
 public static SpecialOffer_Edit CreateNewSpecialOffer(this SpecialOffer x)
 {
     return(SpecialOffer_EditFunctions.CreateFrom(x));
 }