/// <summary> /// Inserts a new DeliveryRegister object in the database. /// </summary> /// <param name="deliveryRegister">The Delivery Register DTO.</param> /// <returns>The new <see cref="DeliveryRegisterDto"/>.</returns> public DeliveryRegisterDto Insert(DeliveryRegisterDto deliveryRegister) { using (var ctx = ConnectionManager <SqlConnection> .GetManager("InterwayDocs")) { using (var cmd = new SqlCommand("dbo.AddDeliveryRegister", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RegisterId", deliveryRegister.RegisterId).Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("@RegisterDate", deliveryRegister.RegisterDate.DBValue).DbType = DbType.Date; cmd.Parameters.AddWithValue("@DocumentType", deliveryRegister.DocumentType).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentReference", deliveryRegister.DocumentReference).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentEntity", deliveryRegister.DocumentEntity).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentDept", deliveryRegister.DocumentDept).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentClass", deliveryRegister.DocumentClass).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentDate", deliveryRegister.DocumentDate.DBValue).DbType = DbType.Date; cmd.Parameters.AddWithValue("@RecipientName", deliveryRegister.RecipientName).DbType = DbType.String; cmd.Parameters.AddWithValue("@ExpeditorName", deliveryRegister.ExpeditorName).DbType = DbType.String; cmd.Parameters.AddWithValue("@ReceptionName", deliveryRegister.ReceptionName).DbType = DbType.String; cmd.Parameters.AddWithValue("@ReceptionDate", deliveryRegister.ReceptionDate.DBValue).DbType = DbType.Date; cmd.Parameters.AddWithValue("@CreateDate", deliveryRegister.CreateDate.DBValue).DbType = DbType.DateTime2; cmd.Parameters.AddWithValue("@ChangeDate", deliveryRegister.ChangeDate.DBValue).DbType = DbType.DateTime2; cmd.ExecuteNonQuery(); deliveryRegister.RegisterId = (int)cmd.Parameters["@RegisterId"].Value; } } return(deliveryRegister); }
private DeliveryRegisterDto Fetch(IDataReader data) { var deliveryRegister = new DeliveryRegisterDto(); using (var dr = new SafeDataReader(data)) { if (dr.Read()) { deliveryRegister.RegisterId = dr.GetInt32("RegisterId"); deliveryRegister.RegisterDate = dr.GetSmartDate("RegisterDate", true); deliveryRegister.DocumentType = dr.GetString("DocumentType"); deliveryRegister.DocumentReference = dr.GetString("DocumentReference"); deliveryRegister.DocumentEntity = dr.GetString("DocumentEntity"); deliveryRegister.DocumentDept = dr.GetString("DocumentDept"); deliveryRegister.DocumentClass = dr.GetString("DocumentClass"); deliveryRegister.DocumentDate = dr.GetSmartDate("DocumentDate", true); deliveryRegister.RecipientName = dr.GetString("RecipientName"); deliveryRegister.ExpeditorName = dr.GetString("ExpeditorName"); deliveryRegister.ReceptionName = dr.GetString("ReceptionName"); deliveryRegister.ReceptionDate = dr.GetSmartDate("ReceptionDate", true); deliveryRegister.CreateDate = dr.GetSmartDate("CreateDate", true); deliveryRegister.ChangeDate = dr.GetSmartDate("ChangeDate", true); } } return(deliveryRegister); }
protected override void DataPortal_Update() { SimpleAuditTrail(); var dto = new DeliveryRegisterDto(); dto.RegisterId = RegisterId; dto.RegisterDate = ReadProperty(RegisterDateProperty); dto.DocumentType = DocumentType; dto.DocumentReference = DocumentReference; dto.DocumentEntity = DocumentEntity; dto.DocumentDept = DocumentDept; dto.DocumentClass = DocumentClass; dto.DocumentDate = ReadProperty(DocumentDateProperty); dto.RecipientName = RecipientName; dto.ExpeditorName = ExpeditorName; dto.ReceptionName = ReceptionName; dto.ReceptionDate = ReadProperty(ReceptionDateProperty); dto.ChangeDate = ChangeDate; using (var dalManager = DalFactoryInterwayDocs.GetManager()) { var args = new DataPortalHookArgs(dto); OnUpdatePre(args); var dal = dalManager.GetProvider <IDeliveryRegisterDal>(); using (BypassPropertyChecks) { var resultDto = dal.Update(dto); args = new DataPortalHookArgs(resultDto); } OnUpdatePost(args); } }
/// <summary> /// Updates in the database all changes made to the DeliveryRegister object. /// </summary> /// <param name="deliveryRegister">The Delivery Register DTO.</param> /// <returns>The updated <see cref="DeliveryRegisterDto"/>.</returns> public DeliveryRegisterDto Update(DeliveryRegisterDto deliveryRegister) { using (var ctx = ConnectionManager <SqlConnection> .GetManager("InterwayDocs")) { using (var cmd = new SqlCommand("dbo.UpdateDeliveryRegister", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RegisterId", deliveryRegister.RegisterId).DbType = DbType.Int32; cmd.Parameters.AddWithValue("@RegisterDate", deliveryRegister.RegisterDate.DBValue).DbType = DbType.Date; cmd.Parameters.AddWithValue("@DocumentType", deliveryRegister.DocumentType).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentReference", deliveryRegister.DocumentReference).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentEntity", deliveryRegister.DocumentEntity).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentDept", deliveryRegister.DocumentDept).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentClass", deliveryRegister.DocumentClass).DbType = DbType.String; cmd.Parameters.AddWithValue("@DocumentDate", deliveryRegister.DocumentDate.DBValue).DbType = DbType.Date; cmd.Parameters.AddWithValue("@RecipientName", deliveryRegister.RecipientName).DbType = DbType.String; cmd.Parameters.AddWithValue("@ExpeditorName", deliveryRegister.ExpeditorName).DbType = DbType.String; cmd.Parameters.AddWithValue("@ReceptionName", deliveryRegister.ReceptionName).DbType = DbType.String; cmd.Parameters.AddWithValue("@ReceptionDate", deliveryRegister.ReceptionDate.DBValue).DbType = DbType.Date; cmd.Parameters.AddWithValue("@ChangeDate", deliveryRegister.ChangeDate.DBValue).DbType = DbType.DateTime2; var rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) { throw new DataNotFoundException("DeliveryRegister"); } } } return(deliveryRegister); }
/// <summary> /// Loads a <see cref="DeliveryRegister"/> object from the given <see cref="DeliveryRegisterDto"/>. /// </summary> /// <param name="data">The DeliveryRegisterDto to use.</param> private void Fetch(DeliveryRegisterDto data) { // Value properties LoadProperty(RegisterIdProperty, data.RegisterId); LoadProperty(RegisterDateProperty, data.RegisterDate); LoadProperty(DocumentTypeProperty, data.DocumentType); LoadProperty(DocumentReferenceProperty, data.DocumentReference); LoadProperty(DocumentEntityProperty, data.DocumentEntity); LoadProperty(DocumentDeptProperty, data.DocumentDept); LoadProperty(DocumentClassProperty, data.DocumentClass); LoadProperty(DocumentDateProperty, data.DocumentDate); LoadProperty(RecipientNameProperty, data.RecipientName); LoadProperty(ExpeditorNameProperty, data.ExpeditorName); LoadProperty(ReceptionNameProperty, data.ReceptionName); LoadProperty(ReceptionDateProperty, data.ReceptionDate); LoadProperty(CreateDateProperty, data.CreateDate); LoadProperty(ChangeDateProperty, data.ChangeDate); var args = new DataPortalHookArgs(data); OnFetchRead(args); }