public VendorModel Update(VendorModel model)
        {
            try
            {
                string sql = @"UPDATE [dbo].[Vendor] SET
                                [VendorCode] = @VendorCode
                               ,[VendorName] = @VendorName
                               ,[Address] = @Address
                               ,[PhoneNumber] = @PhoneNumber
                               ,[City] = @City
                               ,[FAX] = @FAX
                               ,[VAT] = @VAT
                               ,[ContactPerson] = @ContactPerson
                               ,[Email] = @Email
                               ,[CrNo] = @CrNo
                               ,[GosiNo] = @GosiNo
                               ,[Zakaat] = @Zakaat
                               ,[ChamberNo] = @ChamberNo
                               ,[VATExpiry] = @VATExpiry
                               ,[ChamberNoExpiry] = @ChamberNoExpiry
                               ,[CrNoExpiry] = @CrNoExpiry
                               ,[GosiNoExpiry] = @GosiNoExpiry
                               ,[ZakaatExpiry] = @ZakaatExpiry
                               ,[Keywords] = @Keywords
                         WHERE VendorId = '" + model.VendorId + @"'";

                List <SqlParameter> param = new List <SqlParameter>();
                param.Add(new SqlParameter("@VendorCode", model.VendorCode));
                param.Add(new SqlParameter("@VendorName", model.VendorName));
                param.Add(new SqlParameter("@Address", model.Address));
                param.Add(new SqlParameter("@PhoneNumber", model.PhoneNumber));
                param.Add(new SqlParameter("@City", model.City));
                param.Add(new SqlParameter("@FAX", model.FAX));
                param.Add(new SqlParameter("@VAT", model.VAT));
                param.Add(new SqlParameter("@ContactPerson", model.ContactPerson));
                param.Add(new SqlParameter("@Email", model.Email));
                param.Add(new SqlParameter("@CrNo", model.CrNo));
                param.Add(new SqlParameter("@GosiNo", model.GosiNo));
                param.Add(new SqlParameter("@Zakaat", model.Zakaat));
                param.Add(new SqlParameter("@ChamberNo", model.ChamberNo));
                param.Add(new SqlParameter("@Keywords", model.Keywords));

                if (model.VATExpiry == "")
                {
                    param.Add(new SqlParameter("@VATExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@VATExpiry", model.VATExpiry));
                }

                if (model.ChamberNoExpiry == "")
                {
                    param.Add(new SqlParameter("@ChamberNoExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@ChamberNoExpiry", model.ChamberNoExpiry));
                }

                if (model.CrNoExpiry == "")
                {
                    param.Add(new SqlParameter("@CrNoExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@CrNoExpiry", model.CrNoExpiry));
                }

                if (model.GosiNoExpiry == "")
                {
                    param.Add(new SqlParameter("@GosiNoExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@GosiNoExpiry", model.GosiNoExpiry));
                }

                if (model.ZakaatExpiry == "")
                {
                    param.Add(new SqlParameter("@ZakaatExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@ZakaatExpiry", model.ZakaatExpiry));
                }

                fun.OpenConnection();
                if (fun.getConnection().State == ConnectionState.Open)
                {
                    int Id = fun.ExecuteQueryWithParameters(sql, param, "Yes");
                    if (Id > 0)
                    {
                        if (model.CountryId > 0)
                        {
                            sql = @"Update Vendor set CountryId = '" + model.CountryId.ToString() + @"'
                                where VendorId = " + Id.ToString();
                            fun.execQry(sql);
                        }
                        if (model.VendorTypeId > 0)
                        {
                            sql = @"Update Vendor set VendorTypeId = '" + model.VendorTypeId.ToString() + @"'
                                where VendorId = " + Id.ToString();
                            fun.execQry(sql);
                        }
                    }
                    model.VendorId = Id;
                    return(model);
                }
                else
                {
                    throw new Exception("Please check network connection");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
        public VendorModel Insert(VendorModel model)
        {
            int i = 0;

            try
            {
                string sql = @"INSERT INTO Vendor
                               (VendorCode
                               ,VendorName
                               ,Address
                               ,PhoneNumber
                               ,City
                               ,FAX
                               ,VAT
                               ,ContactPerson
                               ,Email
                               ,CrNo
                               ,GosiNo
                               ,Zakaat
                               ,ChamberNo
                               ,VATExpiry
                               ,ChamberNoExpiry
                               ,CrNoExpiry
                               ,GosiNoExpiry
                               ,ZakaatExpiry
                               ,Keywords)
                         output INSERTED.VendorId
                         VALUES
                               (@VendorCode
                               ,@VendorName
                               ,@Address
                               ,@PhoneNumber
                               ,@City
                               ,@FAX
                               ,@VAT
                               ,@ContactPerson
                               ,@Email
                               ,@CrNo
                               ,@GosiNo
                               ,@Zakaat
                               ,@ChamberNo
                               ,@VATExpiry
                               ,@ChamberNoExpiry
                               ,@CrNoExpiry
                               ,@GosiNoExpiry
                               ,@ZakaatExpiry
                               ,@Keywords)";
                List <SqlParameter> param = new List <SqlParameter>();
                param.Add(new SqlParameter("@VendorCode", model.VendorCode));
                param.Add(new SqlParameter("@VendorName", model.VendorName));
                param.Add(new SqlParameter("@Address", model.Address));
                param.Add(new SqlParameter("@PhoneNumber", model.PhoneNumber));
                param.Add(new SqlParameter("@City", model.City));
                param.Add(new SqlParameter("@FAX", model.FAX));
                param.Add(new SqlParameter("@VAT", model.VAT));
                param.Add(new SqlParameter("@ContactPerson", model.ContactPerson));
                param.Add(new SqlParameter("@Email", model.Email));
                param.Add(new SqlParameter("@CrNo", model.CrNo));
                param.Add(new SqlParameter("@GosiNo", model.GosiNo));
                param.Add(new SqlParameter("@Zakaat", model.Zakaat));
                param.Add(new SqlParameter("@ChamberNo", model.ChamberNo));
                param.Add(new SqlParameter("@Keywords", model.Keywords));

                if (model.VATExpiry == "")
                {
                    param.Add(new SqlParameter("@VATExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@VATExpiry", model.VATExpiry));
                }

                if (model.ChamberNoExpiry == "")
                {
                    param.Add(new SqlParameter("@ChamberNoExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@ChamberNoExpiry", model.ChamberNoExpiry));
                }

                if (model.CrNoExpiry == "")
                {
                    param.Add(new SqlParameter("@CrNoExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@CrNoExpiry", model.CrNoExpiry));
                }

                if (model.GosiNoExpiry == "")
                {
                    param.Add(new SqlParameter("@GosiNoExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@GosiNoExpiry", model.GosiNoExpiry));
                }

                if (model.ZakaatExpiry == "")
                {
                    param.Add(new SqlParameter("@ZakaatExpiry", System.DBNull.Value));
                }
                else
                {
                    param.Add(new SqlParameter("@ZakaatExpiry", model.ZakaatExpiry));
                }

                fun.OpenConnection();
                if (fun.getConnection().State == ConnectionState.Open)
                {
                    int Id = fun.ExecuteQueryWithParameters(sql, param, "Yes");
                    if (Id > 0)
                    {
                        if (model.CountryId > 0)
                        {
                            sql = @"Update Vendor set CountryId = '" + model.CountryId.ToString() + @"'
                                where VendorId = " + Id.ToString();
                            fun.execQry(sql);
                        }
                        if (model.VendorTypeId > 0)
                        {
                            sql = @"Update Vendor set VendorTypeId = '" + model.VendorTypeId.ToString() + @"'
                                where VendorId = " + Id.ToString();
                            fun.execQry(sql);
                        }
                    }
                    model.VendorId = Id;
                    return(model);
                }
                else
                {
                    throw new Exception("Please check network connection");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }