Пример #1
0
        public ActionResult Create(SubscriptionPackagesViewModel subscriptionPackages, FormCollection form)
        {
            var packageName     = form["Package"];
            var selectedPackage = db.Packages.Single(package => package.Name.Equals(packageName));
            var pickedDate      = subscriptionPackages.Date;
            var isDateValid     = pickedDate.CompareTo(DateTime.Now) > 0;

            if (!isDateValid)
            {
                pickedDate = DateTime.Now;
            }
            var subscription = new Subscription()
            {
                PackageId = selectedPackage.Id,
                StartDate = pickedDate,
                Validity  = 30
            };

            db.Subscriptions.Add(subscription);
            var userEmail   = User.Identity.Name;
            var currentUser = db.Users.Single(u => u.Email.Equals(userEmail));

            currentUser.SubscriptionId = subscription.Id;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult Create()
        {
            var subscriptionPackages = new SubscriptionPackagesViewModel()
            {
                Subscription = new Subscription(),
                Packages     = db.Packages.ToList()
            };

            return(View(subscriptionPackages));
        }