public async Task <OperationResult> ImportExcel(string pathFile, string user) { using (var package = new ExcelPackage(new FileInfo(pathFile))) { ExcelWorksheet workSheet = package.Workbook.Worksheets[0]; int totalRows = workSheet.Dimension.Rows; for (int i = 2; i <= totalRows; i++) { ProductCategory_Dto productCategory = new ProductCategory_Dto(); productCategory.Product_Cate_Name = workSheet.Cells[i, 1].Value.ToSafetyString().Trim(); productCategory.Status = workSheet.Cells[i, 2].Value.ToBool(); productCategory.Position = workSheet.Cells[i, 3].Value.ToInt(); productCategory.Update_By = user; productCategory.Update_Time = DateTime.Now; try { await Create(productCategory); operationResult = new OperationResult { Message = "Import Success", Success = true }; } catch { operationResult = new OperationResult { Message = "Import Faild", Success = false }; } } } return(await Task.FromResult(operationResult)); }
public async Task <IActionResult> Update(ProductCategory_Dto model) { model.Update_By = User.FindFirst(ClaimTypes.Name).Value; model.Update_Time = DateTime.Now; var data = await _productCategoryService.Update(model); return(Ok(data)); }
public async Task <IActionResult> Update(ProductCategory_Dto model) { model.Update_By = User.FindFirst(ClaimTypes.Name).Value; model.Update_Time = DateTime.Now; var result = await _productCategoryService.Update(model); if (result.Success) { await _hubContext.Clients.All.LoadDataProductCate(); } return(Ok(result)); }
public async Task <OperationResult> Update(ProductCategory_Dto model) { var data = _mapper.Map <ProductCategory>(model); try { _productCategoryRepository.Update(data); await _productCategoryRepository.Save(); operationResult = new OperationResult { Success = true, Message = "Product Category was successfully updated." }; } catch (System.Exception) { operationResult = new OperationResult { Success = false, Message = "Product Category was failes updated." }; } return(operationResult); }
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); }