public dynamic GetList([FromQuery] API.Models.Brand.BrandCriteriaModel criteria, [FromQuery] IDataTablesRequest request) { try { //var query = _accountService.GetByCriteria(criteria); var query = _brandService.GetAll(); var brands = query .Select(x => new API.Models.Brand.BrandCriteriaModel { Id = x.ProductBrandId, BrandName = x.ProductBrandName, }) .ToList() .AsQueryable(); var filteredData = brands; return(ToDataTableResponse <API.Models.Brand.BrandCriteriaModel>(filteredData, request)); } catch (Exception ex) { _logger.LogError(ex, this.GetType().Name); return(ToDataTableResponse <API.Models.Brand.BrandCriteriaModel>()); } }
public async Task <ResponseViewModel> Create(int id, [FromBody] API.Models.Brand.BrandCriteriaModel model) { //var oldBrand = await _brandService.GetByIdWithoutInclude(model.GetByIdWithoutInclude); var oldBrand = await _brandService.GetById(id); if (oldBrand != null) { var response = new ResponseViewModel { Result = false, }; response.Messages.Add("Tên nhãn hiệu đã tồn tại"); return(response); } else { var productBrand = new ProductBrand { ProductBrandName = model.BrandName, }; ApplyUserCreateEntity(productBrand); return(await SaveOrUpdate(productBrand)); } }
public async Task <API.Models.Brand.BrandCriteriaModel> GetById(int id) { API.Models.Brand.BrandCriteriaModel response; var brand = await _brandService.GetById(id); if (brand != null) { response = new API.Models.Brand.BrandCriteriaModel { Id = brand.ProductBrandId, BrandName = brand.ProductBrandName, }; } else { response = new API.Models.Brand.BrandCriteriaModel { }; } return(response); }
public async Task <ResponseViewModel> Update(int id, [FromBody] API.Models.Brand.BrandCriteriaModel model) { var oper = await _brandService.GetById(id); if (oper == null) { var response = new ResponseViewModel { Result = false, }; response.Messages.Add("Không tìm thấy nhãn hiệu"); return(response); } oper.ProductBrandName = model.BrandName; ApplyUserUpdateEntity(oper); return(await SaveOrUpdate(oper)); }