コード例 #1
0
        public async Task <IActionResult> AddSubscription(AddSubscriptionViewModel model)
        {
            string teacherId    = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    subscription = new Subscription
            {
                AppUserId         = model.Student.Id,
                CreatedDatetime   = DateTime.Now,
                CourseId          = model.SelectedCours.Id,
                Period            = model.Month,
                MonthSubscription = true,
                Price             = model.SelectedCours.Price,
            };
            IdentityResult result = await _subscriptionsService.CreateSubscriptionAsync(subscription);

            if (result.Succeeded)
            {
                TempData["SuccessMessage"] = "Абонемент додано";
                return(RedirectToAction(nameof(StudentInfo), new { studentId = model.Student.Id, schoolId = model.SchoolId, model.Month }));
            }
            if (result.Errors.Count() > 0)
            {
                string erorMessage = "";
                foreach (var error in result.Errors)
                {
                    erorMessage += error.Description;
                }
                TempData["ErrorMessage"] = erorMessage;
            }
            return(RedirectToAction(nameof(AddSubscription), new { Id = model.Student.Id, schoolId = model.SchoolId, month = model.Month.ToString() }));
        }
コード例 #2
0
 public ActionResult Add(AddSubscriptionViewModel model)
 {
     if (ModelState.IsValid)
     {
         var user = _dbContext.Users.Single(x => x.Email == WebSecurity.CurrentUserName);
         try
         {
             var userSubscription = _feedsService.AddNewFeed(model.FeedUrl.Trim(), user);
             var successModel     = new UserSubscriptionViewModel
             {
                 Id          = userSubscription.Subscription.Id,
                 SiteUrl     = userSubscription.Subscription.SiteUrl,
                 Title       = userSubscription.Subscription.Title,
                 UnreadItems = userSubscription.Subscription.SubscriptionPosts.Count(y => y.PostsRead == null ||
                                                                                     !y.PostsRead
                                                                                     .Any(z => z.UserSubscription.User.Email == WebSecurity.CurrentUserName &&
                                                                                          z.SubscriptionPost.Id == y.Id))
             };
             var json = JsonConvert.SerializeObject(successModel);
             return(PartialView("_AddSuccess", json));
         }
         catch (BralekTechnicalException ex)
         {
             ModelState.AddModelError(String.Empty, ex.Message);
         }
     }
     return(PartialView("_Add", model));
 }
コード例 #3
0
        public async Task <IActionResult> AddSubscription(string Id, string schoolId, string month)
        {
            DateTime Month;

            DateTime.TryParse(month, out Month);
            if (Month.Year < 2000)
            {
                Month = DateTime.Now;
            }
            IEnumerable <Course> teacherCourses = _courseService.GetTeacherCourses(
                HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier), schoolId, true);
            IEnumerable <string> LastMonthUserCourses = _subscriptionsService.GetLastMonthUserCourseIds(Id);
            string selectedCourseId = teacherCourses.Select(cour => cour.Id).ToList().FirstOrDefault(id => LastMonthUserCourses.Contains(id));

            if (teacherCourses == null && teacherCourses.Where(cour => cour.AllowOneTimePrice == true).Count() == 0)
            {
                TempData["ErrorMessage"] = "У вас немає активних курсів";
                return(RedirectToAction(nameof(StudentInfo), new { studentId = Id, schoolId, Month }));
            }
            AddSubscriptionViewModel model = new AddSubscriptionViewModel
            {
                TeacherCourses   = teacherCourses,
                Month            = Month,
                SchoolId         = schoolId,
                Student          = await _userService.GetUserAsync(Id),
                PaymentTypes     = _paymentService.GetSchoolPaymentTyapes(schoolId),
                SelectedCourseId = selectedCourseId,
            };

            return(View(model));
        }
コード例 #4
0
        public async Task <IActionResult> AddOneTimeSubscription(string schoolId)
        {
            if (string.IsNullOrEmpty(schoolId))
            {
                IEnumerable <School> schools = await SchoolFromContext();

                if (schools.Count() > 1)
                {
                    return(RedirectToAction(nameof(SelectSchool), new { redirectValue = "AddOneTimeSubscription" }));
                }
                if (schools.Count() == 0)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                schoolId = schools.FirstOrDefault().Id;
            }
            IEnumerable <Course> teacherCourses = _courseService.GetTeacherCourses(
                HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier), schoolId, true);

            if (teacherCourses == null || teacherCourses.Where(cour => cour.AllowOneTimePrice == true).Count() == 0)
            {
                TempData["ErrorMessage"] = "У вас немає активних курсів з разовими абонементми";
                return(RedirectToAction(nameof(Index), new { schoolId }));
            }
            AddSubscriptionViewModel model = new AddSubscriptionViewModel()
            {
                TeacherCourses = teacherCourses,
                SchoolId       = schoolId,
                Month          = DateTime.Now,
                PaymentTypes   = _paymentService.GetSchoolPaymentTyapes(schoolId),
            };

            return(View(model));
        }
