public static CategoryModel ConvertCategoryDTOtoCategoryModel(CategoryDTO categoryDTO) { var categoryModel = new CategoryModel(); categoryModel.Id = categoryDTO.CategoryID; categoryModel.Code = categoryDTO.CategoryCode; categoryModel.Name = categoryDTO.CategoryName; categoryModel.CategoryImage = categoryDTO.CategoryImage; categoryModel.Order = categoryDTO.Order; return categoryModel; }
//// POST api/categorymanagerment public HttpResponseMessage Post(CategoryDTO categoryDTO) { try { _categoryManager.SaveCategoryInformation(categoryDTO); return Request.CreateResponse(HttpStatusCode.OK, categoryDTO); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, ex.Message); } }
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 static CategoryDTO ConvertCategoryModelToCategoryDTO(CategoryModel categoryModel) { var categoryDTO = new CategoryDTO() { CategoryID = categoryModel.Id.HasValue ? categoryModel.Id.Value : int.MaxValue, CategoryCode = categoryModel.Code, CategoryImage = categoryModel.CategoryImage, CategoryName = categoryModel.Name, //CategoryLevel = categoryModel. Order = categoryModel.Order }; return categoryDTO; }
// PUT api/categorymanagerment/5 public HttpResponseMessage Put(int id, CategoryDTO categoryDTO) { try { //var categoryDTO = Application.Web.Module.Product.Models.Category.CategoryModelUtis.ConvertCategoryModelToCategoryDTO(category); _categoryManager.UpdateCategoryInformation(id, categoryDTO); return Request.CreateResponse(HttpStatusCode.OK, categoryDTO); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, ex.Message); } }
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); }
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); }