72 lines
1.6 KiB
C#
72 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using AutoMapper;
|
|
using AutoMapper.QueryableExtensions;
|
|
using InventoryTraker.Web.Core;
|
|
using InventoryTraker.Web.Data;
|
|
using InventoryTraker.Web.Models;
|
|
|
|
namespace InventoryTraker.Web.Controllers
|
|
{
|
|
public class ReportController : ControllerBase
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public ReportController(AppDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Distribution()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public ActionResult Distribution(DateTime startDate, DateTime endDate)
|
|
{
|
|
var query =
|
|
from t in _context.Transactions
|
|
where
|
|
t.TransactionType == TransactionType.Distributed
|
|
&& t.TransactionDate >= startDate
|
|
&& t.TransactionDate < endDate
|
|
group t by new { t.TransactionDate, t.Destination }
|
|
into g
|
|
select new
|
|
{
|
|
Date = g.Key.TransactionDate,
|
|
Destination = g.Key.Destination,
|
|
Transactions = g.ToList()
|
|
//(from transaction in g
|
|
//select Mapper.Map<TransactionViewModel>(transaction)).ToArray()
|
|
};
|
|
|
|
var report =
|
|
from item in query.ToArray()
|
|
select new DistributionReport
|
|
{
|
|
Date = item.Date,
|
|
Destination = item.Destination,
|
|
Transactions =
|
|
Mapper.Map<IList<Transaction>, IList<TransactionViewModel>>
|
|
(item.Transactions).ToArray()
|
|
};
|
|
|
|
return BetterJson(report.ToArray());
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult MonthlyInventory()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public ActionResult MonthlyInventory(DateTime month)
|
|
{
|
|
return BetterJson(true);
|
|
}
|
|
}
|
|
} |