Пример #1
0
        public async Task <ActionResult> Subscriptions(string studentId)
        {
            if (studentId == null || studentId.Equals(string.Empty))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var model = new StudentSubscriptionViewModel();
            var db    = new ApplicationDbContext();

            model.studentSubscriptions = await
                                             (from us in db.studentSubscriptions
                                             join s in db.subscriptions on us.subscriptionId equals s.id
                                             where us.studentId.Equals(studentId)
                                             select new StudentSubscriptionModel
            {
                id          = us.subscriptionId,
                startDate   = us.startDate,
                endDate     = us.endDate,
                description = s.description,
                regCode     = s.regCode,
                name        = s.name
            }

                                             ).ToListAsync();
            var ids = model.studentSubscriptions.Select(us => us.id);

            model.subscriptions = await db.subscriptions.Where(s => !ids.Contains(s.id)).ToListAsync();

            model.disableDropDown = model.subscriptions.Count.Equals(0);
            model.studentId       = studentId;
            return(View(model));
        }
Пример #2
0
        //[ValidateAntiForgeryToken]

        public async Task <ActionResult> Subscriptions(StudentSubscriptionViewModel model)
        {
            try
            {
                if (model == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                if (ModelState.IsValid)
                {
                    var db = new ApplicationDbContext();
                    db.studentSubscriptions.Add(new StudentSubscription
                    {
                        studentId      = model.studentId,
                        subscriptionId = model.subscriptionId,
                        startDate      = DateTime.Now,
                        endDate        = DateTime.MaxValue
                    });
                    await db.SaveChangesAsync();
                }
            }

            catch { }
            return(RedirectToAction("Subscriptions", "Account", new { studentId = model.studentId }));
        }
Пример #3
0
        public async Task <ActionResult> Subscriptions(string userId)
        {
            if (userId == null || userId.Equals(string.Empty))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var model = new StudentSubscriptionViewModel();
            var db    = new ApplicationDbContext();

            model.StudentSubscriptions = await
                                             (from ss in db.StudentSubscriptions
                                             join s in db.Subscriptions on ss.SubscriptionId equals s.Id
                                             where ss.UserId.Equals(userId)
                                             select new StudentSubscriptionModel
            {
                Id               = ss.SubscriptionId,
                StartDate        = ss.StartDate,
                EndDate          = ss.EndDate,
                Description      = s.Description,
                RegistrationCode = s.RegistrationCode,
                Title            = s.Title
            }).ToListAsync();

            var ids = model.StudentSubscriptions.Select(ss => ss.Id);

            model.Subscriptions = await db.Subscriptions.Where(
                s => !ids.Contains(s.Id)).ToListAsync();

            model.DisableDropDown = model.Subscriptions.Count.Equals(0);
            model.UserId          = userId;
            return(View(model));
        }