public async Task <IActionResult> Post(int id, [FromBody] AddNewQuotationItemRequest request) { request.QuotationID = id; bool result = await _QuotationItemAppService.addNewQuotation(request); if (result) { return(Ok(result)); } return(NotFound(result)); }
public async Task <IActionResult> ImportQuotation([FromQuery] AddNewQuotationRequest request) { IFormFile file = Request.Form.Files[0]; ISheet sheet = ImportExcelCommon.GetSheetFromFile(file, "Quotation\\Customer_" + request.customer_code); if (sheet != null) { IRow headerRow = sheet.GetRow(11); //Get Header Row int cellCount = headerRow.LastCellNum; int startRow = 12; int lastRow = sheet.LastRowNum; //thuc hien them moi dot bao gia cho khach hang int QuotationId = (await _QuotationAppService.addNewQuotation(request)).Data; if (QuotationId <= 0) { return(BadRequest()); } //them cac san pham vao dot bao gia for (int i = startRow; i <= lastRow; i++) //Read Excel File { IRow row = sheet.GetRow(i); if (row == null) { continue; } if (row.Cells.All(d => d.CellType == CellType.Blank)) { continue; } int startCell = row.FirstCellNum + 1; AddNewQuotationItemRequest itemRequest = new AddNewQuotationItemRequest(); string code = row.GetCell(startCell++).ToString(); if (string.IsNullOrWhiteSpace(code)) { continue; } itemRequest.ProductCode = code; itemRequest.QuotationID = QuotationId; //gia int price = -1; Int32.TryParse(row.GetCell(4).ToString(), out price); if (price == -1) { continue; } itemRequest.Price = price; UnitModel unit = _UnitRepository.GetByName(row.GetCell(3).ToString().ToLower()); if (unit == null) { continue; } itemRequest.UnitID = unit.ID; await _QuotationItemAppService.addNewQuotation(itemRequest); } return(Ok()); } return(BadRequest()); }