using Microsoft.Office.Interop.Excel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace KellyReport_D.Model { internal class ImportContext { public Workbook ImportWorkbook { get; set; } public Microsoft.Office.Interop.Excel.Application Application { get; set; } public IList ClientContactList { get; set; } public IList SalesDetails { get; set; } public class GroupedSalesDetailModel { public string SalesName { get; set; } public string ClientName { get; set; } public string ProductNameEN { get; set; } public decimal TotalAmount { get; set; } public List Details { get; set; } } public IEnumerable GroupedSalesDetailBySalesName => SalesDetails .GroupBy(x => x.SalesName.ToUpper()) .Select(grouped => new GroupedSalesDetailModel { SalesName = grouped.Key, TotalAmount = grouped.Sum(x => x.TotalAmount ?? 0), Details = grouped.ToList() }); public IEnumerable GetGroupedSalesDetailByClientName(IList salesDetails) { return salesDetails .GroupBy(x => new { SalesName = x.SalesName.ToUpper(), x.ClientName, x.ProductNameEN }) .Select(grouped => new GroupedSalesDetailModel { SalesName = grouped.Key.SalesName, ClientName = grouped.Key.ClientName, ProductNameEN = grouped.Key.ProductNameEN, TotalAmount = grouped.Sum(x => x.TotalAmount ?? 0), Details = grouped.ToList() }); } } }