public static CategoryDTO CategoryToCategoryDTO(Category category) { var categoryDTO = new CategoryDTO(); categoryDTO.CategoryID = category.ID; categoryDTO.CategoryName = category.CategoryName; categoryDTO.CategoryCode = category.CategoryCode; categoryDTO.Order = category.Order; categoryDTO.CategoryLevel = category.CategoryLevel; categoryDTO.CategoryImage = category.CategoryImage; return categoryDTO; }
public void UpdateCategoryInformation(int id, CategoryDTO categoryDTO) { if (categoryDTO == null) throw new ArgumentException(LocalizerFactory.CreateLocalizer().GetString("warning_CannotAddCategoryWithNullInformation", typeof(ApplicationErrors))); var originalCategory = _categoryRepository.Get(id); if(originalCategory == null) throw new ArgumentException(LocalizerFactory.CreateLocalizer().GetString("warning_CategoryDoesNotExists", typeof(ApplicationErrors))); var updatedCategory = new Category() { // Can input modified date and modified by here ID = id, CategoryCode = categoryDTO.CategoryCode, CategoryImage = categoryDTO.CategoryImage, CategoryLevel = categoryDTO.CategoryLevel, CategoryName = categoryDTO.CategoryName, Order = categoryDTO.Order }; UpdateCategory(originalCategory, updatedCategory); }
Category UpdateCategory(Category originalCategory, Category updatedCategory) { var entityValidator = EntityValidatorFactory.CreateValidator(); if (entityValidator.IsValid(updatedCategory)) { _categoryRepository.Merge(originalCategory, updatedCategory); _categoryRepository.UnitOfWork.Commit(); return updatedCategory; } else { throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(updatedCategory)); } }
public void SaveCategoryInformation(CategoryDTO categoryDTO) { if (categoryDTO == null) { throw new ArgumentException(LocalizerFactory.CreateLocalizer().GetString("warning_CannotAddCategoryWithNullInformation", typeof(ApplicationErrors))); } var category = new Category() { CategoryCode = categoryDTO.CategoryCode, CategoryImage = categoryDTO.CategoryImage, CategoryLevel = categoryDTO.CategoryLevel, CategoryName = categoryDTO.CategoryName, Order = categoryDTO.Order }; SaveCategory(category); }
Category SaveCategory(Category category) { var entityValidator = EntityValidatorFactory.CreateValidator(); if (entityValidator.IsValid(category)) { _categoryRepository.Add(category); _categoryRepository.UnitOfWork.Commit(); return category; } else { throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(category)); } }