private void Generate_Save_NetSuiteLst(List <FoodicsInventoryItem> lstitems, string Subsidiary)
        {
            try
            {
                List <Item> NetSuitelst = new List <Item>();
                foreach (var Foodicsitem in lstitems)
                {
                    Item Netsuiteitem = new Item();
                    Netsuiteitem.Foodics_Id             = Foodicsitem.id;
                    Netsuiteitem.Item_Type              = (int)Item_Type.InventoryItem;
                    Netsuiteitem.Item_Type_Name         = nameof(Item_Type.InventoryItem);
                    Netsuiteitem.Foodics_Item_Type_Name = nameof(FoodicsItem_Type.InventoryItem);
                    Netsuiteitem.Name_Ar         = Foodicsitem.name_localized;
                    Netsuiteitem.Name_En         = Foodicsitem.name;
                    Netsuiteitem.Display_Name_Ar = Foodicsitem.name_localized;
                    Netsuiteitem.Display_Name_En = Foodicsitem.name;
                    Netsuiteitem.InActive        = Foodicsitem.deleted_at != null ? true : false;
                    Netsuiteitem.UPC_Code        = Foodicsitem.sku;
                    Netsuiteitem.Storage_Unit    = Foodicsitem.storage_unit;
                    Netsuiteitem.Ingredient_Unit = Foodicsitem.ingredient_unit;
                    Netsuiteitem.storage_to_ingredient_factor = Foodicsitem.storage_to_ingredient_factor;
                    Netsuiteitem.FoodicsUpdateDate            = Foodicsitem.updated_at;
                    Netsuiteitem.Subsidiary_Id = Utility.ConvertToInt(ConfigurationManager.AppSettings[Subsidiary + "Netsuite.Subsidiary_Id"]);
                    if (Foodicsitem.category != null && !string.IsNullOrEmpty(Foodicsitem.category.id))
                    {
                        Netsuiteitem.FoodicsCategory_Id = Foodicsitem.category.id;
                        Categories.FoodicsCategories obj = new GenericeDAO <Categories.FoodicsCategories>().GetByFoodicsId(Foodicsitem.category.id);
                        Netsuiteitem.Category_Id = obj.Netsuite_Id;
                    }

                    int UnitsOfMeasure_Id = 0;
                    if (!string.IsNullOrEmpty(Netsuiteitem.Ingredient_Unit))
                    {
                        UnitsOfMeasure_Id = new CustomDAO().Check_Create_unitName(Netsuiteitem.Ingredient_Unit);
                    }

                    if (UnitsOfMeasure_Id > 0 && Netsuiteitem.Storage_Unit.ToLower() != Netsuiteitem.Ingredient_Unit.ToLower())
                    {
                        UnitsOfMeasureIngredient obj = new UnitsOfMeasureIngredient();
                        obj.Storage_To_Ingredient_Value = Netsuiteitem.storage_to_ingredient_factor;
                        obj.unitName          = Netsuiteitem.Storage_Unit;
                        obj.UnitsOfMeasure_Id = UnitsOfMeasure_Id;

                        new CustomDAO().Check_Create_unitName_ingredient(obj);
                    }
                    else if (!string.IsNullOrEmpty(Netsuiteitem.Storage_Unit) && Netsuiteitem.Storage_Unit.ToLower() != Netsuiteitem.Ingredient_Unit.ToLower())
                    {
                        new CustomDAO().Check_Create_unitName(Netsuiteitem.Storage_Unit);
                    }
                    Netsuiteitem.Price = Utility.ConvertToDouble(Foodicsitem.cost);

                    NetSuitelst.Add(Netsuiteitem);
                }
                new GenericeDAO <Item>().FoodicsIntegration(NetSuitelst, false);
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
        }
Beispiel #2
0
        public void Check_Create_unitName_ingredient(UnitsOfMeasureIngredient obj)
        {
            StringBuilder query = new StringBuilder();

            query.Append("IF NOT EXISTS(SELECT id FROM UnitsOfMeasureIngredient WHERE Storage_To_Ingredient_Value='" + obj.Storage_To_Ingredient_Value + "' and unitName = '" + obj.unitName + "' and UnitsOfMeasure_Id=" + obj.UnitsOfMeasure_Id + " )");
            query.Append(" begin insert into UnitsOfMeasureIngredient (UnitsOfMeasure_Id,unitName,Storage_To_Ingredient_Value,InActive,UpdateDate,CreateDate)");
            query.Append(" values('" + obj.UnitsOfMeasure_Id + "','" + obj.unitName + "','" + obj.Storage_To_Ingredient_Value + "','False',GETDATE(),GETDATE()) end ");
            using (db)
            {
                db.ExecuteScalar(query.ToString());
            }
        }