public static ResponseViewModel <ProductAttribute> AddProductAttribute(ProductAttributeViewModel viewModel) { ResponseViewModel <ProductAttribute> responseViewModel = new ResponseViewModel <ProductAttribute>(); ProductAttribute productAtribute = new ProductAttribute(); productAtribute.Name = viewModel.attributeName; productAtribute.ProductCategoryID = viewModel.productCategoryId; productAtribute.ProductSubCategoryID = viewModel.productSubCategoryId; using (EcommerceEntities entities = new EcommerceEntities()) { if (CheckDuplicate(productAtribute)) { responseViewModel.errorViewModel = new ErrorViewModel(); responseViewModel.errorViewModel.statusCode = 400; } else { entities.ProductAttributes.Add(productAtribute); entities.SaveChanges(); ProductAttributeManager.AddOption(viewModel.options, productAtribute.ID); responseViewModel.Data = productAtribute; entities.SaveChanges(); } } return(responseViewModel); }
public static ResponseViewModel <ProductAttribute> UpdateProductAttribute(ProductAttributeViewModel viewModel) { ResponseViewModel <ProductAttribute> responseViewModel = new ResponseViewModel <ProductAttribute>(); using (EcommerceEntities entities = new EcommerceEntities()) { ProductAttribute productAtributeDb = entities.ProductAttributes.Where(entry => entry.ID == viewModel.ID).FirstOrDefault(); productAtributeDb.Name = viewModel.attributeName; productAtributeDb.ProductCategoryID = viewModel.productCategoryId; productAtributeDb.ProductSubCategoryID = viewModel.productSubCategoryId; entities.SaveChanges(); ProductAttributeManager.AddOption(viewModel.options, productAtributeDb.ID); responseViewModel.Data = productAtributeDb; entities.SaveChanges(); return(responseViewModel); } }