Пример #1
0
        public SnippetDTO CreateSnippet(SnippetDTO snippet, LanguageDTO language, UserDTO user,
                                        IEnumerable<FileDTO> files,
                                        IEnumerable<HyperlinkDTO> links)
        {
            SnippetDTO returnDTO = snippet;

            if (snippet.Data == null || (language == null || language.Id <= 0)) return null;

            if (snippet.Language_Id > 0)
            {
                snippet.Language_Id = language.Id;
                snippet.PreviewData = GetPreviewData(snippet.Data);
                snippet.LastModified = DateTime.UtcNow;
                snippet.User_Id = user.Id;
                snippet.User_FormsAuthId = user.FormsAuthId;
            }

            int result = _snippetOperationsEngine.CreateNewSnippet(snippet);
            if (result > 0)
            {
                returnDTO.Id = snippet.Id;
                returnDTO.Guid = snippet.Guid;

                // Snippet creation was successult. Now we have a SnippetId and can insert
                // any hyperlinks or files

                // Hyperlinks first
                if (links != null && links.Any())
                {
                    foreach (HyperlinkDTO hyperlinkDTO in links)
                    {
                        // Update the hyperlink's Snippet Id since we successfully sved it
                        hyperlinkDTO.Snippet_Id = result;
                        int createHyperlinkResponse = _snippetOperationsEngine.CreateNewHyperlink(hyperlinkDTO);
                        if (createHyperlinkResponse <= 0)
                            Logger.LogInfo(
                                string.Format("Failed to create hyperlink uri {0} for snippet id {1}", hyperlinkDTO.Uri,
                                              hyperlinkDTO.Snippet_Id), LogType.Notify);
                    }
                }

                // Files now
                if (files != null && files.Any())
                {
                    foreach (FileDTO fileDTO in files)
                    {
                        // Update the SnippetId with newly created id
                        fileDTO.Snippet_Id = result;
                        int createFileResponse = _snippetOperationsEngine.CreateNewFile(fileDTO);
                        if (createFileResponse <= 0)
                            Logger.LogInfo(string.Format("Failed to create new file {0} for snippet id {1}", fileDTO.Id,
                                                         fileDTO.Snippet_Id), LogType.Notify);
                    }
                }
            }

            return returnDTO;
        }
        public SnippetDTO CreateSnippet(SnippetDTO snippet, LanguageDTO language, UserDTO user,
                                        IEnumerable<FileDTO> files,
                                        IEnumerable<HyperlinkDTO> links)
        {
            SnippetDTO newSnippet = SnippetManager.CreateSnippet(snippet, language, user, files, links);

            return newSnippet;
        }