public IHttpActionResult GetAvailableTemplates() { try { return(Ok(_mappingManager.GetAvailableTemplates())); } catch (WebException exception) { LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception); return(BadRequest(exception.Message + " Please check your credentials")); } catch (Exception exception) { LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception); return(BadRequest(exception.Message)); } }
public List <CmsTemplateModel> GetAvailableTemplates() { try { return(_mappingManager.GetAvailableTemplates()); } catch (WebException exception) { LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception); throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception.Message + " Please check your credentials")); } catch (Exception exception) { LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception); throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception.Message)); } }
public ActionResult GetMapping(string gcTemplateId, string scMappingId) { try { var mappingModel = MappingManager.GetSingleMappingModel(gcTemplateId, scMappingId); var model = new TemplateMapViewModel { ScMappingId = mappingModel.MappingId, }; if (mappingModel.GcProject != null) { model.GcProjectId = mappingModel.GcProject.Id; model.GcProjectName = mappingModel.GcProject.Name; } var addMappingModel = new AddMappingViewModel { DefaultLocationTitle = mappingModel.DefaultLocationTitle, DefaultLocation = mappingModel.DefaultLocationId, GcMappingTitle = mappingModel.MappingTitle, OpenerId = "drop-tree" + Guid.NewGuid(), }; if (mappingModel.GcTemplate != null) { model.GcTemplateName = mappingModel.GcTemplate.Name; addMappingModel.GcTemplateId = mappingModel.GcTemplate.Id; } if (mappingModel.CmsTemplate != null) { addMappingModel.SelectedTemplateId = mappingModel.CmsTemplate.Id; } model.AddMappingModel = addMappingModel; foreach (var fieldMapping in mappingModel.FieldMappings) { model.SelectedFields.Add(new FieldMappingViewModel { SitecoreTemplateId = fieldMapping.CmsTemplateId, GcFieldId = fieldMapping.GcFieldId }); } #region Available templates var sitecoreTemplates = new List <SitecoreTemplateViewModel>(); var defaultTemplate = new SitecoreTemplateViewModel { SitrecoreTemplateName = "Select sitecore template *", SitrecoreTemplateId = "0", }; defaultTemplate.SitecoreFields.Add(new SitecoreTemplateField { SitecoreFieldId = "0", SitrecoreFieldName = "Do not map" }); sitecoreTemplates.Add(defaultTemplate); var availableCmsTemplates = MappingManager.GetAvailableTemplates(); foreach (var template in availableCmsTemplates) { var st = new SitecoreTemplateViewModel { SitrecoreTemplateId = template.Id, SitrecoreTemplateName = template.Name }; st.SitecoreFields.Add(new SitecoreTemplateField { SitecoreFieldId = "0", SitrecoreFieldName = "Do not map", }); foreach (var field in template.Fields) { st.SitecoreFields.Add(new SitecoreTemplateField { SitecoreFieldId = field.Id, SitrecoreFieldName = field.Name, SitecoreFieldType = field.Type }); } sitecoreTemplates.Add(st); } model.SitecoreTemplates = sitecoreTemplates; #endregion model.Rules = GetMapRules(); model.GcProjects.Add(new ProjectViewModel { Id = "0", Name = "Select project *" }); var projects = MappingManager.GetAllGcProjects(); foreach (var project in projects) { model.GcProjects.Add(new ProjectViewModel { Id = project.Id, Name = project.Name }); } if (string.IsNullOrEmpty(gcTemplateId) && string.IsNullOrEmpty(scMappingId)) { model.IsEdit = false; } else { model.IsEdit = true; } return(Json(model, JsonRequestBehavior.AllowGet)); } catch (WebException exception) { Log.Error("GatherContent message: " + exception.Message + exception.StackTrace, exception); return(Json(new { status = "error", message = exception.Message + " Please check your credentials" }, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { Log.Error("GatherContent message: " + exception.Message + exception.StackTrace, exception); return(Json(new { status = "error", message = exception.Message }, JsonRequestBehavior.AllowGet)); } }