public ActionResult ViewResults(int id) { JobAlertViewModel jobAlertDetails = _jobAlertService.GetMemeberJobAlert(id).jobAlertViewModelData; string resultsPageUrl = SitefinityHelper.GetPageUrl(this.ResultsPageId); return(Redirect(resultsPageUrl + "?" + ToQueryString(jobAlertDetails))); }
public ActionResult Edit(JobAlertViewModel model) { var statusMessage = "A Job Alert has been updated successfully."; var alertStatus = JobAlertStatus.SUCCESS; List <JobAlertEditFilterRootItem> filtersVMList = GetJobFilterData(); model.Data = JobAlertUtility.ConvertJobAlertViewModelToSearchModel(model, filtersVMList); var response = GetUpsertResponse(model, true); if (!response.Success) { statusMessage = response.Errors.First(); alertStatus = JobAlertStatus.UPDATE_FAILED; } TempData["StatusMessage"] = statusMessage; TempData["StatusCode"] = alertStatus; // Why action name is empty? // Here we need to call Index action, if we are providing action name as Index here // It is appending in the URL, but we dont want to show that in URL. So, sending it as empty // Will definity call defaut action i,.e Index return(RedirectToAction("")); }
public static string ConvertJobAlertViewModelToSearchModel(JobAlertViewModel model, List <JobAlertEditFilterRootItem> filtersVMList) { JobAlertEditFilterRootItem dest = new JobAlertEditFilterRootItem(); if (model.SalaryStringify != null) { model.Salary = JsonConvert.DeserializeObject <JobAlertSalaryFilterReceiver>(model.SalaryStringify); } var alertViewModel = JsonConvert.SerializeObject(model); if (model.Filters != null && model.Filters.Count > 0) { foreach (var rootItem in model.Filters) { if (rootItem != null) { if (filtersVMList != null && filtersVMList.Count > 0) { foreach (var filterVMRootItem in filtersVMList) { if (filterVMRootItem.Name == rootItem.RootId) { if (filterVMRootItem.Filters != null && filterVMRootItem.Filters.Count > 0) { foreach (var filterItem in filterVMRootItem.Filters) { MergeFilters(filterItem, rootItem.Values); } } } } } } } } dynamic searchModel = new ExpandoObject(); searchModel.search = _mapToSearchModel(filtersVMList, model); if (alertViewModel != null) { searchModel.jobAlertViewModelData = JsonConvert.DeserializeObject <JobAlertViewModel>(alertViewModel); } else { searchModel.jobAlertViewModelData = null; } return(JsonConvert.SerializeObject(searchModel)); }
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 IMemberUpsertJobAlertResponse MemberJobAlertUpsert(JobAlertViewModel jobAlertData, bool update = false) { int?memberJobAlertId = null; if (update) { memberJobAlertId = jobAlertData.Id; } IMemberUpsertJobAlertRequest request = new JXTNext_MemberUpsertJobAlertRequest { Name = jobAlertData.Name, DateCreated = jobAlertData.LastModifiedTime, Data = ConvertToSerializeData(jobAlertData), Status = 1, MemberJobAlertId = memberJobAlertId }; IMemberUpsertJobAlertResponse response = _BLconnector.MemberUpsertJobAlert(request); return(response); }
static string ToQueryString(JobAlertViewModel jobAlertDetails) { List <string> queryParamsStringList = new List <string>(); // Encode the URL string // Why replacing single quote with %27? // To be inconsistent with JavaScript encodeURIComponent in the front end. string encodeKeywords = jobAlertDetails.Keywords; if (!encodeKeywords.IsNullOrEmpty()) { encodeKeywords = Uri.EscapeDataString(jobAlertDetails.Keywords).Replace("'", "%27"); } queryParamsStringList.Add("Keywords=" + encodeKeywords); if (jobAlertDetails.Filters != null) { for (int i = 0; i < jobAlertDetails.Filters.Count; i++) { var item = jobAlertDetails.Filters[i]; queryParamsStringList.Add("Filters[" + i + "].rootId=" + item.RootId); if (item.Values != null) { foreach (var filterId in item.Values) { queryParamsStringList.Add("Filters[" + i + "].values=" + filterId); } } } } if (jobAlertDetails.Salary != null && !jobAlertDetails.Salary.TargetValue.IsNullOrEmpty()) { queryParamsStringList.Add("Salary.TargetValue=" + jobAlertDetails.Salary.TargetValue); queryParamsStringList.Add("Salary.LowerRange=" + jobAlertDetails.Salary.LowerRange); queryParamsStringList.Add("Salary.UpperRange=" + jobAlertDetails.Salary.UpperRange); } return(String.Join("&", queryParamsStringList)); }
private string ConvertToSerializeData(JobAlertViewModel jobAlertData) { dynamic data = new ExpandoObject(); if (jobAlertData.Filters != null) { data.Filters = jobAlertData.Filters; } if (jobAlertData.Salary != null) { data.Salary = jobAlertData.Salary; } if (jobAlertData.Keywords != null) { data.Keywords = jobAlertData.Keywords; } data.EmailAlerts = jobAlertData.EmailAlerts; return(JsonConvert.SerializeObject(data)); }
public IMemberUpsertJobAlertResponse MemberJobAlertUpsert(JobAlertViewModel jobAlertData, bool update = false) { int?memberJobAlertId = null; if (update) { memberJobAlertId = jobAlertData.Id; } IMemberUpsertJobAlertRequest request = new JXTNext_MemberUpsertJobAlertRequest { Name = jobAlertData.Name, DateCreated = jobAlertData.LastModifiedTime, Data = jobAlertData.Data, Status = 1, MemberJobAlertId = memberJobAlertId, Email = jobAlertData.Email, EmailNotification = jobAlertData.EmailNotifications }; IMemberUpsertJobAlertResponse response = _BLconnector.MemberUpsertJobAlert(request, SitefinityHelper.IsUserLoggedIn()); return(response); }
private static dynamic _mapToSearchModel(List <JobAlertEditFilterRootItem> filtersVMList, JobAlertViewModel model) { dynamic json = new ExpandoObject(); json.FieldRanges = null; json.FieldSearches = null; json.ClassificationsSearchCriteria = new List <dynamic>(); json.KeywordsSearchCriteria = new List <dynamic>(); var companyFilter = filtersVMList.Where(x => x.Name.ToLower() == CompanyString.ToLower()).FirstOrDefault(); if (companyFilter != null && companyFilter.Filters != null && companyFilter.Filters.Count > 0) { var companyFieldSearch = new List <dynamic>(); foreach (var filter in companyFilter.Filters) { if (filter.Selected) { dynamic company = new ExpandoObject(); company.CompanyId = filter.ID; companyFieldSearch.Add(company); } } if (companyFieldSearch.Count > 0) { json.FieldSearches = companyFieldSearch; } } foreach (var filter in filtersVMList) { var classificationData = _mapToClassificationData(filter, model); if (classificationData != null && filter.Name.ToLower() != CompanyString.ToLower()) { json.ClassificationsSearchCriteria.Add(classificationData); } } if (model.Salary != null) { dynamic classification = new ExpandoObject(); classification.SearchType = RangeString; classification.ClassificationRootName = SalaryString; classification.TargetValue = model.Salary.TargetValue; classification.UpperRange = model.Salary.UpperRange; classification.LowerRange = model.Salary.LowerRange; json.ClassificationsSearchCriteria.Add(classification); } if (model != null && !String.IsNullOrWhiteSpace(model.Keywords)) { model.Keywords.Split(',').ToList().ForEach(x => json.KeywordsSearchCriteria.Add(new { Keyword = x })); } else { json.KeywordsSearchCriteria = null; } return(json); }
private static dynamic _mapToClassificationData(JobAlertEditFilterRootItem filter, JobAlertViewModel model) { if (filter.Name != null && filter.Name.ToLower() != SalaryString.ToLower()) { dynamic classification = new ExpandoObject(); classification.SearchType = CategoryString; classification.ClassificationRootName = filter.Name; var subTargets = filter.Filters .Select(x => MapJobAlertFilterToClassification(x)) .Where(x => x != null) .ToList(); if (subTargets != null && subTargets.Count > 0) { classification.TargetClassifications = subTargets; return(classification); } } return(null); }
public ActionResult Create(JobAlertViewModel model) { List <JobAlertEditFilterRootItem> filtersVMList = GetJobFilterData(); if (model.SalaryStringify != null) { model.Salary = JsonConvert.DeserializeObject <JobAlertSalaryFilterReceiver>(model.SalaryStringify); } if (String.IsNullOrEmpty(model.Email)) { model.Email = SitefinityHelper.GetLoggedInUserEmail(); } model.Data = JobAlertUtility.ConvertJobAlertViewModelToSearchModel(model, filtersVMList); // Create Email Notification EmailNotificationSettings jobAlertEmailNotificationSettings = null; if (this.JobAlertEmailTemplateId != null) { jobAlertEmailNotificationSettings = new EmailNotificationSettings(new EmailTarget(this.JobAlertEmailTemplateSenderName, this.JobAlertEmailTemplateSenderEmailAddress), new EmailTarget(string.Empty, model.Email), SitefinityHelper.GetCurrentSiteEmailTemplateTitle(this.JobAlertEmailTemplateId), SitefinityHelper.GetCurrentSiteEmailTemplateHtmlContent(this.JobAlertEmailTemplateId), 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); } } } model.EmailNotifications = jobAlertEmailNotificationSettings; var response = GetUpsertResponse(model); var stausMessage = "A Job Alert has been created successfully."; var alertStatus = JobAlertStatus.SUCCESS; if (!response.Success) { stausMessage = response.Errors.First(); alertStatus = JobAlertStatus.CREATE_FAILED; } TempData["StatusCode"] = alertStatus; TempData["StatusMessage"] = stausMessage; // Why action name is empty? // Here we need to call Index action, if we are providing action name as Index here // It is appending in the URL, but we dont want to show that in URL. So, sending it as empty // Will definity call defaut action i,.e Index return(RedirectToAction("")); }
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 }); }