Ejemplo n.º 1
0
        public void EditCategory(int id, NewCategory category)
        {
            var detail     = _attributeDetailRepository.GetAll().ToList();
            var dbCategory = _categoryRepository.Get(id);

            var newCategory = new Category
            {
                Id          = dbCategory.Id,
                Description = category.Description,
                Icon        = category.Icon,
                CreatedBy   = dbCategory.CreatedBy,
                ModifiedBy  = category.CreatedBy,
                Name        = category.Name,
                CreatedOn   = DateTime.Now
            };

            _categoryRepository.Update(newCategory, newCategory.Id);

            foreach (var attribute in detail.Where(attribute => attribute.CategoryId == id))
            {
                _attributeDetailRepository.Remove(attribute);
            }
            foreach (var attribute in category.Attributes.Select(newAttribute => new AttributeDetail
            {
                CategoryId = newCategory.Id,
                Name = newAttribute.Name,
                Type = newAttribute.Type,
                IsMandatory = newAttribute.IsMandatory
            }))
            {
                _attributeDetailRepository.Add(attribute);
            }
        }
Ejemplo n.º 2
0
        public void PostCategory(NewCategory category)
        {
            var newCategory = new Category();
            var detail      = new AttributeDetail();

            newCategory.CreatedBy   = category.CreatedBy;
            newCategory.Name        = category.Name;
            newCategory.Description = category.Description;
            newCategory.Icon        = category.Icon;
            newCategory.CreatedOn   = DateTime.Now;
            _categoryRepository.Add(newCategory);
            foreach (var attribute in category.Attributes)
            {
                detail.CategoryId  = newCategory.Id;
                detail.IsMandatory = attribute.IsMandatory;
                detail.Name        = attribute.Name;
                detail.Type        = attribute.Type;
                _attributeDetailRepository.Add(detail);
                detail = new AttributeDetail();
            }
        }