コード例 #5
0
        public async Task <SubscriptionViewModel> AddSubscription([FromBody] AddSubscriptionViewModel addSubscriptionViewModel)
        {
            var subscription = await readerDataService.AddSubscriptionAsync(User.Identity.Name, addSubscriptionViewModel.FeedUrl);

            var subscriptionViewModel = new SubscriptionViewModel(subscription);

            return(subscriptionViewModel);
        }
コード例 #6
0
        public IActionResult AddSubscription(AddSubscriptionViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                var users = _context.Users.Select(u => new UserDropdownItemViewModel()
                {
                    Name = u.UserName, Id = u.Id
                }).ToList();
                ViewBag.Users = users;
                return(View(vm));
            }

            var user = _context.Users.FirstOrDefault(m => m.Id == vm.MasterUserId);

            if (user == null)
            {
                ModelState.AddModelError("userId", "The specified master user does not exist");
                return(View(vm));
            }

            var subscription = new Subscription()
            {
                StartDate          = vm.StartTime.HasValue ? vm.StartTime.Value : DateTime.Now,
                Expires            = vm.ExpiryTime,
                Revoked            = false,
                RateLimit          = vm.RateLimit,
                AnalysisCap        = vm.AnalysisCap,
                PrimaryContact     = user,
                GroupSubscriptions = vm.Groups.Where(g => !String.IsNullOrEmpty(g.EmailWildcard) && !String.IsNullOrEmpty(g.GroupName))
                                     .Select(g => new GroupSubscription()
                {
                    GroupName     = g.GroupName,
                    EmailWildcard = g.EmailWildcard
                }).ToList()
            };

            _context.Subscriptions.Add(subscription);
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
コード例 #7
0
        public async Task <IActionResult> AddOneTimeSubscription(AddSubscriptionViewModel model)
        {
            IEnumerable <Course> teacherCourses = _courseService.GetTeacherCourses(
                HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier), model.SchoolId, true);

            if (teacherCourses == null || teacherCourses.Where(cour => cour.AllowOneTimePrice == true).Count() == 0)
            {
                TempData["ErrorMessage"] = "У вас немає активних курсів з разовими абонементми";
                return(RedirectToAction(nameof(Index), new { model.SchoolId }));
            }
            model.TeacherCourses = teacherCourses;
            Subscription subscription = new Subscription();

            if (model == null)
            {
                return(RedirectToAction(nameof(AddOneTimeSubscription)));
            }
            if (model.Student == null)
            {
                return(RedirectToAction(nameof(AddOneTimeSubscription)));
            }
            if (string.IsNullOrEmpty(model.Student.FullName) && string.IsNullOrEmpty(model.Student.Id))
            {
                TempData["ErrorMessage"] = "Потрібно вибрати учня ";
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.Student.Id) && (model.Student.FullName.Length < 5))
            {
                TempData["ErrorMessage"] = "Ім'я повинно бути довше 5 символів";
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.SelectedPaymentType))
            {
                TempData["ErrorMessage"] = "Виберіть тип оплати";
                return(View(model));
            }
            if (model.Month.Year < 2000)
            {
                return(RedirectToAction(nameof(AddOneTimeSubscription)));
            }
            if (model.SelectedCours == null || string.IsNullOrEmpty(model.SelectedCours.Id))
            {
                return(RedirectToAction(nameof(AddOneTimeSubscription)));
            }
            if (!string.IsNullOrEmpty(model.Student.Id))
            {
                var student = await _userService.GetUserAsync(model.Student.Id);

                subscription.AppUserId = model.Student.Id;
                subscription.FullName  = student.FullName;
                subscription.Phone     = student.PhoneNumber;
            }
            else if (!string.IsNullOrEmpty(model.Student.FullName))
            {
                subscription.FullName = model.Student.FullName;
                if (!string.IsNullOrEmpty(model.Student.PhoneNumber))
                {
                    subscription.Phone = model.Student.PhoneNumber;
                }
            }
            else
            {
                return(RedirectToAction(nameof(AddOneTimeSubscription)));
            }
            subscription.Id                = Guid.NewGuid().ToString();
            subscription.Period            = model.Month;
            subscription.CourseId          = model.SelectedCours.Id;
            subscription.MonthSubscription = false;
            subscription.CreatedDatetime   = DateTime.Now;
            subscription.Payments          = new List <Payment>
            {
                new Payment
                {
                    DateTime      = DateTime.Now,
                    PaymentTypeId = model.SelectedPaymentType,
                    Price         = model.SelectedCours.Price,
                    PayedToId     = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier),
                },
            };
            subscription.Price = teacherCourses.FirstOrDefault(cour => cour.Id == model.SelectedCours.Id).OneTimePrice;

            IdentityResult result = await _subscriptionsService.CreateSubscriptionAsync(subscription);

            if (result.Succeeded)
            {
                TempData["SuccessMessage"] = "Відвідування додано";
            }
            else if (result.Errors.Count() > 0)
            {
                string erorMessage = "";
                foreach (var error in result.Errors)
                {
                    erorMessage += error.Description;
                }
                TempData["ErrorMessage"] = erorMessage;
            }
            return(RedirectToAction(nameof(Index)));
        }