コード例 #1
0
        public ActionResult Delete(int ItemID)
        {
            Payment Payment = PaymentBusiness.Find(ItemID);

            Payment.Draft        = true;
            Payment.ModifiedDate = DateTime.Now;
            PaymentBusiness.Update(Payment);
            PaymentBusiness.Save();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public ActionResult Subcriber(string cardNumber, string email, string expityMonth, string expityYear, string CV)
        {
            int  n = 0;
            long m = 0;

            if (cardNumber.Length != 12 || !long.TryParse(cardNumber, out m))
            {
                ModelState.AddModelError(string.Empty, "Card's not valid!");
            }
            if (expityMonth.Length > 2 || !int.TryParse(expityMonth, out n) || n > 12 || n < DateTime.Now.Month)
            {
                ModelState.AddModelError(string.Empty, "Month not valid!");
            }
            if (expityYear.Length != 4 || !int.TryParse(expityYear, out n) || n < DateTime.Now.Year)
            {
                ModelState.AddModelError(string.Empty, "Year not valid!");
            }
            if (CV.Length != 3 || !int.TryParse(CV, out n))
            {
                ModelState.AddModelError(string.Empty, "CVG not valid!");
            }
            using (var context = new EgreetingContext())
            {
                if (!context.Set <Subcriber>().Any(x => x.Email.Equals(email)))
                {
                    ModelState.AddModelError(string.Empty, "Subcriber not found!");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(ViewNamesConstant.FrontendPaymentsSubcriber));
            }
            var      listPayment = new List <int>();
            DateTime maxMonth    = DateTime.Now;

            using (var context = new EgreetingContext())
            {
                listPayment = context.Set <Payment>().Where(x => x.EgreetingUser.Email.Equals(email) &&
                                                            x.Draft != true &&
                                                            x.PaymentStatus == false &&
                                                            x.Month >= DateTime.Now.Month &&
                                                            x.Year == DateTime.Now.Year
                                                            ).OrderBy(x => x.Year).ThenBy(x => x.Month).Select(x => x.PaymentID).ToList();
                if (listPayment.Count > 0)
                {
                    var paymentMonthMax = context.Set <Payment>().Where(x => x.EgreetingUser.Email.Equals(email) &&
                                                                        x.Draft != true &&
                                                                        x.PaymentStatus == false &&
                                                                        x.Month >= DateTime.Now.Month &&
                                                                        x.Year == DateTime.Now.Year
                                                                        ).OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).Take(1).FirstOrDefault();
                    maxMonth = new DateTime(paymentMonthMax.Year, paymentMonthMax.Month, 1);
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Subcriber has paid for this month!");
                    return(View(ViewNamesConstant.FrontendPaymentsSubcriber));
                }
            }
            foreach (var id in listPayment)
            {
                var item = PaymentBusiness.Find(id);
                item.PaymentStatus = true;
                item.ModifiedDate  = DateTime.Now;
                item.EgreetingUser.PaymentDueDate = maxMonth.AddMonths(1);
                PaymentBusiness.Update(item);
                PaymentBusiness.Save();
            }
            return(Redirect("/"));
        }