示例#1
0
        public bool Save <T>(T item) where T : IContract
        {
            var result       = 0;
            var operatorItem = (Operator)(object)item;

            if (currentTransaction == null)
            {
                connection = db.CreateConnection();
                connection.Open();
            }

            var transaction = (currentTransaction == null ? connection.BeginTransaction() : currentTransaction);

            try
            {
                var savecommand = db.GetStoredProcCommand(DBRoutine.SAVEOPERATOR);
                db.AddInParameter(savecommand, "OperatorID", System.Data.DbType.String, operatorItem.OperatorID ?? "");
                db.AddInParameter(savecommand, "OperatorName", System.Data.DbType.String, operatorItem.OperatorName);
                db.AddInParameter(savecommand, "Password", System.Data.DbType.String, operatorItem.Password);
                db.AddInParameter(savecommand, "FatherName", System.Data.DbType.String, operatorItem.FatherName);
                db.AddInParameter(savecommand, "DateOfBirth", System.Data.DbType.DateTime, operatorItem.DateOfBirth);
                db.AddInParameter(savecommand, "PlaceOfBirth", System.Data.DbType.String, operatorItem.PlaceOfBirth);
                db.AddInParameter(savecommand, "Gender", System.Data.DbType.Int16, operatorItem.Gender);
                db.AddInParameter(savecommand, "MaritialStatus", System.Data.DbType.Int16, operatorItem.MaritialStatus);
                db.AddInParameter(savecommand, "MobileNo", System.Data.DbType.String, operatorItem.MobileNo);
                db.AddInParameter(savecommand, "PhoneNo", System.Data.DbType.String, operatorItem.PhoneNo);
                db.AddInParameter(savecommand, "PANNo", System.Data.DbType.String, operatorItem.PANNo);
                db.AddInParameter(savecommand, "AadharCardNo", System.Data.DbType.String, operatorItem.AadharCardNo);
                db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, operatorItem.CreatedBy);
                db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, operatorItem.ModifiedBy);
                db.AddInParameter(savecommand, "Nationality", System.Data.DbType.String, operatorItem.Nationality ?? "Indian");
                db.AddOutParameter(savecommand, "NewDocumentNo", System.Data.DbType.String, 50);
                result = db.ExecuteNonQuery(savecommand, transaction);
                if (result > 0)
                {
                    operatorItem.OperatorID = savecommand.Parameters["@NewDocumentNo"].Value.ToString();

                    if (operatorItem.operatorAttachment != null && operatorItem.operatorAttachment.Count > 0)
                    {
                        foreach (var operatorAttachment in operatorItem.operatorAttachment)
                        {
                            operatorAttachment.operatorId   = operatorItem.OperatorID;
                            operatorAttachment.attachmentId = operatorItem.OperatorID + operatorAttachment.lookupCode;
                        }
                        result = new OperatorAttachementDAL().SaveList(operatorItem.operatorAttachment, transaction) == true ? 1 : 0;
                    }
                    if (operatorItem.BankDetails != null && operatorItem.BankDetails.Count > 0)
                    {
                        operatorItem.BankDetails.ForEach(x =>
                                                         { x.OperatorBankID = operatorItem.OperatorID;
                                                           result = new BankDetailsDAL().Save(x, transaction) == true ? 1 : 0; });
                    }

                    if (operatorItem.OperatorDriverList != null && operatorItem.OperatorDriverList.Count > 0)
                    {
                        operatorItem.OperatorDriverList.ForEach(x =>
                        {
                            x.OperatorDriverId = operatorItem.OperatorID;
                            result             = new OperatorDriverDAL().Save(x, transaction) == true ? 1 : 0;
                        });
                    }

                    if (operatorItem.OperatorVehicle != null && operatorItem.OperatorVehicle.Count > 0)
                    {
                        operatorItem.OperatorVehicle.ForEach(x =>
                        {
                            x.OperatorVehicleID = operatorItem.OperatorID;
                            result = new OperatorVehicleDAL().Save(x, transaction) == true ? 1 : 0;
                        });
                    }
                    if (operatorItem.AddressList != null && operatorItem.AddressList.Count > 0)
                    {
                        //foreach (var addressItem in operatorItem.AddressList)
                        //{
                        //    addressItem.AddressLinkID = operatorItem.OperatorID;
                        //}
                        operatorItem.AddressList.ForEach(x =>
                                                         { x.AddressLinkId = operatorItem.OperatorID;
                                                           result = new AddressDAL().Save(x, transaction) == true ? 1 : 0; });
                    }
                    if (currentTransaction == null)
                    {
                        transaction.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                if (currentTransaction == null)
                {
                    transaction.Rollback();
                }

                throw ex;
            }
            finally
            {
                transaction.Dispose();
                connection.Close();
            }

            return(result > 0 ? true : false);
        }
 public OperatorVehicleBO()
 {
     operatorVehicleDAL = new OperatorVehicleDAL();
 }