コード例 #1
0
        /// <summary>
        /// Создать Регистрацию на занятие
        /// </summary>
        /// <param name="lessonRegistrationDto">DTO-объект Регистрации на занятие</param>
        /// <param name="notification">Уведомление о регистрации на занятие</param>
        /// <exception cref="ArgumentNullException">Аргумент содержит null</exception>
        public void CreateLessonRegistration(
            LessonRegistrationCreatingDto lessonRegistrationDto,
            Notification notification = null)
        {
            var mapper = new CreatingDtoToLessonRegistrationMapper();

            LessonRegistration lessonRegistration = mapper.Map(lessonRegistrationDto);
            lessonRegistration.CreatedDate = DateTime.Now;

            _repository.Create(lessonRegistration);
            _repository.Save();

            if (notification != null)
            {
                Task.Run(() => _notificationTransfer.Send(notification));
            }
        }
コード例 #2
0
        /// <summary>
        /// Создать Заявку на занятие
        /// </summary>
        /// <param name="lessonApplicationDto">DTO-объект Заявки на занятие</param>
        /// <param name="notification">Уведомление о новой Заявке на занятие</param>
        /// <exception cref="ArgumentNullException">Аргумент содержит null</exception>
        public void CreateLessonApplication(
            LessonApplicationCreatingDto lessonApplicationDto,
            Notification notification = null)
        {
            if (lessonApplicationDto == null)
                throw new ArgumentNullException("lessonApplicationDto");

            var mapper = new CreatingDtoToLessonApplicationMapper();

            LessonApplication lessonApplication = mapper.Map(lessonApplicationDto);
            lessonApplication.CreatedDate = DateTime.Now;

            _repository.Create(lessonApplication);
            _repository.Save();

            if (notification != null)
            {
                Task.Run(() => _notificationTransfer.Send(notification));
            }
        }
コード例 #3
0
        public PartialViewResult _MakeApplicationToLessonPartial(
            MakeApplicationToLessonViewModel applicationToLessonViewModel)
        {
            applicationToLessonViewModel.Lessons = GetLessonSelectList();

            try
            {
                if (ModelState.IsValid)
                {
                    if (this.VerifyRecaptchaResponse())
                    {
                        var lessonApplicationDto =
                            Mapper.Map<LessonApplicationCreatingDto>(
                                applicationToLessonViewModel);

                        string lessonName = applicationToLessonViewModel.Lessons
                            .FirstOrDefault(l => l.Value == applicationToLessonViewModel.LessonId.ToString())
                            .Text;

                        var notification = new Notification(
                            ConfigurationManager.AppSettings["EmailForNotifications"],
                            Resources.Resource.MakeApplicationToLessonNotificationSubject,
                            String.Format(
                                Resources.Resource.MakeApplicationToLessonNotificationBody,
                                applicationToLessonViewModel.LearnerName,
                                applicationToLessonViewModel.LearnerPhone,
                                applicationToLessonViewModel.LearnerEmail,
                                applicationToLessonViewModel.LearnerCount,
                                lessonName,
                                applicationToLessonViewModel.LessonCount,
                                applicationToLessonViewModel.Comment));

                        lock (_updateLocker)
                        {
                            _managementService.CreateLessonApplication(
                                lessonApplicationDto,
                                notification);
                        }

                        ModelState.Clear();

                        return _MakeApplicationToLessonPartial(
                            applicationToLessonViewModel.LessonId,
                            true);
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, _invalidCaptchaError);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(String.Empty, _generalError);
                _logger.Error(
                    ex,
                    "Не удалось оформить заявку на занятие viewModel='{0}'",
                    applicationToLessonViewModel);
            }

            return PartialView(applicationToLessonViewModel);
        }
コード例 #4
0
        public PartialViewResult _RegisterToLessonPartial(
            RegisterToLessonViewModel registerToLessonViewModel)
        {
            registerToLessonViewModel.Lessons = GetLessonList();

            var selectedLesson = registerToLessonViewModel.Lessons
                .FirstOrDefault(l => l.Id == registerToLessonViewModel.LessonId);

            registerToLessonViewModel.LessonCost = (selectedLesson != null) ?
                selectedLesson.Price :
                0;

            try
            {
                if (ModelState.IsValid)
                {
                    if (this.VerifyRecaptchaResponse())
                    {
                        var lessonRegistrationDto =
                            Mapper.Map<LessonRegistrationCreatingDto>(
                                registerToLessonViewModel);

                        string lessonName = selectedLesson.Name;

                        var notification = new Notification(
                            ConfigurationManager.AppSettings["EmailForNotifications"],
                            Resources.Resource.RegisterToLessonNotificationSubject,
                            String.Format(
                                Resources.Resource.RegisterToLessonNotificationBody,
                                registerToLessonViewModel.LearnerName,
                                registerToLessonViewModel.LearnerPhone,
                                registerToLessonViewModel.LearnerEmail,
                                lessonName,
                                registerToLessonViewModel.LessonDate,
                                registerToLessonViewModel.LessonTime,
                                registerToLessonViewModel.LessonCost,
                                registerToLessonViewModel.Comment));

                        lock (_updateLocker)
                        {
                            _managementService.CreateLessonRegistration(
                                lessonRegistrationDto,
                                notification);
                        }

                        ModelState.Clear();

                        return _RegisterToLessonPartial(
                            registerToLessonViewModel.LessonId,
                            true);
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, _invalidCaptchaError);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(String.Empty, _generalError);
                _logger.Error(
                    ex,
                    "Не удалось выполнить регистрацию на занятие viewModel='{0}'",
                    registerToLessonViewModel);
            }

            return PartialView(registerToLessonViewModel);
        }