public async Task <IActionResult> PutOrderEntry([FromRoute] Guid id, [FromBody] FullOrder order) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order.OrderID) { return(BadRequest()); } _context.Entry(order).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostOrderEntry([FromBody] OrderEntry orderEntry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.OrderEntries.Add(orderEntry); await _context.SaveChangesAsync(); //Make the HTTP Client Call to Products API for product info, Add to Full Order DB //Get Full list of Products, URL: https://localhost:44350/api/products //Get Specific Product, URL: https://localhost:44350/api/products/id //List of Products to be added to FullOrder List <Products> products = new List <Products>(); //The 'using' will help to prevent memory leaks. //Create a new instance of HttpClient using (HttpClient client = new HttpClient()) //Setting up the response... //iterate through list of Product IDs, adding the products to Products List foreach (var id in orderEntry.Items) { string baseUrl = $"https://localhost:44350/api/products/{id.ProductID}"; using (HttpResponseMessage res = await client.GetAsync(baseUrl)) using (HttpContent content = res.Content) { Products data = await content.ReadAsAsync <Products>(); if (data != null) { products.Add(data); } } } //FullOrder object FullOrder fullOrder = new FullOrder { OrderID = Guid.NewGuid(), orderEntry = orderEntry, Products = products }; //Add Fullorder object to FullOrder DB _context.FullOrders.Add(fullOrder); await _context.SaveChangesAsync(); return(CreatedAtAction("GetOrderEntry", new { id = orderEntry.CustomerID }, fullOrder)); }
public async Task <Stream> GetFile(FullOrder fullOrder) { using (var workbook = new XLWorkbook()) { var worksheet = workbook.Worksheets.Add("Заказ"); var colA = worksheet.Column("A"); colA.Width = 10; var colB = worksheet.Column("B"); colB.Width = 10; var colC = worksheet.Column("C"); colC.Width = 10; var colD = worksheet.Column("D"); colD.Style.Alignment.WrapText = true; colD.Width = 50; var colE = worksheet.Column("E"); colE.Style.Alignment.WrapText = true; colE.Width = 20; //Order worksheet.Cell("A1").SetValue("Заказ"); worksheet.Cell("C1").SetValue(_fullOrder.order.id); worksheet.Cell("H1").SetValue("Дата"); worksheet.Cell("I1").SetValue(_fullOrder.order.creationDate); worksheet.Cell("H2").SetValue("Статус"); worksheet.Cell("I2").SetValue(_fullOrder.order.statusId); worksheet.Cell("A3").SetValue("Магазин"); worksheet.Cell("C3").SetValue(_fullOrder.order.storeId); worksheet.Cell("H3").SetValue("Отдел"); worksheet.Cell("I3").SetValue(_fullOrder.order.deparmentId); worksheet.Cell("A5").SetValue("Автор - " + _fullOrder.order.author); worksheet.Cell("A5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; worksheet.Cell("A1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; worksheet.Cell("A1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; worksheet.Range("A1:B2").Merge(); worksheet.Cell("C1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; worksheet.Cell("C1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; worksheet.Cell("C1").Style.Font.FontSize = 22; worksheet.Range("C1:G2").Merge(); worksheet.Range("I1:K1").Row(1).Merge(); worksheet.Range("I2:K2").Row(1).Merge(); worksheet.Cell("A3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; worksheet.Cell("A3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; worksheet.Range("A3:B4").Merge(); worksheet.Cell("C3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; worksheet.Cell("C3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; worksheet.Range("C3:G4").Merge(); worksheet.Cell("H3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; worksheet.Cell("H3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; worksheet.Range("H3:H4").Column(1).Merge(); worksheet.Cell("I3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; worksheet.Cell("I3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; worksheet.Range("I3:K4").Merge(); worksheet.Range("A5:K5").Row(1).Merge(); //OrderBody worksheet.Cell("A6").SetValue("Группа"); worksheet.Cell("B6").SetValue("Артикул"); worksheet.Cell("C6").SetValue("Штпихкод"); worksheet.Cell("D6").SetValue("Наименование"); worksheet.Cell("E6").SetValue("Поставщик"); worksheet.Cell("F6").SetValue("Остаток"); worksheet.Cell("G6").SetValue("Ср. реал"); worksheet.Cell("H6").SetValue("Запас дней"); worksheet.Cell("I6").SetValue("Дата пост."); worksheet.Cell("J6").SetValue("Ком. рук."); worksheet.Cell("K6").SetValue("Примечание"); //FreezeRows worksheet.SheetView.FreezeRows(6); var currentRow = 7; foreach (var item in _fullOrder.orderBodies) { worksheet.Cell(currentRow, 1).Value = item.group; worksheet.Cell(currentRow, 1).DataType = XLDataType.Text; worksheet.Cell(currentRow, 2).Value = item.article; worksheet.Cell(currentRow, 2).DataType = XLDataType.Number; worksheet.Cell(currentRow, 3).Value = item.barcode; worksheet.Cell(currentRow, 3).DataType = XLDataType.Number; worksheet.Cell(currentRow, 4).Value = item.name; worksheet.Cell(currentRow, 4).DataType = XLDataType.Text; worksheet.Cell(currentRow, 5).Value = item.supplier; worksheet.Cell(currentRow, 5).DataType = XLDataType.Text; worksheet.Cell(currentRow, 6).Value = item.goods; worksheet.Cell(currentRow, 6).DataType = XLDataType.Number; worksheet.Cell(currentRow, 7).Value = item.average; worksheet.Cell(currentRow, 7).DataType = XLDataType.Number; worksheet.Cell(currentRow, 8).Value = item.stockDay; worksheet.Cell(currentRow, 8).DataType = XLDataType.Number; worksheet.Cell(currentRow, 9).Value = new DateTime(2010, 9, 2); worksheet.Cell(currentRow, 9).DataType = XLDataType.DateTime; worksheet.Cell(currentRow, 10).Value = item.managerСomment; worksheet.Cell(currentRow, 10).DataType = XLDataType.Text; worksheet.Cell(currentRow, 11).Value = item.departmentComment; worksheet.Cell(currentRow, 11).DataType = XLDataType.Text; currentRow++; } worksheet.Range($"A1:K{currentRow - 1}").Style.Border.TopBorder = XLBorderStyleValues.Thin; worksheet.Range($"A1:K{currentRow - 1}").Style.Border.InsideBorder = XLBorderStyleValues.Thin; worksheet.Range($"A1:K{currentRow - 1}").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; worksheet.Range($"A1:K{currentRow - 1}").Style.Border.LeftBorder = XLBorderStyleValues.Thin; worksheet.Range($"A1:K{currentRow - 1}").Style.Border.RightBorder = XLBorderStyleValues.Thin; worksheet.Range($"A1:K{currentRow - 1}").Style.Border.TopBorder = XLBorderStyleValues.Thin; // Adjust column width worksheet.Columns(6, 11).AdjustToContents(); worksheet.PageSetup.PrintAreas.Add($"A1:K{currentRow - 1}"); worksheet.PageSetup.PageOrientation = XLPageOrientation.Landscape; worksheet.PageSetup.SetRowsToRepeatAtTop(6, 6); using (var stream = new MemoryStream()) { workbook.SaveAs(stream); //var content = stream.ToArray(); using (FileStream file = new FileStream("output.xlsx", FileMode.OpenOrCreate, FileAccess.Write)) { stream.WriteTo(file); file.Close(); stream.Close(); } return(stream); } } }