Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Report()
- {
- return View();
- }
- [HttpPost]
- public ActionResult Report(ReportModel incomingData)
- {
- //Вычисление количества продаж
- int count;
- if (incomingData.StartDate != null && incomingData.EndDate != null)
- {
- count = (from x in db.Orders where (x.Date >= incomingData.StartDate && x.Date <= incomingData.EndDate) select x).Count();
- }
- else count = 0;
- ViewBag.Count = count;
- //вычисление суммы по этим продажам
- decimal? result;
- if (incomingData.StartDate != null && incomingData.EndDate != null)
- {
- result=(from o in db.Orders
- join p in db.Products on o.ProductId equals p.ProductId
- let amount = o.Count * p.Cost
- where (o.Date >= incomingData.StartDate && o.Date <= incomingData.EndDate)
- select amount).DefaultIfEmpty(0).Sum();
- }
- else result = 0;
- ViewBag.Result = result;
- return View();
- }
- @{
- ViewBag.Title = "Report";
- }
- <h2>Report</h2>
- @using (Html.BeginForm())
- {
- <fieldset>
- <div>
- <label>Start Date</label>
- @Html.TextBox("StartDate")
- </div>
- <div>
- <label>End Date</label>
- @Html.TextBox("EndDate")
- </div>
- <input type="submit" value="Check" />
- </fieldset>
- }
- <div>Всего продаж @ViewBag.Count</div>
- <div>Общая стоимость @ViewBag.Result</div>
- @using (Html.BeginForm())
- {
- <div>
- <label>Введите имя пользователя </label>
- @Html.TextBox("y")
- </div>
- <input type="submit" value="Запросить статистику" />
- [HttpPost]
- public ActionResult Report(ReportModel incomingData,string y)
- {
- //Вычисление количества продаж
- int count;
- if (incomingData.StartDate != null && incomingData.EndDate != null)
- {
- count = (from x in db.Orders where (x.Date >= incomingData.StartDate && x.Date <= incomingData.EndDate) select x).Count();
- }
- else count = 0;
- ViewBag.Count = count;
- //вычисление суммы по этим продажам
- decimal? result;
- if (incomingData.StartDate != null && incomingData.EndDate != null)
- {
- result=(from o in db.Orders
- join p in db.Products on o.ProductId equals p.ProductId
- let amount = o.Count * p.Cost
- where (o.Date >= incomingData.StartDate && o.Date <= incomingData.EndDate)
- select amount).DefaultIfEmpty(0).Sum();
- }
- else result = 0;
- ViewBag.Result = result;
- //Вывод статистики по конкретному пользователю
- var query = from c in db.Customers
- join o in db.Orders on c.CustomerId equals o.CustomerId
- join p in db.Products on o.ProductId equals p.ProductId
- where c.Name==y
- select new
- {
- c.CustomerId,
- c.Name,
- c.Surname,
- Product=p.Name,
- p.Cost,
- c=o.Count,
- d=o.Date
- };
- ViewBag.Query = query;
- return View();
- }
- @{
- ViewBag.Title = "Report";
- }
- <h2>Report</h2>
- @using (Html.BeginForm())
- {
- <fieldset>
- <div>
- <label>Start Date</label>
- @Html.TextBox("StartDate")
- </div>
- <div>
- <label>End Date</label>
- @Html.TextBox("EndDate")
- </div>
- <input type="submit" value="Check" />
- </fieldset>
- }
- <div>Всего продаж @ViewBag.Count</div>
- <div>Общая стоимость @ViewBag.Result</div>
- @using (Html.BeginForm())
- {
- <div>
- <label>Введите имя пользователя </label>
- @Html.TextBox("y")
- </div>
- <input type="submit" value="Запросить статистику" />
- }
- <table class="table">
- <tr>
- <th>
- @Html.DisplayName("CustomerId")
- </th>
- <th>
- @Html.DisplayName("Name")
- </th>
- <th>
- @Html.DisplayName("Surname")
- </th>
- <th>
- @Html.DisplayName("Product")
- </th>
- <th>
- @Html.DisplayName("Cost")
- </th>
- <th>
- @Html.DisplayName("Count")
- </th>
- <th>
- @Html.DisplayName("Date")
- </th>
- </tr>
- @foreach (var item in ViewBag.Query)
- {
- <tr>
- <td>
- @item
- </td>
- </tr>
- }
- </table>
- using System;
- using System.ComponentModel.DataAnnotations;
- namespace MVC_Fund6_2.Models
- {
- public class X
- {
- [Key]
- public int CustomerId { get; set; }
- public string Name { get; set; }
- public string Surname { get; set; }
- public string Product { get; set; }
- public decimal Cost { get; set; }
- public int Count { get; set; }
- public DateTime Date { get; set; }
- }
- }
- using System.Linq;
- using System.Web.Mvc;
- using MVC_Fund6_2.Models;
- namespace MVC_Fund6_2.Controllers
- {
- public class testController : Controller
- {
- private DatabaseContext db = new DatabaseContext();
- // GET: test
- public ActionResult Statistic()
- {
- var query = from c in db.Customers
- join o in db.Orders on c.CustomerId equals o.CustomerId
- join p in db.Products on o.ProductId equals p.ProductId //
- select new
- {
- c.CustomerId,
- c.Name,
- c.Surname,
- Product = p.Name,
- p.Cost,
- o.Count,
- o.Date
- };
- return View(query.ToList());
- }
- }
- }
- @{
- ViewBag.Title = "Statistic";
- }
- <h2>Statistic</h2>
- <table class="table">
- @foreach (var item in Model) {
- <tr>
- <td>
- @item
- </td>
- </tr>
- }
Add Comment
Please, Sign In to add comment