Skip to content

Instantly share code, notes, and snippets.

@gabrielfuller
Created October 25, 2011 20:23
Show Gist options
  • Save gabrielfuller/1314136 to your computer and use it in GitHub Desktop.
Save gabrielfuller/1314136 to your computer and use it in GitHub Desktop.
Save Option Command Issues
using SharpArch.Web.Mvc.Castle;
namespace EasyOptions.Web.Mvc.CastleWindsor
{
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using SharpArch.Domain.PersistenceSupport;
using SharpArch.NHibernate;
using SharpArch.NHibernate.Contracts.Repositories;
public class ComponentRegistrar
{
public static void AddComponentsTo(IWindsorContainer container)
{
AddGenericRepositoriesTo(container);
AddCustomRepositoriesTo(container);
AddQueryObjectsTo(container);
AddTasksTo(container);
AddCommandsTo(container);
}
private static void AddTasksTo(IWindsorContainer container)
{
container.Register(
AllTypes
.FromAssemblyNamed("EasyOptions.Tasks")
.Pick()
.WithService.FirstNonGenericCoreInterface("EasyOptions.Domain"));
}
private static void AddCustomRepositoriesTo(IWindsorContainer container)
{
container.Register(
AllTypes
.FromAssemblyNamed("EasyOptions.Infrastructure")
.Pick()
.WithService.FirstNonGenericCoreInterface("EasyOptions.Domain"));
//Added this to keep the Repositories in the EasyOptions.Web.Mvc Project
container.Register(
AllTypes
.FromAssemblyNamed("EasyOptions.Web.Mvc")
.Pick()
.WithService.FirstNonGenericCoreInterface("EasyOptions.Domain"));
}
private static void AddGenericRepositoriesTo(IWindsorContainer container)
{
container.Register(
Component.For(typeof(IQuery<>))
.ImplementedBy(typeof(NHibernateQuery<>))
.Named("NHibernateQuery"));
container.Register(
Component.For(typeof(IEntityDuplicateChecker))
.ImplementedBy(typeof(EntityDuplicateChecker))
.Named("entityDuplicateChecker"));
container.Register(
Component.For(typeof(INHibernateRepository<>))
.ImplementedBy(typeof(NHibernateRepository<>))
.Named("nhibernateRepositoryType")
.Forward(typeof(IRepository<>)));
container.Register(
Component.For(typeof(INHibernateRepositoryWithTypedId<,>))
.ImplementedBy(typeof(NHibernateRepositoryWithTypedId<,>))
.Named("nhibernateRepositoryWithTypedId")
.Forward(typeof(IRepositoryWithTypedId<,>)));
container.Register(
Component.For(typeof(ISessionFactoryKeyProvider))
.ImplementedBy(typeof(DefaultSessionFactoryKeyProvider))
.Named("sessionFactoryKeyProvider"));
container.Register(
Component.For(typeof(SharpArch.Domain.Commands.ICommandProcessor))
.ImplementedBy(typeof(SharpArch.Domain.Commands.CommandProcessor))
.Named("commandProcessor"));
}
private static void AddQueryObjectsTo(IWindsorContainer container)
{
container.Register(
AllTypes.FromAssemblyNamed("EasyOptions.Web.Mvc")
.Pick()
.WithService.FirstInterface());
}
private static void AddCommandsTo(IWindsorContainer container)
{
var register = AllTypes.FromAssemblyNamed("EasyOptions.Tasks")
.Pick()
.WithService.FirstInterface();
container.Register(register);
}
}
}
using System;
using SharpArch.Domain.Commands;
using LoanPurpose = FullerHelpers.LoanPurpose;
using LoanType = FullerHelpers.LoanType;
namespace EasyOptions.Tasks.Commands
{
public class SaveOptionStep1Command : CommandBase
{
public SaveOptionStep1Command(
long? optionID,
long userID,
long clientID,
int loanPurposeID,
int loanTypeID,
int defaultTerm,
int secondLientTerm,
int vaMilitaryType,
int originalTerm,
decimal purchasePrice,
decimal downpaymentPercent,
decimal downpaymentAmount,
decimal loanAmount,
decimal vaFundingFeePercent,
decimal vaFundingFeeAmount,
decimal secondLienLoanAmount,
decimal secondLienRate,
decimal secondLienClosingCosts,
decimal secondLienLoanToValue,
decimal fhaAUFMI,
decimal fhaMonthlyMI,
decimal originalRate,
decimal originalPrincipleAndInterest,
decimal originalMortgageInsurance,
decimal estimatedLoanPayoff,
bool vaIsFirstTime,
bool vaVetPaysAtClosing,
DateTime originalCloseDate)
{
this.OptionId = optionID;
this.OptionGuid = Guid.NewGuid();
this.UserID = userID;
this.ClientID = clientID;
this.LoanPurposeID = loanPurposeID;
this.LoanTypeID = loanTypeID;
this.DefaultTerm = defaultTerm;
this.SecondLienTerm = secondLientTerm;
this.VAMilitaryType = vaMilitaryType;
this.PurchasePrice = purchasePrice;
this.DownpaymentPercent = downpaymentPercent;
this.DownpaymentAmount = downpaymentAmount;
this.LoanAmount = loanAmount;
this.VAFundingFeePercent = vaFundingFeePercent;
this.VAFundingFeeAmount = vaFundingFeeAmount;
this.SecondLienLoanAmount = secondLienLoanAmount;
this.SecondLienRate = secondLienRate;
this.SecondLienClosingCosts = secondLienClosingCosts;
this.SecondLienLoanToValue = secondLienLoanToValue;
this.FHAUFMI = fhaAUFMI;
this.FHAMonthlyMortgageInsurance = fhaMonthlyMI;
this.VetFirstTime = vaIsFirstTime;
this.VetPaysAtClosing = vaVetPaysAtClosing;
this.OriginalTerm = originalTerm;
this.OriginalRate = originalRate;
this.OriginalPrincipleAndInterest = originalPrincipleAndInterest;
this.OriginalMortgageInsurance = originalMortgageInsurance;
this.EstimatedLoanPayoff = estimatedLoanPayoff;
this.OriginalCloseDate = originalCloseDate;
this.RevenueRequiredPercentage = 2.5m;
this.StartingRate = 4.25m;
this.OptionHasChanged = true;
this.DateCreated = DateTime.Now;
this.DateLastModified = DateTime.Now;
this.DateDocumentLastUploaded = new DateTime(1753, 1, 1);
}
public long? OptionId { get; set; }
public long UserID { get; set; }
public long ClientID { get; set; }
public Guid OptionGuid { get; set; }
public int LoanPurposeID { get; set; }
public int LoanTypeID { get; set; }
public int DefaultTerm { get; set; }
public int SecondLienTerm { get; set; }
public int VAMilitaryType { get; set; }
public int OriginalTerm { get; set; }
public decimal PurchasePrice { get; set; }
public decimal DownpaymentPercent { get; set; }
public decimal DownpaymentAmount { get; set; }
public decimal LoanAmount { get; set; }
public decimal VAFundingFeePercent { get; set; }
public decimal VAFundingFeeAmount { get; set; }
public decimal SecondLienLoanAmount { get; set; }
public decimal SecondLienRate { get; set; }
public decimal SecondLienClosingCosts { get; set; }
public decimal SecondLienPrincipleAndInterest { get; set; }
public decimal SecondLienLoanToValue { get; set; }
public decimal FHAUFMI { get; set; }
public decimal FHAMonthlyMortgageInsurance { get; set; }
public decimal SellerContributions { get; set; }
public decimal OriginalRate { get; set; }
public decimal OriginalPrincipleAndInterest { get; set; }
public decimal OriginalMortgageInsurance { get; set; }
public decimal EstimatedLoanPayoff { get; set; }
public decimal StartingRate { get; set; }
public decimal RevenueRequiredPercentage { get; set; }
public bool VetFirstTime { get; set; }
public bool VetPaysAtClosing { get; set; }
public bool OptionHasChanged { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateLastModified { get; set; }
public DateTime DateDocumentLastUploaded { get; set; }
public DateTime OriginalCloseDate { get; set; }
}
}
using EasyOptions.Domain;
using SharpArch.Domain.Commands;
using SharpArch.NHibernate;
namespace EasyOptions.Tasks.Commands
{
public class SaveOptionStep1CommandHandler : ICommandHandler<SaveOptionStep1Command>
{
private NHibernateRepositoryWithTypedId<Option, long> _optionRepository;
public SaveOptionStep1CommandHandler(NHibernateRepositoryWithTypedId<Option, long> optionRepository)
{
this._optionRepository = optionRepository;
}
public ICommandResult Handle(SaveOptionStep1Command command)
{
var option = command.OptionId.HasValue ? _optionRepository.Get(command.OptionId.Value) : new Option();
option.OptionGuid = command.OptionGuid;
//option.CreatorUserId = command.UserID;
//option.ClientId = command.ClientID;
//option.LoanPurposeId = command.LoanPurposeID;
//option.LoanTypeId = command.LoanTypeID;
option.DefaultTerm = command.DefaultTerm;
option.SecondLienTerm = command.SecondLienTerm;
option.VAMilitaryType = command.VAMilitaryType;
option.PurchasePrice = command.PurchasePrice;
option.DownpaymentPercent = command.DownpaymentPercent;
option.DownpaymentAmount = command.DownpaymentAmount;
option.LoanAmount = command.LoanAmount;
option.VAFundingFeePercent = command.VAFundingFeePercent;
option.VAFundingFeeAmount = command.VAFundingFeeAmount;
option.SecondLienLoanAmount = command.SecondLienLoanAmount;
option.SecondLienRate = command.SecondLienRate;
option.SecondLienClosingCosts = command.SecondLienClosingCosts;
option.SecondLienLoanToValue = command.SecondLienLoanToValue;
option.FHAUFMI = command.FHAUFMI;
option.FHAMonthlyMortgageInsurance = command.FHAMonthlyMortgageInsurance;
option.VetFirstTime = command.VetFirstTime;
option.VetPaysAtClosing = command.VetPaysAtClosing;
option.OriginalTerm = command.OriginalTerm;
option.OriginalRate = command.OriginalRate;
option.OriginalPrincipleAndInterest = command.OriginalPrincipleAndInterest;
option.OriginalMortgageInsurance = command.OriginalMortgageInsurance;
option.EstimatedLoanPayoff = command.EstimatedLoanPayoff;
option.OriginalCloseDate = command.OriginalCloseDate;
option.RevenueRequiredPercentage = command.RevenueRequiredPercentage;
option.StartingRate = command.StartingRate;
option.OptionHasChanged = option.OptionHasChanged;
option.DateCreated = command.DateCreated;
option.DateLastModified = command.DateLastModified;
option.DateDocumentLastUploaded = command.DateDocumentLastUploaded;
this._optionRepository.SaveOrUpdate(option);
return new SaveOptionStep1CommandResult(true);
}
}
}
using SharpArch.Domain.Commands;
namespace EasyOptions.Tasks.Commands
{
public class SaveOptionStep1CommandResult : CommandResult
{
public SaveOptionStep1CommandResult(bool success)
: base(success)
{
}
public string Message { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment