Example #1
0
        public static Category ToDao(this AbstractEntities.NewCategory dto)
        {
            if (dto == null)
            {
                return(null);
            }

            return(new Category
            {
                Name = dto.Name
            });
        }
Example #2
0
        public AbstractEntities.Category CreateCategory(AbstractEntities.NewCategory newCategory)
        {
            if (newCategory == null)
            {
                throw new ArgumentNullException("newCategory");
            }

            lock (syncObject)
            {
                if (context.Categories.Any(c => string.Compare(c.Name, newCategory.Name, true) == 0))
                {
                    throw new RecordAlreadyExistsException($"Category with name \"{newCategory.Name}\" already exists.");
                }

                var dao = newCategory.ToDao();
                context.Categories.Add(dao);
                context.SaveChanges();

                return(dao.ToAbstract());
            }
        }