public string AddCollection(Models.Collection collection)
        {
            string result = string.Empty;
            AddCollectionRequest request = new AddCollectionRequest
            {
                Collection = new EchoService.DataContracts.Collection
                {
                    ID          = collection.ID,
                    Description = collection.Description,
                    IsPrivate   = collection.IsPrivate,
                    Title       = collection.Title
                }
            };

            using (EchoCollectionClient client = new EchoCollectionClient())
            {
                if (collection.ID == 0)
                {
                    client.SaveCollection(request);
                }
                else
                {
                    client.UpdateCollection(request);
                }
            }

            // TODO: Save to database
            return(string.Format("Collection {0} successfully added", result));
        }
        public GetDocumentTypeResponse GetDocTypes()
        {
            GetDocumentTypeResponse response = new GetDocumentTypeResponse();

            using (var client = new EchoCollectionClient())
            {
                response = client.GetDocTypes();
            }
            return(response);
        }
        public GetItemsResponse GetItems()
        {
            GetItemsResponse response = new GetItemsResponse();

            using (var client = new EchoCollectionClient())
            {
                response = client.GetItems();
            }
            return(response);
        }
        public string AddItem(Api.Models.Item item)
        {
            item.Metadata.Date = DateTime.Now;
            AddItemRequest request = new AddItemRequest();

            request.Item = new EchoService.DataContracts.Item
            {
                DocumentTypeId = item.DocumentType.ID,
                CollectionId   = item.CollectionId,
                ID             = item.ID,
                IsPrivate      = item.IsPrivate,
                Title          = item.Title,
                Attachment     = item.Attachment,
                Metadata       = new Metadata
                {
                    ID        = item.Metadata.ID,
                    Abstract  = item.Metadata.Abstract,
                    Author    = item.Metadata.Author,
                    Date      = item.Metadata.Date,
                    Extra     = item.Metadata.Extra,
                    Language  = item.Metadata.Language,
                    Publisher = item.Metadata.Publisher,
                    Rights    = item.Metadata.Rights,
                    Url       = item.Metadata.Url
                }
            };
            using (var client = new EchoCollectionClient())
            {
                if (item.ID == 0)
                {
                    client.AddItem(request);
                }
                else
                {
                    client.UpdateItem(request);
                }
            }

            return(string.Format("Item with title: '{0}', Document Type: '{1}' has been added successfully.", item.Title, item.DocumentType));
        }
        public IHttpActionResult GetCitations(int citStyleID)
        {
            string rootPath  = HttpContext.Current.Server.MapPath("~") + @"CSL Library\";
            string stylePath = rootPath + @"Styles\";
            string itemsPath = rootPath + @"cit_items.json";

            switch (citStyleID)
            {
            case 1:
                stylePath += "ieee.csl";
                break;

            case 2:
                stylePath += "elsevier-harvard.csl";
                break;

            case 3:
                stylePath += "chicago-author-date.csl";
                break;

            case 4:
                stylePath += "apa-5th-edition.csl";
                break;

            default:
                return(BadRequest());
            }

            var style = CiteProc.File.Load(stylePath);

            var processor = CiteProc.Processor.Compile(style);

            GetItemsResponse items = new GetItemsResponse();

            using (var client = new EchoCollectionClient())
            {
                items = client.GetItems();
            }

            List <CSLCompatibleItem> CSLCompatibleItems = new List <CSLCompatibleItem>(items.Items.Count);

            foreach (var item in items.Items)
            {
                CSLCompatibleItem CslItem = new CSLCompatibleItem();
                CslItem.@abstract = "bla"; // item.Metadata != null ? item.Metadata.Abstract : string.Empty;
                CslItem.id        = "bla"; //item.ID.ToString();
                CslItem.issued    = "bla"; //item.Metadata != null ? item.Metadata.Date.ToString("yyyy-MM-dd") : string.Empty;
                CslItem.language  = "bla"; //item.Metadata != null ? item.Metadata.Language : string.Empty;
                CslItem.note      = "bla"; //item.Metadata != null ? item.Metadata.Extra : string.Empty;
                CslItem.publisher = "bla"; //item.Metadata != null ? item.Metadata.Publisher : string.Empty;
                CslItem.title     = "bla"; //item.Metadata != null ? item.Title : string.Empty;
                CslItem.type      = "Book";
                CslItem.URL       = "bla"; //item.Metadata != null ? item.Metadata.Url : string.Empty;
                CslItem.author    = "sss";
                CSLCompatibleItems.Add(CslItem);
            }

            using (MemoryStream m = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(m, CSLCompatibleItems);

                processor.DataProviders = CiteProc.Data.DataProvider.Load(m, CiteProc.Data.DataFormat.Json);
            }

            var entries = processor.GenerateBibliography();

            string allEntries = "";

            foreach (var entry in entries)
            {
                HtmlString htmlstring = new HtmlString(@"<br />");
                allEntries += entry.ToHtml() + htmlstring.ToHtmlString();
            }

            return(Ok(allEntries));
        }