Example #1
0
        public void OrderStarted(Entities.Context.Order order)
        {
            var orderDetail = order.OrderDetails.FirstOrDefault(x => !x.IsTestCert);

            if (orderDetail == null)
            {
                return;
            }
            var courseData = orderDetail.Course;
            var groupData  = orderDetail.Group;

            var user        = order.User;
            var managerData = EmployeeService.AllEmployees()[Employees.GetKarpovich()];
            var manager     = H.Anchor("/manager/" + managerData.Employee_TC.ToLower(),
                                       managerData.FullName).AbsoluteHref().ToString();
            var managerPhoto = Images.Employee(managerData.Employee_TC).ToString();

            var userName = user.FullName;
            var template = MailTemplateService.GetTemplate(MailTemplates.OrderStarted, userName);

            var orderDescription = H.Anchor("/course/" + courseData.UrlName.ToLower(),
                                            courseData.GetName()).AbsoluteHref().ToString();
            var certType = string.Empty;

            if (courseData.AuthorizationType_TC == AuthorizationTypes.Microsoft)
            {
                certType = "Международный сертификат Microsoft";
            }
            else
            {
                certType = courseData.CourseCertificates
                           .FirstOrDefault().GetOrDefault(x => x.CertType.CertTypeName);
            }
            if (!certType.IsEmpty())
            {
                certType = " и " + certType;
            }
            var complexInfo = string.Empty;
            var trainerInfo = string.Empty;

            if (groupData != null && groupData.Teacher != null)
            {
                var trainerLink = H.Anchor("/trainer/" +
                                           groupData.Teacher.Employee_TC.ToLower(),
                                           groupData.Teacher.FullName).AbsoluteHref().ToString();
                var complexData = groupData.Complex;
                var complexLink = H.Anchor("/locations/complex/" +
                                           complexData.UrlName, complexData.Name).ToString();

                trainerInfo = "Ваш курс будет вести {0}. {1} <br/> {2}".FormatWith(trainerLink,
                                                                                   StringUtils.GetFirstParagraph(groupData.Teacher.SiteDescription),
                                                                                   H.Anchor("/trainer/{0}/trainer-responses/1".FormatWith(
                                                                                                groupData.Teacher.Employee_TC.ToLower()),
                                                                                            "Отзывы по преподавателю").AbsoluteHref());
                complexInfo = " или непосредственно в учебный комплекс {0} по адресу {1} {2}"
                              .FormatWith(complexLink, complexData.Address,
                                          H.Anchor(Urls.GetComplexMap(complexData.UrlName), "[Схема проезда]"));

                orderDescription += (". Дата начала занятий: {0}. " +
                                     "Место проведения обучения: УК {1}. Дни и часы занятий: {2} {3}").FormatWith(
                    groupData.DateBeg.DefaultString(), complexLink, groupData.DaySequence, groupData.TimeInterval);
            }
            var body = TemplateEngine.GetText(
                template.Description, new {
                orderDescription,
                manager,
                trainerInfo,
                complexInfo,
                managerPhoto,
                certType
            });
            var title = TemplateEngine.GetText(template.Name, new{ UserName = user.FirstSecondName });

            body = StringUtils.AddUtm(body, "email", "email", "unfinished_orders");
            Send(new MailAddress(managerData.FirstSpecEmail), MailAddress(order.User), body, title, websiteManagers);
        }