private int SaveDetails( ForumPost item ) { int rowsAffected = 0; try { Session["CurrentObject"] = item.Save(); rowsAffected = 1; } catch (Csla.Validation.ValidationException ex) { System.Text.StringBuilder message = new System.Text.StringBuilder(); message.AppendFormat( "{0}<br/>", ex.Message ); if (item.BrokenRulesCollection.Count == 1) message.AppendFormat( "* {0}: {1}", item.BrokenRulesCollection[0].Property, item.BrokenRulesCollection[0].Description ); else foreach (Csla.Validation.BrokenRule rule in item.BrokenRulesCollection) message.AppendFormat( "* {0}: {1}<br/>", rule.Property, rule.Description ); PostError.Visible = true; PostError.Text = message.ToString(); rowsAffected = 0; } catch (Csla.DataPortalException ex) { PostError.Visible = true; PostError.Text = ex.BusinessException.Message; rowsAffected = 0; } catch (Exception ex) { PostError.Visible = true; PostError.Text = ex.Message; rowsAffected = 0; } return rowsAffected; }
private int SaveDetails( ForumPost item ) { int rowsAffected = 0; // before adding the post, we have to add a new topic ForumTopic topic = ForumTopic.NewForumTopic(); try { int boardId = 0; try { boardId = Int32.Parse( Request.QueryString["ID"] ); } catch { Response.Redirect( "ForumBoards.aspx"); } topic.BoardID = boardId; topic.Title = item.Subject; topic.Sticky = Sticky.Checked; topic.Locked = Locked.Checked; if (item.IsValid) topic.Save(); // now we can assign the new topic's id to the post item.TopicID = topic.ID; item.UserID = User.ID; item.Save(); rowsAffected = 1; } catch (Csla.Validation.ValidationException ex) { System.Text.StringBuilder message = new System.Text.StringBuilder(); message.AppendFormat( "{0}<br/>", ex.Message ); if (item.BrokenRulesCollection.Count == 1) message.AppendFormat( "* {0}: {1}", item.BrokenRulesCollection[0].Property, item.BrokenRulesCollection[0].Description ); else if (item.BrokenRulesCollection.Count > 1) foreach (Csla.Validation.BrokenRule rule in item.BrokenRulesCollection) message.AppendFormat( "* {0}: {1}<br/>", rule.Property, rule.Description ); if (topic.BrokenRulesCollection.Count == 1) message.AppendFormat( "* {0}: {1}", topic.BrokenRulesCollection[0].Property, topic.BrokenRulesCollection[0].Description ); else if (topic.BrokenRulesCollection.Count > 1) foreach (Csla.Validation.BrokenRule rule in topic.BrokenRulesCollection) message.AppendFormat( "* {0}: {1}<br/>", rule.Property, rule.Description ); PostError.Visible = true; PostError.Text = message.ToString(); rowsAffected = 0; } catch (Csla.DataPortalException ex) { PostError.Visible = true; PostError.Text = ex.BusinessException.Message; rowsAffected = 0; } catch (Exception ex) { PostError.Visible = true; PostError.Text = ex.Message; rowsAffected = 0; } return rowsAffected; }