Ejemplo n.º 1
0
        public Guid CreateCustomerAddressByCustomerDescription(string customerDescription, string type,
                                                               string firstName, string lastName,
                                                               string addressLine, string district, string city,
                                                               string zipCode, string countryCode,
                                                               string taxNumber, string taxOffice)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(customerDescription))
                {
                    throw new Exception("Customer description (B2C Id) must be provided");
                }

                NebimV3.CurrentAccounts.RetailCustomer customer = new NebimV3.CurrentAccounts.RetailCustomer();
                string customerCode = null;


                customerCode = FindCustomerCodeByDescription(customerDescription);
                customer.RetailCustomerCode = customerCode;
                if (!customer.ExistsInDB())
                {
                    throw new Exception("Customer does not exists. CustomerCode:" + customerCode);
                }
                return(CreateCustomerAddressByCustomerCode(customerCode, type, firstName, lastName, addressLine, district, city, zipCode, countryCode, taxNumber, taxOffice));
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
        }
Ejemplo n.º 2
0
        public Guid CreateCustomerAddressByCustomerCode(string customerCode, string type,
                                                        string firstName, string lastName,
                                                        string addressLine, string district, string city,
                                                        string zipCode, string countryCode,
                                                        string taxNumber, string taxOffice)
        {
            try
            {
                // DB'de kayıtlı bir müşterinin Müşteri Kodu vasıtasıyla yüklenmesi
                NebimV3.CurrentAccounts.RetailCustomer customer = new NebimV3.CurrentAccounts.RetailCustomer();
                if (!string.IsNullOrWhiteSpace(customerCode))
                {
                    customer.RetailCustomerCode = customerCode;
                    if (!customer.ExistsInDB())
                    {
                        throw new Exception("Customer does not exists. customer code:" + customerCode);
                    }
                    customer.Load();
                }

                NebimV3.CurrentAccounts.CurrAccPostalAddress address = new NebimV3.CurrentAccounts.CurrAccPostalAddress(customer);
                //TODO: il, ilçeyi ayır
                addressLine             = string.Format(_nebimIntegrationSettings.AddressFormat, firstName, lastName, addressLine, district);
                address.AddressTypeCode = type; // 1:Ev adresi , 2: İş adresi
                address.Address         = addressLine.Substring(0, Math.Min(200, addressLine.Length));
                address.ZipCode         = zipCode == null ? null : zipCode.Substring(0, Math.Min(20, zipCode.Length));
                address.CountryCode     = countryCode;
                //address.StateCode = "TR.00"; // Marmara
                address.CityCode = city; // TR.34 İstanbul

                address.TaxNumber = taxNumber == null ? null : taxNumber.Substring(0, Math.Min(10, taxNumber.Length));
                if (!string.IsNullOrWhiteSpace(taxOffice))
                {
                    address.SetTaxOfficedescription(taxOffice.Substring(0, Math.Min(100, taxOffice.Length)));
                }
                address.SetCitydescription(city);
                if (!string.IsNullOrWhiteSpace(district))
                {
                    address.SetDistrictdescription(district.Substring(0, Math.Min(100, district.Length)));
                }
                address.SaveOrUpdate();
                customer.PostalAddresses.Add(address);
                return(address.PostalAddressID);
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
        }
Ejemplo n.º 3
0
        private int?FindProductHierarchy(int[] hierarchLevelCodes)
        {
            int?productHierarchyId = null;

            try
            {
                NebimV3.DataConnector.SqlSelectStatement query = new NebimV3.DataConnector.SqlSelectStatement();
                query.TableNames.Add("dfProductHierarchy", false);
                query.Parameters.Add(new NebimV3.DataConnector.PropertyCondition("dfProductHierarchy", "ProductHierarchyID"));

                for (int i = 0; i < hierarchLevelCodes.Length; i++)
                {
                    // query.Parameters.Add(new NebimV3.DataConnector.PropertyCondition("dfProductHierarchy", "ProductHierarchyLevelCode0"+(i+1).ToString()));

                    query.Filter.AddCondition(
                        new NebimV3.DataConnector.BinaryCondition(
                            new NebimV3.DataConnector.PropertyCondition("dfProductHierarchy", "ProductHierarchyLevelCode0" + (i + 1).ToString()),
                            new NebimV3.DataConnector.ValueCondition(hierarchLevelCodes[i])
                            ));
                }

                HashSet <int> results = new HashSet <int>();

                using (System.Data.IDataReader reader = NebimV3.DataConnector.SqlStatmentExecuter.ExecuteSelect(query))
                {
                    while (reader.Read())
                    {
                        results.Add((int)(reader["ProductHierarchyID"]));
                    }
                }

                // if (results.Count > 1)  // Örnek olarak yaptik. Exception atmak yerine ne yapilmasi gerektigi uygulamaya göre degisebilir.
                //     throw new Exception("More than one record with the same B2C customer Id");

                if (results.Count == 0)
                {
                    return(null);
                }

                productHierarchyId = results.LastOrDefault();
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
            return(productHierarchyId);
        }
Ejemplo n.º 4
0
        internal IList <int> FindProductHierarchyLevelCode(string hierarchLevelName, int levelNumber)
        {
            try
            {
                NebimV3.DataConnector.SqlSelectStatement query = new NebimV3.DataConnector.SqlSelectStatement();
                query.TableNames.Add("cdProductHierarchyLevel", false);
                query.TableNames.Add("cdProductHierarchyLevelDesc", false);
                query.Parameters.Add(new NebimV3.DataConnector.PropertyCondition("cdProductHierarchyLevel", "ProductHierarchyLevelCode"));

                query.Filter = new NebimV3.DataConnector.GroupCondition();
                query.Filter.AddCondition(
                    new NebimV3.DataConnector.BinaryCondition(
                        new NebimV3.DataConnector.PropertyCondition("cdProductHierarchyLevel", "ProductHierarchyLevelCode"),
                        new NebimV3.DataConnector.PropertyCondition("cdProductHierarchyLevelDesc", "ProductHierarchyLevelCode")
                        ));

                query.Filter.AddCondition(
                    new NebimV3.DataConnector.BinaryCondition(
                        new NebimV3.DataConnector.PropertyCondition("cdProductHierarchyLevelDesc", "ProductHierarchyLevelDescription"),
                        new NebimV3.DataConnector.ValueCondition(hierarchLevelName)
                        ));

                query.Filter.AddCondition(
                    new NebimV3.DataConnector.BinaryCondition(
                        new NebimV3.DataConnector.PropertyCondition("cdProductHierarchyLevel", "LevelNumber"),
                        new NebimV3.DataConnector.ValueCondition(levelNumber)
                        ));


                HashSet <int> results = new HashSet <int>();

                using (System.Data.IDataReader reader = NebimV3.DataConnector.SqlStatmentExecuter.ExecuteSelect(query))
                {
                    while (reader.Read())
                    {
                        results.Add((int)(reader["ProductHierarchyLevelCode"]));
                    }
                }

                // if (results.Count > 1)  // Örnek olarak yaptik. Exception atmak yerine ne yapilmasi gerektigi uygulamaya göre degisebilir.
                //     throw new Exception("More than one record with the same B2C customer Id");

                if (results.Count == 0)
                {
                    throw new Exception("Kategori*hiyerarşi eşi bulunamadı. Kategori:" + hierarchLevelName);
                    //return null;
                }


                return(results.ToList());
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
        }
Ejemplo n.º 5
0
        //AF
        internal void CreateUpdateProduct(
            string Barcode,
            string ProductCode,        /*sku*/
            string ProductNameTR,
            string ProductNameEN,
            int ItemDimTypeCode,
            IList <Tuple <string, string, string, string, string, string, string> > combinations,     //renk kodu,renk adı, renk adı, boyut kodu,boyut adı,boyut adı
            string UnitOfMeasureCode1,
            string CountryCode,
            string PurcVatRate,                                       //tax rate
            string SellVatRate,                                       //tax rate
            string ItemAccountGrCode,                                 //tax rate
            int[] ProductHierarchyLevelCodes,
            IList <Tuple <byte, string, string, string> > attributes, //attr type code (1-20),attr code, attr name,attr name
            decimal price1,
            decimal price2,
            decimal price3,
            string currencyCode)
        {
            try
            {
                using (NebimV3.DataConnector.JoinedSqlTransactionScope Trans = new NebimV3.DataConnector.JoinedSqlTransactionScope())
                {
                    NebimV3.Items.Product Product = new NebimV3.Items.Product();
                    Product.ProductCode        = ProductCode;
                    Product.ProductDescription = ProductNameTR;
                    //kampanya grubu
                    Product.PromotionGroupCode = null;//"Sezon"; //sezon ürünleri
                    #region hierarchy

                    //TODO: yoksa önce hiyerarşi yaratılmalıdır.
                    // Ürün hiyerarşisindeki yeri
                    int?hierarchyId = FindProductHierarchy(ProductHierarchyLevelCodes);
                    if (!hierarchyId.HasValue)
                    {
                        throw new Exception("CreateUpdateProduct=> kategori*hiyerarşi eşleşrtirilemedi. product code:" + ProductCode + "hierarchy levels:" + String.Join("-", ProductHierarchyLevelCodes.Select(x => x.ToString())));
                    }
                    Product.ProductHierarchyID = 0;//ProductHierarchyLevel03.HasValue? ProductHierarchyLevel03.Value:ProductHierarchyLevel02.HasValue?ProductHierarchyLevel02.Value:ProductHierarchyLevel03.Value;

                    #endregion hierarchy

                    //NoDimension = 0,
                    //OnlyColor = 1,
                    //ColorAndOne = 2,
                    //ColorAndTwo = 3,
                    //ColorAndThree = 4,
                    Product.ItemDimTypeCode = (byte)ItemDimTypeCode;   // Örn: Renk + Beden + Ton

                    // Vergi grubu
                    Product.ItemTaxGrCode = ItemAccountGrCode;
                    Product.SaveOrUpdate();

                    // Farklı dilde ürün açıklaması için
                    string LangCode = "EN";
                    Product.Descriptions.Load();
                    NebimV3.v3Entities.LanguageDescription LanguageDescription = Product.Descriptions.Where((NebimV3.v3Entities.LanguageDescription X) => NebimV3.Library.ObjectComparer.AreEqual(X.DataLanguageCode, LangCode)).FirstOrDefault();
                    if (LanguageDescription != null)
                    {
                        LanguageDescription.Description = ProductNameEN;
                        LanguageDescription.SaveOrUpdate();
                    }

                    #region variants
                    // Renk ve boyut ekleme
                    foreach (var comb in combinations)
                    {
                        switch (ItemDimTypeCode)
                        {
                        case 0:
                            CreateProductBarcode(Product, comb.Item7);
                            break;

                        case 1:
                            CreateColorIfNotExists(comb.Item1, comb.Item2, comb.Item3);
                            Product.Variants.Load();
                            //check if variant is already exists?
                            if (Product.Variants.Any(x => x.ColorCode == comb.Item1))
                            {
                                break;
                            }
                            Product.AddItemVariant(comb.Item1);
                            CreateProductBarcode(Product, comb.Item7, comb.Item1);
                            break;

                        case 2:
                            CreateColorIfNotExists(comb.Item1, comb.Item2, comb.Item3);
                            CreateItemDim1IfNotExists(comb.Item4, comb.Item5, comb.Item6);
                            Product.Variants.Load();
                            //check if variant is already exists?
                            if (Product.Variants.Any(x => (x.ColorCode == comb.Item1) && (x.ItemDim1Code == comb.Item4)))
                            {
                                break;
                            }
                            Product.AddItemVariant(comb.Item1, comb.Item4);
                            CreateProductBarcode(Product, comb.Item7, comb.Item1, comb.Item4);
                            break;

                        default:
                            break;
                        }
                    }
                    #endregion variants

                    #region attributes

                    Product.Attributes.Load();
                    for (byte i = 0; i < attributes.Count; i++)
                    {
                        var attr = attributes[i];
                        if (string.IsNullOrWhiteSpace(attr.Item2))
                        {
                            continue;
                        }
                        if (Product.Attributes.Any(x => (x.AttributeCode == attr.Item2) && (x.AttributeTypeCode == attr.Item1)))
                        {
                            continue;
                        }

                        //this.CreateProductAttributeIfNotExists(attr.Item1, attr.Item2, attr.Item3, attr.Item4);
                        NebimV3.Items.ProductAttribute Attribute = new NebimV3.Items.ProductAttribute(Product);
                        Attribute.AttributeTypeCode = attr.Item1;
                        Attribute.AttributeCode     = attr.Item2;
                        Attribute.SaveOrUpdate();
                        Product.Attributes.Add(Attribute);
                    }
                    #endregion attributes

                    this.CreateProductBasePrice(Product, currencyCode, price1, price2, price3);

                    Trans.Commit();
                }
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
        }
Ejemplo n.º 6
0
        private string FindCustomerCodeByDescription(string description)
        {
            string customerCode = null;

            try
            {
                NebimV3.DataConnector.SqlSelectStatement query = new NebimV3.DataConnector.SqlSelectStatement();
                query.TableNames.Add("cdCurrAcc", false);
                query.TableNames.Add("cdCurrAccDesc", false);

                query.Parameters.Add(new NebimV3.DataConnector.PropertyCondition("cdCurrAcc", "CurrAccCode"));
                query.Filter = new NebimV3.DataConnector.GroupCondition();
                query.Filter.AddCondition(
                    new NebimV3.DataConnector.BinaryCondition(
                        new NebimV3.DataConnector.PropertyCondition("cdCurrAcc", "CurrAccCode"),
                        new NebimV3.DataConnector.PropertyCondition("cdCurrAccDesc", "CurrAccCode")
                        ));


                if (description != null)
                {
                    query.Filter.AddCondition(
                        new NebimV3.DataConnector.BinaryCondition(
                            new NebimV3.DataConnector.PropertyCondition("cdCurrAccDesc", "CurrAccDescription"),
                            new NebimV3.DataConnector.ValueCondition(description)
                            ));
                }



                query.Filter.AddCondition(
                    new NebimV3.DataConnector.BinaryCondition(
                        new NebimV3.DataConnector.PropertyCondition("cdCurrAcc", "CurrAccTypeCode"),
                        new NebimV3.DataConnector.ValueCondition(NebimV3.ApplicationCommon.CurrAccTypes.RetailCustomer)
                        ));

                HashSet <string> results = new HashSet <string>();

                using (System.Data.IDataReader reader = NebimV3.DataConnector.SqlStatmentExecuter.ExecuteSelect(query))
                {
                    while (reader.Read())
                    {
                        results.Add((string)(reader["CurrAccCode"]));
                    }
                }

                // if (results.Count > 1)  // Örnek olarak yaptik. Exception atmak yerine ne yapilmasi gerektigi uygulamaya göre degisebilir.
                //     throw new Exception("More than one record with the same B2C customer Id");

                if (results.Count == 0)
                {
                    return(null);
                }

                customerCode = results.LastOrDefault();
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
            return(customerCode);
        }
Ejemplo n.º 7
0
        public string CreateUpdateCustomer(string description, string languageCode, string firstName, string lastName,
                                           List <string> emails, List <string> phones, string identityNum, byte genderCode = 3, string customerSegment = null, DateTime?registerDate = null)
        {
            try
            {
                NebimV3.CurrentAccounts.RetailCustomer customer = new NebimV3.CurrentAccounts.RetailCustomer();

                //check if customer exists by B2C id in description filed.
                string customerCode = null;
                if (_nebimIntegrationSettings.API_CustomerCodePrefix == null)
                {
                    customerCode = this.FindCustomerCodeByDescription(description);
                }
                else
                {
                    customerCode = GetCustomerCodeFromB2CId(description);
                }
                customer.RetailCustomerCode = customerCode;
                if (customer.ExistsInDB())
                {
                    customer.Load();
                }


                //lets keep "B2C customer id" in description
                customer.RetailCustomerDescription = description;
                customer.DataLanguageCode          = languageCode;//TR,EN
                customer.FirstName = firstName;
                customer.LastName  = lastName;
                if (registerDate.HasValue)
                {
                    customer.AccountOpeningDate = registerDate.Value;
                }

                customer.IdentityNum             = identityNum;
                customer.PersonalInfo.GenderCode = genderCode;//1:erkek,2:kadın,3:bilimiyor
                //if (customerCode != null)
                //{
                customer.SaveOrUpdate();
                //}
                //else
                //{
                //    customer.Save();

                //    customerCode = customer.RetailCustomerCode;
                //}
                #region müşteri idsi özellik olarak ekleniyor

                //B2C customer id,
                //SetAttribute(1, description, customer);
                //müşteri seviyesi, müşteri seviyeleri açılmış olması gerekiyor. (müşteri özelliği 2 noyu kullnacağız)
                if (!string.IsNullOrWhiteSpace(customerSegment))
                {
                    //SetExistingAttribute(2, customerSegment, customer);
                    SetAttribute(2, customerSegment, customer);
                }

                #endregion müşteri idsi özellik olarak ekleniyor

                NebimV3.CurrentAccounts.CurrAccCommunication comm = null;
                customer.Communications.Load();
                #region CommunicationTypeCode
                //1	EN	Telephone
                //2	EN	Fax
                //3	EN	E-Mail
                //4	EN	Home Phone
                //5	EN	Office Phone
                //6	EN	Business Mobile
                //7	EN	Personal Mobile
                //1	TR	Telefon
                //2	TR	Fax
                //3	TR	E-Posta
                //4	TR	Ev Telefonu
                //5	TR	İş Telefonu
                //6	TR	İş Cep Telefonu
                //7	TR	Özel Cep Telefonu
                #endregion CommunicationTypeCode

                foreach (var email in emails)
                {
                    if (CommunicationExists(customer.Communications, email))
                    {
                        continue;
                    }
                    comm = new NebimV3.CurrentAccounts.CurrAccCommunication(customer);
                    comm.CommunicationTypeCode = _nebimIntegrationSettings.API_CommunicationTypeEmail;
                    comm.CommAddress           = email;
                    comm.Save();
                    customer.Communications.Add(comm);
                }
                foreach (var phone in phones)
                {
                    if (CommunicationExists(customer.Communications, phone))
                    {
                        continue;
                    }
                    comm = new NebimV3.CurrentAccounts.CurrAccCommunication(customer);
                    comm.CommunicationTypeCode = _nebimIntegrationSettings.API_CommunicationTypePhone;
                    comm.CommAddress           = phone;
                    comm.Save();
                    customer.Communications.Add(comm);
                }
                return(customerCode); // Kaydederken otomatik olarak bir numara verilir. Bu numarayı kullanacağız.
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
        }