Skip to content

Commit

Permalink
Adding orders query
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-fretz committed Oct 1, 2012
1 parent c58470e commit 1387cdf
Show file tree
Hide file tree
Showing 5 changed files with 894 additions and 21 deletions.
25 changes: 25 additions & 0 deletions bbv/Controllers/SearchController.cs
Expand Up @@ -46,5 +46,30 @@ public object Magic(string q)

return Json(results);
}

public object SearchRevenues(decimal value)
{
var query = Session.Query<Orders_Search.RevenueResult, Orders_Search>()
.Where(x => x.Revenue > value)
.As<Order>();

var results = query
.ToList();

return Json(results);
}

public object CreateOrders()
{
for (int i = 0; i < 100; i++)
{
var order = new Order {
Cost = 1,
Participants = i
};
Session.Store(order);
}
return Json("Done");
}
}
}
56 changes: 35 additions & 21 deletions bbv/Controllers/StudentController.cs
@@ -1,22 +1,36 @@
using bbv.Models;

namespace bbv.Controllers
{
public class StudentController : RavenController
{
public object New(string firstName, string lastName, string email)
{
var student = new Student
{
FirstName = firstName,
LastName = lastName,
Email = email
};

Session.Store(student);

return Json(student.Id);

}
}
using bbv.Models;

namespace bbv.Controllers
{
using Raven.Client;

public class StudentController : RavenController
{
public object AddSome()
{
for (int i = 0; i < 100; i++)
{
this.New(
"First " + i,
"Last " + i,
"foo@bar.com");
}
return Json("Done");
}

public object New(string firstName, string lastName, string email)
{
var student = new Student
{
FirstName = firstName,
LastName = lastName,
Email = email
};

Session.Store(student);

return Json(student.Id);

}
}
}
24 changes: 24 additions & 0 deletions bbv/Infrastructure/Indexes/Orders_Search.cs
@@ -0,0 +1,24 @@
namespace bbv.Infrastructure.Indexes
{
using System.Linq;

using Raven.Client.Indexes;

using bbv.Models;

public class Orders_Search : AbstractIndexCreationTask<Order, Orders_Search.RevenueResult>
{
public class RevenueResult
{
public decimal Revenue { get; set; }
}

public Orders_Search()
{
this.Map = orders => from o in orders
select new {
Revenue = (o.Cost * o.Participants)
};
}
}
}

0 comments on commit 1387cdf

Please sign in to comment.