Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Linq;
using OrangeBricks.Web.Models;
using OrangeBricks.Web.Controllers.Offers.ViewModels;

namespace OrangeBricks.Web.Controllers.Offers.Builders
{
public class MyOffersViewModelBuilder
{
private readonly IOrangeBricksContext _context;

public MyOffersViewModelBuilder(IOrangeBricksContext context)
{
_context = context;
}

public MyOffersViewModel Build(string buyerId)
{
var myOffers = _context.Offers
.Where(p => p.BuyerUserId == buyerId).ToList<Offer>();

return new MyOffersViewModel
{
MyOffers = myOffers.Select(x => new MyOfferViewModel
{
Id = x.Id,
Amount = x.Amount,
CreatedAt = x.CreatedAt,
IsPending = x.Status == OfferStatus.Pending,
Status = x.Status.ToString(),
BuyerUserId = x.BuyerUserId,
StreetName = GetPropertyStreetName(x.PropertyId)
}),
};
}

private string GetPropertyStreetName(int propertyId)
{
var property = _context.Properties
.Where(p => p.Id == propertyId)
.SingleOrDefault();

return property.StreetName;
}
}
}
23 changes: 18 additions & 5 deletions OrangeBricks.Web/Controllers/Offers/OffersController.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using OrangeBricks.Web.Attributes;
using OrangeBricks.Web.Controllers.Offers.Builders;
using OrangeBricks.Web.Controllers.Offers.Commands;
using OrangeBricks.Web.Models;

