public IActionResult OrdersInDay([FromBody] OrderTodayReq req) { var res = new SingleRsp(); res.Data = _svc.OrdersInDay(req); return(Ok(res)); }
/// <summary> /// câu 4: danh sách đơn hàng theo ngày nhập vô /// </summary> /// <param name="req"></param> /// <returns>danh sách đơn hàng, tên khách hàng, địa chỉ cần giao trong ngày đó có phân trang</returns> public object OrdersInDay(OrderTodayReq req) { var res = from o in Context.Orders join c in Context.Customers on o.CustomerId equals c.CustomerId where o.OrderDate == req.Date select new { o.OrderId, o.OrderDate, c.ContactName, o.ShipAddress }; var offSet = (req.Page - 1) * req.Size; var total = res.Count(); int totalPage = (total % req.Size) == 0 ? (int)(total / req.Size) : ((int)(total / req.Size) + 1); var data = res.OrderBy(x => x.OrderDate).Skip(offSet).Take(req.Size).ToList(); List <object> lst = new List <object>(); for (int i = 0; i < data.Count(); i++) { var item = data[i]; var tam = new { STT = i + 1 + offSet, item.OrderId, item.OrderDate, item.ContactName, item.ShipAddress }; lst.Add(tam); } return(new { Data = lst, TotalRecords = total, Page = req.Page, Size = req.Size, TotalPages = totalPage }); }
public object OrdersInDay(OrderTodayReq req) { return(_rep.OrdersInDay(req)); }