예제 #1
0
        public Pass_Log getPassLog(DateTime date, int userId)
        {
            IEnumerable <Pass_Log> pls = myDb.Pass_Log.Where(x => x.U_Id == userId);
            Pass_Log pass = (from passlog in pls
                             where passlog.Date_Purchased.Date == date.Date && passlog.Date_Purchased.TimeOfDay == date.TimeOfDay && passlog.U_Id == userId
                             orderby passlog.Pass_Id
                             select passlog).Single();

            return(pass);
        }
예제 #2
0
 public void CreatePass_Log(Pass_Log pl)
 {
     myDb.Pass_Log.Add(pl);
     myDb.SaveChanges();
 }
예제 #3
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);
        }