예제 #1
0
        public void EditDiscount(Discount discount)
        {
            Discount toUpdate = Discounts.FirstOrDefault(d => d.DiscountID == discount.DiscountID);

            toUpdate.Code            = discount.Code;
            toUpdate.StartTime       = discount.StartTime;
            toUpdate.EndTime         = discount.EndTime;
            toUpdate.DiscountPercent = discount.DiscountPercent;
            toUpdate.Title           = discount.Title;
            toUpdate.Description     = discount.Description;

            SaveChanges();
        }
예제 #2
0
        public Discount CreateDiscount(Discount discount)
        {
            int code;

            // generate Discount code and ensure that there's no duplicates
            do
            {
                code = _random.Next(1000, 9999);
            }while (Discounts.FirstOrDefault(d => d.Code == code) != null);
            discount.Code = code;

            Discounts.Add(discount);
            SaveChanges();
            return(discount);
        }