Guest User

Untitled

a guest
Aug 26th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. deleted object would be re-saved by cascade
  2. <%@ Page Title="" Language="C#" MasterPageFile="~/LayoutNew.Master" AutoEventWireup="true" CodeBehind="Prueba.aspx.cs" Inherits="OfficeMart.Prueba" %>
  3. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
  4. <%@ Register Assembly="DevExpress.Web.ASPxGridView.v10.1, Version=10.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
  5. <%@ Register assembly="DevExpress.Web.ASPxEditors.v10.1, Version=10.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
  6.  
  7. <asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server">
  8.  
  9.  
  10. </asp:Content>
  11.  
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Web;
  16. using System.Web.UI;
  17. using System.Web.UI.WebControls;
  18. using DomainLayer.Objects;
  19. using System.Text;
  20. using System.Configuration;
  21. using NHibernate;
  22. using System.Net.Mail;
  23. using OfficeMart.DataAccesLayer;
  24.  
  25.  
  26. namespace OfficeMart
  27. {
  28. public partial class Prueba : System.Web.UI.Page
  29. {
  30. protected void Page_Load(object sender, EventArgs e)
  31. {
  32. ISession Sesion;
  33. ITransaction Transaction = null;
  34. Sesion = SessionManager.OpenSession();
  35. Transaction = Sesion.BeginTransaction();
  36. BO_User user = (BO_User)Sesion.Load(typeof(BO_User), Request["User"]);
  37. user.Categorys.Clear();
  38. try
  39. {
  40. Sesion.SaveOrUpdate(user);
  41. Transaction.Commit();
  42. }
  43. catch (Exception er)
  44. {
  45. Transaction.Rollback();
  46. Response.Redirect("ErrorPage.aspx?Error=" + er.Message);
  47. }
  48. finally
  49. {
  50. Sesion.Close();
  51. Sesion.Dispose();
  52. }
  53. }
  54. }
  55. }
  56.  
  57. using System;
  58. using System.Collections.Generic;
  59. using System.Linq;
  60. using System.Text;
  61.  
  62. namespace DomainLayer.Objects
  63. {
  64. public class BO_User
  65. {
  66. public BO_User()
  67. { }
  68.  
  69. public BO_User(String UserName, String Password, String Name, String LastName, String Email, BO_Rol Rol, Boolean Enable, List<BO_CategoryUser> Categorys)
  70. {
  71. this.UserName = UserName;
  72. this.Password = Password;
  73. this.Name = Name;
  74. this.LastName = LastName;
  75. this.Email = Email;
  76. this.Rol = Rol;
  77. this.Enable = Enable;
  78. this.Categorys = Categorys;
  79. }
  80.  
  81. public String UserName { get; set; }
  82. public String Password { get; set; }
  83. public String Name { get; set; }
  84. public String LastName { get; set; }
  85. public String Email { get; set; }
  86. public BO_Rol Rol { get; set; }
  87. public Boolean Enable { get; set; }
  88. public BO_Area Area { get; set; }
  89. public BO_Company Company {get; set;}
  90. public IList<BO_CategoryUser> Categorys { set; get; }
  91.  
  92. public override string ToString()
  93. {
  94. return this.LastName + ", " + this.Name + " - " + this.Rol.Description;
  95. }
  96. }
  97. }
  98.  
  99. <?xml version="1.0" encoding="utf-8" ?>
  100. <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainLayer" namespace="DomainLayer.Objects" default-lazy="false">
  101. <class name="BO_User" table="USERS" lazy="false">
  102.  
  103. <id name="UserName" column="USERNAME" type="string" >
  104. <generator class="assigned" />
  105. </id>
  106. <property name="Password" column="PASSWORD" type="string" not-null="true"/>
  107. <property name="Name" column="NAME" type="string" not-null="true"/>
  108. <property name="LastName" column="LASTNAME" type="string" not-null="true"/>
  109. <property name="Email" column="EMAIL" type="string" not-null="true"/>
  110. <many-to-one name="Rol" column="IDROL" class="BO_Rol" />
  111. <property name="Enable" column="ENABLE" type="boolean" not-null="true"/>
  112. <many-to-one name="Company" column="IDCOMPANY" class="BO_Company" />
  113. <many-to-one name="Area" column="IDAREA" class="BO_Area" />
  114. <bag name="Categorys" cascade="all-delete-orphan">
  115. <key column="USERNAME"/>
  116. <one-to-many class="BO_CategoryUser"/>
  117. </bag>
  118. </class>
  119. </hibernate-mapping>
  120.  
  121. deleted object would be re-saved by cascade (remove deleted object from associations): 100, of class: DomainLayer.Objects.BO_CategoryUser
  122.  
  123. using System;
  124. using System.Collections.Generic;
  125. using System.Linq;
  126. using System.Text;
  127.  
  128. namespace DomainLayer.Objects
  129. {
  130. public class BO_CategoryUser
  131. {
  132. public BO_CategoryUser()
  133. { }
  134. public BO_CategoryUser(Int32 IdCategoryUser, BO_Category Category, BO_User User)
  135. {
  136. this.IdCategoryUser = IdCategoryUser;
  137. this.Category = Category;
  138. this.User = User;
  139.  
  140. }
  141. public Int32 IdCategoryUser { get; set; }
  142. public BO_Category Category { get; set; }
  143. public BO_User User { get; set; }
  144. }
  145.  
  146. }
  147.  
  148. <?xml version="1.0" encoding="utf-8" ?>
  149. <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainLayer" namespace="DomainLayer.Objects" default-lazy="false">
  150. <class name="BO_CategoryUser" table="CATEGORY_USER" lazy="false">
  151.  
  152. <id name="IdCategoryUser" column ="IDCATEGORYUSER" type="int" unsaved-value="0">
  153. <generator class="identity"/>
  154. </id>
  155. <many-to-one name="Category" column="IDCATEGORY" class="BO_Category" />
  156. <many-to-one name="User" column="USERNAME" class="BO_User" />
  157. </class>
  158. </hibernate-mapping>
Add Comment
Please, Sign In to add comment