Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <Entities.Client> GetAllClients()
        {
            var clients = new List <Entities.Client>();

            DbCommand dbCommand = null;

            try
            {
                using (dbCommand = database.GetStoredProcCommand(DBStoredProcedure.GetAllClients))
                {
                    using (IDataReader reader = database.ExecuteReader(dbCommand))
                    {
                        while (reader.Read())
                        {
                            ClientAddress clientAddress = new ClientAddress();

                            var client = new Entities.Client
                            {
                                ClientTypeId     = DRE.GetNullableInt32(reader, "client_type_id", 0),
                                ClientTypeName   = DRE.GetNullableString(reader, "client_type", null),
                                ClientId         = DRE.GetNullableInt32(reader, "client_id", 0),
                                ClientCode       = DRE.GetNullableString(reader, "client_code", null),
                                ClientName       = DRE.GetNullableString(reader, "client_name", null),
                                PANNo            = DRE.GetNullableString(reader, "pan_no", null),
                                SrNo             = DRE.GetNullableInt64(reader, "sr_no", null),
                                ClientAddressess = clientAddress.GetAllClientAddressessByClientId(DRE.GetInt32(reader, "client_id"))
                            };

                            clients.Add(client);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbCommand = null;
            }

            return(clients);
        }
Пример #2
0
        public Int32 SaveClient(List <Entities.Client> client)
        {
            var clientId = 0;

            var db = DBConnect.getDBConnection();

            using (DbConnection conn = db.CreateConnection())
            {
                conn.Open();

                using (DbTransaction transaction = conn.BeginTransaction())
                {
                    try
                    {
                        var clientAddressId = 0;

                        if (client.Count > 0)
                        {
                            foreach (Entities.Client c in client)
                            {
                                if (c.ClientId == null || c.ClientId == 0)
                                {
                                    var result = IsClientNameExists(c.ClientName);

                                    if (result == false)
                                    {
                                        clientId = AddClient(c, transaction);
                                    }
                                    else
                                    {
                                        clientId = -2;
                                    }
                                }
                                else if (c.ModifiedBy == null || c.ModifiedBy == 0)
                                {
                                    clientId = UpdateClient(c, transaction);
                                }
                                else if (c.IsDeleted == true)
                                {
                                    var result = DeleteClient(c, transaction);

                                    if (result)
                                    {
                                        clientId = (int)c.ClientId;
                                    }
                                }

                                if (clientId > 0)
                                {
                                    foreach (Entities.ClientAddress ca in c.ClientAddressess)
                                    {
                                        ca.ClientId = clientId;

                                        ClientAddress clientAddress = new ClientAddress();

                                        clientAddressId = clientAddress.SaveClientAddress(ca, transaction);
                                    }
                                }
                            }
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        db = null;
                    }
                }
            }

            return(clientId);
        }