public IHttpActionResult GetItems(string projectId = "", string templateId = "")
        {
            try
            {
                if (string.IsNullOrWhiteSpace(projectId))
                {
                    return(Ok());
                }

                return(Ok(_itemManager.GetImportDialogModel(null, projectId)));
            }
            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 <ItemModel> GetItems(string projectId = "", string templateId = "")
        {
            try
            {
                if (string.IsNullOrWhiteSpace(projectId))
                {
                    return(new List <ItemModel>());
                }

                return(_itemManager.GetImportDialogModel(null, projectId));
            }
            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 string Get(string id, string projectId, string db)
        {
            try
            {
                var items           = ImportManager.GetImportDialogModel(id, projectId);
                var importViewModel = new ImportViewModel();
                importViewModel.Languages = GetLanguages(db);

                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var importItem = new ImportListItemViewModel
                        {
                            Id       = item.GcItem.Id,
                            Title    = item.GcItem.Title,
                            Template = new TemplateViewModel
                            {
                                Name = item.GcTemplate.Name,
                                Id   = item.GcTemplate.Id
                            },
                            Status = new StatusViewModel
                            {
                                Color = item.Status.Color,
                                Name  = item.Status.Name,
                                Id    = item.Status.Id
                            },
                            Breadcrumb      = item.Breadcrumb,
                            LastUpdatedInGC = item.GcItem.LastUpdatedInGc
                        };


                        foreach (var availableMapping in item.AvailableMappings.Mappings)
                        {
                            importItem.AvailableMappings.Mappings.Add(new AvailableMappingViewModel
                            {
                                Id    = availableMapping.Id,
                                Title = availableMapping.Title
                            });
                        }

                        importViewModel.Items.Add(importItem);
                    }
                }

                importViewModel.Filters = GetFilters(projectId);

                var model = JsonConvert.SerializeObject(importViewModel);
                return(model);
            }
            catch (WebException exception)
            {
                Log.Error("GatherContent message: " + exception.Message + exception.StackTrace, exception);
                return(exception.Message + " Please check your credentials");
            }
            catch (Exception exception)
            {
                Log.Error("GatherContent message: " + exception.Message + exception.StackTrace, exception);
                return(exception.Message);
            }
        }
Example #4
0
        public void Get(string id, string projectId, string db)
        {
            object resultObject = null;

            try
            {
                var items           = ImportManager.GetImportDialogModel(id, projectId);
                var importViewModel = new ImportViewModel();
                importViewModel.Languages = this.GetLanguages(db);

                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var importItem = new ImportListItemViewModel
                        {
                            Id       = item.GcItem.Id,
                            Title    = item.GcItem.Title,
                            Template = new TemplateViewModel
                            {
                                Name = item.GcTemplate.Name,
                                Id   = item.GcTemplate.Id
                            },
                            Status = new StatusViewModel
                            {
                                Color = item.Status.Color,
                                Name  = item.Status.Name,
                                Id    = item.Status.Id
                            },
                            Breadcrumb      = item.Breadcrumb,
                            LastUpdatedInGC = item.GcItem.LastUpdatedInGc
                        };


                        foreach (var availableMapping in item.AvailableMappings.Mappings)
                        {
                            importItem.AvailableMappings.Mappings.Add(new AvailableMappingViewModel
                            {
                                Id    = availableMapping.Id,
                                Title = availableMapping.Title
                            });
                        }

                        importViewModel.Items.Add(importItem);
                    }
                }

                importViewModel.Filters = this.GetFilters(projectId);

                resultObject = importViewModel;
            }
            catch (WebException exception)
            {
                Log.Error("GatherContent message: " + exception.Message + exception.StackTrace, exception);
                resultObject = new { status = "error", message = exception.Message + " Please check your credentials" };
                //return exception.Message + " Please check your credentials";
            }
            catch (Exception exception)
            {
                Log.Error("GatherContent message: " + exception.Message + exception.StackTrace, exception);
                resultObject = new { status = "error", message = "GatherContent message: " + exception.Message };
                //return exception.Message;
            }
            finally
            {
                Context.Response.Clear();
                Context.Response.ContentType = "application/json";
                JavaScriptSerializer js = new JavaScriptSerializer();
                Context.Response.Write(js.Serialize(resultObject));
            }
        }