Beispiel #1
0
 public void CreatePromotion(Promotion p)
 {
     myDb.Promotions.Add(p);
     myDb.SaveChanges();
 }
Beispiel #2
0
        public Pass_Log processPurchase(Class_Passes pass, int userId, string purchaseType)
        {
            Pass_Log pass_Log = new Pass_Log();



            Promotion p = getPromotionByPassId(pass.Pass_Id);


            pass_Log.Pass_Id         = pass.Pass_Id;
            pass_Log.U_Id            = userId;
            pass_Log.Purchase_Method = purchaseType;

            int token;

            if (p != null)
            {
                if (p.Num_Classes == 0)
                {
                    token = pass.Pass_Size;
                    pass_Log.Num_Classes = token;
                }
                else
                {
                    token = pass.Pass_Size + (int)p.Num_Classes;
                    pass_Log.Num_Classes = token;
                }


                if (p.Discount == 0)
                {
                    pass_Log.Purchase_Price = decimal.Round(pass.Pass_Price * (decimal)1.15, 2);
                }
                else
                {
                    decimal subtotal = decimal.Round((pass.Pass_Price - (pass.Pass_Price * (decimal)p.Discount)), 2);

                    pass_Log.Purchase_Price = decimal.Round((subtotal * (decimal)1.15), 2);
                }
            }
            else
            {
                token = pass.Pass_Size;
                pass_Log.Num_Classes    = token;
                pass_Log.Purchase_Price = decimal.Round(pass.Pass_Price * (decimal)1.15, 2);
            }

            AddTokens(userId, token);
            DateTime date = DateTime.Now;

            pass_Log.Date_Purchased = date;


            CreatePass_Log(pass_Log);

            string purchaseDateTime = date.ToString("dd/MM/yyyy HH:mm:ss");
            string purchaseDate     = date.ToString("ddMMyy");

            Pass_Log pl = getPassLog(date, userId);

            string invoiceNumber = userId.ToString() + pl.Pass_Log_Id;

            pl.Invoice_Number = Int32.Parse(invoiceNumber);

            myDb.SaveChanges();

            return(pl);
        }