Esempio n. 1
0
        public int CreateNewCategory(Category category)
        {
            using (DobbermanEntities context = new DobbermanEntities())
            {
                // find out if category already exists by its name
                CategoryEntity validateCategory = (from p
                                             in context.Categories
                                                     where p.Name == category.Name
                                                     select p).FirstOrDefault();
                if (!(validateCategory == null)) return validateCategory.CategoryId;

                CategoryEntity categoryEntity = new CategoryEntity()
                {
                    Name = category.Name,
                    Description = category.Description,
                    Picture = category.Picture,

                };
                context.AddToCategories(categoryEntity);
                context.SaveChanges();
                return categoryEntity.CategoryId;
            }
        }
 /// <summary>
 /// Create a new CategoryEntity object.
 /// </summary>
 /// <param name="categoryId">Initial value of the CategoryId property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static CategoryEntity CreateCategoryEntity(global::System.Int32 categoryId, global::System.String name)
 {
     CategoryEntity categoryEntity = new CategoryEntity();
     categoryEntity.CategoryId = categoryId;
     categoryEntity.Name = name;
     return categoryEntity;
 }
Esempio n. 3
0
 private Category TranslateCategoryEntityToCategory(CategoryEntity categoryEntity)
 {
     Category category = new Category()
     {
         CategoryId = categoryEntity.CategoryId,
         Name = categoryEntity.Name,
         Description = categoryEntity.Description,
         Picture = categoryEntity.Picture,
     };
     return category;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategories(CategoryEntity categoryEntity)
 {
     base.AddObject("Categories", categoryEntity);
 }