public int AddIndustryCategory(IndustryCategoryModel categoryModel)
        {
            int CategoryId = 0;
            try
            {
                CategoryId = (from cat in DatabaseConnection.IndustryCategories
                              where cat.CategoryName.ToLower() == categoryModel.CategoryName.ToLower()
                              select cat.Id).FirstOrDefault();
                if (CategoryId == 0)
                {
                    DatabaseConnection.IndustryCategories.Add(new WorldRef.IndustryCategory()
                    {
                        IndustryId = categoryModel.IndustryId,
                        CategoryName = categoryModel.CategoryName,
                        createdon = DateTime.Now
                    });

                    DatabaseConnection.SaveChanges();

                    CategoryId = (from cat in DatabaseConnection.IndustryCategories
                                  where cat.CategoryName.ToLower() == categoryModel.CategoryName.ToLower()
                                  select cat.Id).FirstOrDefault();
                }

            }
            catch (Exception ex)
            {
                CategoryId = 0;
            }
            return CategoryId;
        }
Exemplo n.º 2
0
        public int AddIndustryCategory(IndustryCategoryModel categoryModel)
        {
            int CategoryId = 0;

            try
            {
                CategoryId = (from cat in DatabaseConnection.IndustryCategories
                              where cat.CategoryName.ToLower() == categoryModel.CategoryName.ToLower()
                              select cat.Id).FirstOrDefault();
                if (CategoryId == 0)
                {
                    DatabaseConnection.IndustryCategories.Add(new WorldRef.IndustryCategory()
                    {
                        IndustryId   = categoryModel.IndustryId,
                        CategoryName = categoryModel.CategoryName,
                        createdon    = DateTime.Now
                    });

                    DatabaseConnection.SaveChanges();

                    CategoryId = (from cat in DatabaseConnection.IndustryCategories
                                  where cat.CategoryName.ToLower() == categoryModel.CategoryName.ToLower()
                                  select cat.Id).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                CategoryId = 0;
            }
            return(CategoryId);
        }