public int AddEntry(Blog_Type incoming) { string sSQL = "INSERT INTO [dbo].[Blog] ([Parent], [Title], [BlogDate], [Author], [BlogContent], [BlogTrailID], [Sticky], [Archive], [Banned]) " + "VALUES (@Parent, @Title, getdate(), @Author, @BlogContent, (SELECT MAX(BlogTrailID) + 1 FROM [dbo].[Blog] WHERE Parent = @Parent), @Sticky, @Archive, @Banned); SELECT Scope_Identity();"; int iRet = -1; using (Data DC = new Data("conn", Page, Process)) { try { DC.AddCommand(CommandType.Text, sSQL); DC.AttachParameterByValue("Parent", incoming.ParentID); DC.AttachParameterByValue("Archive", incoming.Archive); DC.AttachParameterByValue("Author", incoming.Author); DC.AttachParameterByValue("Banned", incoming.Banned); DC.AttachParameterByValue("BlogContent", Conversion.ConvertIn(incoming.BlogContent)); DC.AttachParameterByValue("Sticky", incoming.Sticky); DC.AttachParameterByValue("Title", incoming.Title); object obj = DC.ExecuteScalar(); iRet = (int)Utils.ParseNumControlledReturn(obj); } catch (Exception ex) { DC.MakeError(ex, Process, sSQL); } finally { DC.Dispose(); } } return(iRet); }
public int SubmitReply(int BlogID, int Author, string AuthorName, string Title, string Content) { BlogRepository br = new BlogRepository(Author, "BlogModel", "SubmitReply"); Blog_Type type = new Blog_Type { Archive = true, Author = Author, AuthorName = AuthorName, Banned = false, BlogContent = Content, BlogDate = DateTime.Now, ParentID = BlogID, Sticky = false, Title = Title }; int iRet = br.AddEntry(type); if (iRet > 0) { //send me an email to tell me what's going on UserType _user = new UserType { Email = ConfigurationManager.AppSettings["AccountEmail"].StringSafe(), UserName = "******" }; List <UserType> recipients = new List <UserType>(); recipients.Add(_user); EmailType _type = new EmailType { Message = Content, SentTime = DateTime.Now, SenderName = AuthorName, ID = Author }; Email send = new Email(); send.SendAlert(false, "A reply is sent on the blog", respEmail, "An error occurred on the site"); } return(iRet); }