namespace OrangeBricks.Web.Controllers.Offers
{
[OrangeBricksAuthorize(Roles = "Seller")]
{

public class OffersController : Controller
{
private readonly IOrangeBricksContext _context;

public OffersController(IOrangeBricksContext context)
{
_context = context;
}

}

[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult OnProperty(int id)
{
var builder = new OffersOnPropertyViewModelBuilder(_context);
Expand All @@ -24,7 +26,17 @@ public ActionResult OnProperty(int id)
return View(viewModel);
}

[HttpPost]
[OrangeBricksAuthorize(Roles = "Buyer")]
public ActionResult MyOffers()
{
var builder = new MyOffersViewModelBuilder(_context);
var viewModel = builder.Build(User.Identity.GetUserId());

return View(viewModel);
}

[HttpPost]
[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult Accept(AcceptOfferCommand command)
{
var handler = new AcceptOfferCommandHandler(_context);
Expand All @@ -35,6 +47,7 @@ public ActionResult Accept(AcceptOfferCommand command)
}

[HttpPost]
[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult Reject(RejectOfferCommand command)
{
var handler = new RejectOfferCommandHandler(_context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,17 @@ public class OfferViewModel
public DateTime CreatedAt { get; set; }
public bool IsPending { get; set; }
public string Status { get; set; }
public string BuyerUserId { get; set; }
}

public class MyOffersViewModel
{
public IEnumerable<MyOfferViewModel> MyOffers { get; set; }
}

public class MyOfferViewModel : OfferViewModel
{
public string StreetName { get; set; }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ public class MakeOfferCommand
public int PropertyId { get; set; }

public int Offer { get; set; }

public string BuyerUserId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public void Handle(MakeOfferCommand command)
Amount = command.Offer,
Status = OfferStatus.Pending,
CreatedAt = DateTime.Now,
UpdatedAt = DateTime.Now
UpdatedAt = DateTime.Now,
BuyerUserId = command.BuyerUserId,
PropertyId = property.Id

};

if (property.Offers == null)
Expand Down
192 changes: 98 additions & 94 deletions OrangeBricks.Web/Controllers/Property/PropertyController.cs
Original file line number Diff line number Diff line change
@@ -1,95 +1,99 @@
using System.Collections;
using System.Linq;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using OrangeBricks.Web.Attributes;
using OrangeBricks.Web.Controllers.Property.Builders;
using OrangeBricks.Web.Controllers.Property.Commands;
using OrangeBricks.Web.Controllers.Property.ViewModels;
using OrangeBricks.Web.Models;

namespace OrangeBricks.Web.Controllers.Property
{
public class PropertyController : Controller
{
private readonly IOrangeBricksContext _context;

public PropertyController(IOrangeBricksContext context)
{
_context = context;
}

[Authorize]
public ActionResult Index(PropertiesQuery query)
{
var builder = new PropertiesViewModelBuilder(_context);
var viewModel = builder.Build(query);

return View(viewModel);
}

[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult Create()
{
var viewModel = new CreatePropertyViewModel();

viewModel.PossiblePropertyTypes = new string[] { "House", "Flat", "Bungalow" }
.Select(x => new SelectListItem { Value = x, Text = x })
.AsEnumerable();

return View(viewModel);
}

[OrangeBricksAuthorize(Roles = "Seller")]
[HttpPost]
public ActionResult Create(CreatePropertyCommand command)
{
var handler = new CreatePropertyCommandHandler(_context);

command.SellerUserId = User.Identity.GetUserId();

handler.Handle(command);

return RedirectToAction("MyProperties");
}

[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult MyProperties()
{
var builder = new MyPropertiesViewModelBuilder(_context);
var viewModel = builder.Build(User.Identity.GetUserId());

return View(viewModel);
}

[HttpPost]
[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult ListForSale(ListPropertyCommand command)
{
var handler = new ListPropertyCommandHandler(_context);

handler.Handle(command);

return RedirectToAction("MyProperties");
}

[OrangeBricksAuthorize(Roles = "Buyer")]
public ActionResult MakeOffer(int id)
{
var builder = new MakeOfferViewModelBuilder(_context);
var viewModel = builder.Build(id);
return View(viewModel);
}

[HttpPost]
[OrangeBricksAuthorize(Roles = "Buyer")]
public ActionResult MakeOffer(MakeOfferCommand command)
{
var handler = new MakeOfferCommandHandler(_context);

handler.Handle(command);

return RedirectToAction("Index");
}
}
using System.Collections;
using System.Linq;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using OrangeBricks.Web.Attributes;
using OrangeBricks.Web.Controllers.Property.Builders;
using OrangeBricks.Web.Controllers.Property.Commands;
using OrangeBricks.Web.Controllers.Property.ViewModels;
using OrangeBricks.Web.Models;

namespace OrangeBricks.Web.Controllers.Property
{
public class PropertyController : Controller
{
private readonly IOrangeBricksContext _context;

public PropertyController(IOrangeBricksContext context)
{
_context = context;
}

[Authorize]
public ActionResult Index(PropertiesQuery query)
{
var builder = new PropertiesViewModelBuilder(_context);
var viewModel = builder.Build(query);

return View(viewModel);
}

[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult Create()
{
var viewModel = new CreatePropertyViewModel();

viewModel.PossiblePropertyTypes = new string[] { "House", "Flat", "Bungalow" }
.Select(x => new SelectListItem { Value = x, Text = x })
.AsEnumerable();

return View(viewModel);
}

[OrangeBricksAuthorize(Roles = "Seller")]
[HttpPost]
public ActionResult Create(CreatePropertyCommand command)
{
var handler = new CreatePropertyCommandHandler(_context);

command.SellerUserId = User.Identity.GetUserId();

handler.Handle(command);

return RedirectToAction("MyProperties");
}

[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult MyProperties()
{
var builder = new MyPropertiesViewModelBuilder(_context);
var viewModel = builder.Build(User.Identity.GetUserId());

return View(viewModel);
}

[HttpPost]
[OrangeBricksAuthorize(Roles = "Seller")]
public ActionResult ListForSale(ListPropertyCommand command)
{
var handler = new ListPropertyCommandHandler(_context);

handler.Handle(command);

return RedirectToAction("MyProperties");
}

[OrangeBricksAuthorize(Roles = "Buyer")]
public ActionResult MakeOffer(int id)
{
var builder = new MakeOfferViewModelBuilder(_context);
var viewModel = builder.Build(id);
return View(viewModel);
}

[HttpPost]
[OrangeBricksAuthorize(Roles = "Buyer")]
public ActionResult MakeOffer(MakeOfferCommand command)
{
var handler = new MakeOfferCommandHandler(_context);

command.BuyerUserId = User.Identity.GetUserId();

handler.Handle(command);

return RedirectToAction("Index");
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class MakeOfferViewModel
public string StreetName { get; set; }
public int Offer { get; set; }
public int PropertyId { get; set; }
public string BuyerUserId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using OrangeBricks.Web.Controllers.Viewing.ViewModels;
using OrangeBricks.Web.Models;
using System;

namespace OrangeBricks.Web.Controllers.Viewing.Builders
{
public class BookViewingViewModelBuilder
{
private readonly IOrangeBricksContext _context;

public BookViewingViewModelBuilder(IOrangeBricksContext context)
{
_context = context;
}

public BookViewingViewModel Build(int id)
{
var property = _context.Properties.Find(id);

return new BookViewingViewModel
{
PropertyId = property.Id,
PropertyType = property.PropertyType,
StreetName = property.StreetName,
ViewingDateTime = DateTime.Now
};
}
}
}
Loading