Ejemplo 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;
            }
        }
Ejemplo n.º 2
0
 private Category TranslateCategoryEntityToCategory(CategoryEntity categoryEntity)
 {
     Category category = new Category()
     {
         CategoryId = categoryEntity.CategoryId,
         Name = categoryEntity.Name,
         Description = categoryEntity.Description,
         Picture = categoryEntity.Picture,
     };
     return category;
 }