Exemplo n.º 1
0
        private IMemberUpsertJobAlertResponse GetUpsertResponse(JobAlertViewModel model, bool update = false)
        {
            JobAlertSalaryFilterReceiver salary = null;

            if (!model.SalaryStringify.IsNullOrEmpty())
            {
                salary = JsonConvert.DeserializeObject <JobAlertSalaryFilterReceiver>(model.SalaryStringify);
            }

            if (salary != null)
            {
                model.Salary = salary;
            }

            var epochTime = ConversionHelper.GetUnixTimestamp(SitefinityHelper.GetSitefinityApplicationTime(), true);

            model.LastModifiedTime = (long)epochTime;

            // Remove null value filters
            List <JobAlertFilters> Filters = new List <JobAlertFilters>();

            if (model != null && model.Filters != null && model.Filters.Count > 0)
            {
                foreach (var item in model.Filters)
                {
                    if (item.Values != null && item.Values.Count > 0)
                    {
                        Filters.Add(item);
                    }
                }
            }

            model.Filters = Filters;

            if (model != null && model.Email.IsNullOrEmpty())
            {
                model.Email = SitefinityHelper.GetLoggedInUserEmail();
            }

            var response = _jobAlertService.MemberJobAlertUpsert(model, update);

            return(response);
        }
        public JsonResult CreateAnonymousJobAlert(JobSearchResultsFilterModel filterModel, string email)
        {
            string  alertName   = String.Empty;
            var     jsonData    = JsonConvert.SerializeObject(filterModel);
            dynamic searchModel = new ExpandoObject();
            var     jsonModel   = _mapToCronJobJsonModel(filterModel);

            searchModel.search = jsonModel.search;
            // Creating the job alert model
            JobAlertViewModel alertModel = new JobAlertViewModel()
            {
                Filters = new List <JobAlertFilters>(),
                Salary  = new JobAlertSalaryFilterReceiver(),
                Email   = email
            };



            if (filterModel != null)
            {
                // Keywords
                alertModel.Keywords = filterModel.Keywords;
                if (!alertModel.Keywords.IsNullOrEmpty())
                {
                    alertName = alertModel.Keywords;
                }

                // Filters
                if (filterModel.Filters != null && filterModel.Filters.Count() > 0)
                {
                    List <JobAlertFilters> alertFilters = new List <JobAlertFilters>();
                    bool flag = false;
                    for (int i = 0; i < filterModel.Filters.Count(); i++)
                    {
                        var filter = filterModel.Filters[i];
                        if (filter != null && filter.values != null && filter.values.Count > 0)
                        {
                            JobAlertFilters alertFilter = new JobAlertFilters
                            {
                                RootId = filter.rootId,
                                Values = new List <string>()
                            };

                            foreach (var filterItem in filter.values)
                            {
                                if (!flag && alertName.IsNullOrEmpty())
                                {
                                    flag      = true;
                                    alertName = filter.values.Count.ToString() + " " + filter.rootId;
                                }

                                JobSearchResultsFilterModel.ProcessFilterLevelsToFlat(filterItem, alertFilter.Values);
                            }

                            alertFilters.Add(alertFilter);
                        }
                    }

                    alertModel.Filters = alertFilters;
                }

                // Salary
                if (filterModel.Salary != null)
                {
                    alertModel.Salary.RootName    = filterModel.Salary.RootName;
                    alertModel.Salary.TargetValue = filterModel.Salary.TargetValue;
                    alertModel.Salary.LowerRange  = filterModel.Salary.LowerRange;
                    alertModel.Salary.UpperRange  = filterModel.Salary.UpperRange;

                    if (alertName.IsNullOrEmpty())
                    {
                        alertName = "Salary from" + alertModel.Salary.LowerRange.ToString() + " to " + alertModel.Salary.UpperRange.ToString();
                    }
                }
            }

            if (alertName.IsNullOrEmpty())
            {
                alertName = "All search";
            }

            alertModel.Name = alertName;
            searchModel.jobAlertViewModelData = alertModel;
            alertModel.Data = JsonConvert.SerializeObject(searchModel);

            // Code for sending email alerts
            EmailNotificationSettings jobAlertEmailNotificationSettings = null;

            if (JobAlertEmailTemplateId != null)
            {
                jobAlertEmailNotificationSettings = new EmailNotificationSettings(new EmailTarget(this.JobAlertEmailTemplateSenderName, this.JobAlertEmailTemplateSenderEmailAddress),
                                                                                  new EmailTarget(string.Empty, email),
                                                                                  this.GetJobAlertHtmlEmailTitle(),
                                                                                  this.GetJobAlertHtmlEmailContent(), null);
                if (!this.JobAlertEmailTemplateCC.IsNullOrEmpty())
                {
                    foreach (var ccEmail in this.JobAlertEmailTemplateCC.Split(';'))
                    {
                        jobAlertEmailNotificationSettings.AddCC(String.Empty, ccEmail);
                    }
                }

                if (!this.JobAlertEmailTemplateBCC.IsNullOrEmpty())
                {
                    foreach (var bccEmail in this.JobAlertEmailTemplateBCC.Split(';'))
                    {
                        jobAlertEmailNotificationSettings.AddBCC(String.Empty, bccEmail);
                    }
                }
            }


            alertModel.EmailNotifications = jobAlertEmailNotificationSettings;


            var response = _jobAlertService.MemberJobAlertUpsert(alertModel);

            return(new JsonResult {
                Data = response
            });
        }