public bool SaveEntity(ProductCategoryModel productCategoryModel) { try { if (productCategoryModel.Id > 0) { var productCategory = GetProductCategoryById(productCategoryModel.Id).ToProductCategory(); productCategory.Id = productCategoryModel.Id; productCategory.Name = productCategoryModel.Name; productCategory.UpdatedDate = DateTime.Now; productCategory.ParentId = productCategoryModel.ParentId; productCategory.Status = productCategoryModel.Status; _productCategoryRepository.Update(productCategory); return(true); } else { var productCategory = new ProductCategory(); productCategory.Id = productCategoryModel.Id; productCategory.Name = productCategoryModel.Name; productCategory.ParentId = productCategoryModel.ParentId; productCategory.Status = productCategoryModel.Status; productCategory.CreatedDate = DateTime.Now; _productCategoryRepository.Add(productCategory); return(true); } } catch (Exception ex) { return(false); } }
public int AddCategory(Models.DomainModels.ProductCategory productCategory) { prodCategoryRepository.Add(productCategory); prodCategoryRepository.SaveChanges(); return(productCategory.ProductCategoryID); // If Exception occurs this line will not be executed }
public ProductCategoryViewModel Add(ProductCategoryViewModel productCategoryVm) { var productCategory = Mapper.Map <ProductCategoryViewModel, ProductCategory>(productCategoryVm); _productCategoryRepository.Add(productCategory); return(productCategoryVm); }
public async Task <ProductCategoryViewModel> Add(ProductCategoryViewModel productCategoryVm) { var productCategory = new ProductCategoryViewModel().Map(productCategoryVm); await _productCategoryRepository.Add(productCategory); return(productCategoryVm); }
public ProductCategoryViewModel Add(ProductCategoryViewModel productCategoryVm) { var productCategory = _mapper.Map <ProductCategory>(productCategoryVm); _productCategoryRepository.Add(productCategory); _unitOfWork.Commit(); return(productCategoryVm); }
public ProductCategory Add(ProductCategory productCategory) { if (_productCategoryRepository.CheckContains(x => x.Name == productCategory.Name)) { throw new NameDuplicatedException("Tên danh mục không được trùng"); } return(_productCategoryRepository.Add(productCategory)); }
public async Task <string> Handle(CreateProductCategoryCommand request, CancellationToken cancellationToken) { var newProductCategoryToAdd = new ProductCategory(request.Name, request.PhotoUrl); _productCategoryRepository.Add(newProductCategoryToAdd); await _productCategoryRepository.UnitOfWork.SaveEntitiesSeveralTransactionsAsync(cancellationToken); return(newProductCategoryToAdd.Id.ToString()); }
public async Task <IActionResult <int> > Handle(ProductCategoryAddRequestDto request, CancellationToken cancellationToken) { await _validatorService.ValidateCommand(request); var category = _mapper.Map <Data.Entities.ProductCategory>(request); _categoryRepository.Add(category); return(ActionResult <int> .Success(category.Id)); }
public void AddProductCategory(ProductCategoryViewModel viewModel) { var category = new ProductCategory { Name = viewModel.Name }; _productCategoryRepository.Add(category); _productCategoryRepository.SaveChanges(); }
public override async Task <ActionResult> HandleAsync([FromBody] CreateProductCategoryRequest request, CancellationToken cancellationToken = default) { var ProductCategory = new ProductCategory { Name = request.Name }; await _repo.Add(ProductCategory); await _repo.Save(); return(Ok(ProductCategory)); }
public void ProductCategory_Repository_Add() { ProductCategory productCategory = new ProductCategory(); productCategory.Name = "Test product category"; productCategory.Alias = "Test-product-category"; productCategory.Status = true; productCategory.CreateDate = DateTime.Now; var result = objRepository.Add(productCategory); unitOfWork.Commit(); Assert.AreEqual(8, result.ID); }
private void _AddProductCategories(IEnumerable <int> toBeAddedCategoriesLinks, int productId) { foreach (var categoryId in toBeAddedCategoriesLinks) { var productCategory = new ProductCategory { CategoryId = categoryId, ProductId = productId }; _productCategoryRepository .Add(productCategory); } }
public async Task <ActionResult <ProductCategory> > PostProductCategories(ProductCategory productCategory) { if (ModelState.IsValid) { ProductCategory productCatNew = await _productCategories.Add(productCategory); return(CreatedAtAction("GetProductCategories", new { id = productCatNew.ProductCategoryId }, productCatNew)); } else { return(BadRequest(ModelState)); } }
public void ProductCategoryRepositoryCreate() { ProductCategory product = new ProductCategory(); product.ProductCategoryName = "San Pham 1"; product.ProductCategoryAlias = "San-Pham-1"; product.Status = true; var result = objRepository.Add(product); unitOfWork.Commit(); Assert.IsNotNull(result); Assert.AreEqual(1, result.ProductCategoryID); }
public void ProductCategory_Repository_Create() { ProductCategory productCategory = new ProductCategory(); productCategory.Name = "Test category"; productCategory.Alias = "Test-category"; productCategory.Status = true; var result = objRepository.Add(productCategory); unitOfWork.Commit(); Assert.IsNotNull(result); Assert.AreEqual(2, result.ID); }
public void ProductCategory_Repository_Test() { ProductCategory productCategory = new ProductCategory { Name = "Test product category", Alias = "Test-product-category", Status = true }; var result = productCategoryRepository.Add(productCategory); unitOfWork.Commit(); Assert.AreEqual(1, result.ID); Assert.IsNotNull(result); }
public IActionResult CreateProductCategory(CreateProductCategoryViewModel model) { if (ModelState.IsValid) { ProductCategory productCategory = new ProductCategory() { Name = model.ProductCategoryName }; productCategoryRepository.Add(productCategory); productCategoryRepository.Save(); return(RedirectToAction("ListProductCategories")); } return(View(model)); }
public BaseViewModel <ProductCategoryViewModel> CreateProductCategory(CreateProductCategoryRequestViewModel request) { var entity = _mapper.Map <ProductCategory>(request); entity.Id = Guid.NewGuid(); entity.SetDefaultInsertValue(_repository.GetUsername()); _repository.Add(entity); var result = new BaseViewModel <ProductCategoryViewModel>() { Data = _mapper.Map <ProductCategoryViewModel>(entity), StatusCode = HttpStatusCode.OK }; Save(); return(result); }
public IActionResult SaveEntity(ProductCategoryViewModel productVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (productVm.Id == 0) { _productCategoryRepository.Add(productVm); } else { _productCategoryRepository.Update(productVm); } _productCategoryRepository.Save(); return(new OkObjectResult(productVm)); } }
public ProductCategory Add(ProductCategoryAction entity) { try { ProductCategory category = new ProductCategory(); category.Avatar = "http://localhost:44351/" + entity.Avatar; category.CreateBy = entity.CreateBy; category.CreateDate = DateTime.Now; category.Desc = entity.Desc; category.ID = entity.ID; category.ModifyBy = entity.ModifyBy; category.ModifyDate = DateTime.Now; category.Rank = entity.Rank; category.Status = entity.Status; category.Title = entity.Title; return(_productCategory.Add(category)); } catch (Exception) { return(null); } }
public GeneralResponse AddProductCategory(AddProductCategoryRequest request) { GeneralResponse response = new GeneralResponse(); try { ProductCategory productCategory = new ProductCategory(); productCategory.ID = Guid.NewGuid(); productCategory.CreateDate = PersianDateTime.Now; productCategory.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID); productCategory.ProductCategoryName = request.ProductCategoryName; productCategory.Note = request.Note; productCategory.Discontinued = request.Discontinued; productCategory.RowVersion = 1; _productCategoryRepository.Add(productCategory); _uow.Commit(); ////response.success = true; // Validation if (productCategory.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in productCategory.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } return(response); }
public async Task <OperationResult> Create(ProductCategory_Dto model) { model.Product_Cate_ID = await GetProductCategoryID(); var data = _mapper.Map <ProductCategory>(model); try { _productCategoryRepository.Add(data); await _productCategoryRepository.Save(); operationResult = new OperationResult { Success = true, Message = "Product Category was successfully added." }; } catch (System.Exception) { operationResult = new OperationResult { Success = false, Message = "Product Category was exists." }; } return(operationResult); }
public ProductCategory Add(ProductCategory productCategory) { var result = _productCategoryRepository.Add(productCategory); return(_uow.Commit() ? result : null); }
public ProductCategory Add(ProductCategory productCategory) { productCategory.CreatedDate = DateTime.Now; return(_productCategoryRepository.Add(productCategory)); }
public async Task Add(ProductCategoryDto dto) { var entity = dto.MapToEntity(); await _productCategoryRepository.Add(entity); }
ProductCategory ICategoryService.Add(ProductCategory cate) { return(_cateRepository.Add(cate)); //throw new NotImplementedException(); }
public bool Add(ProductCategory entity) { return(repository.Add(entity)); }
public void CreateProductCategory(ProductCategory productCategory) { productCategoryRepository.Add(productCategory); }
public ProductCategory Add(ProductCategory ProductCategory) { return(_ProductCategoryRepository.Add(ProductCategory)); }
public ProductCategory Insert(ProductCategory entity) { return(_ProductCategoryRepository.Add(entity)); }