Skip to content

Commit

Permalink
change in saving in sales and registration - sales
Browse files Browse the repository at this point in the history
  • Loading branch information
lyndonkieljerymiah committed Dec 24, 2016
1 parent 8f30416 commit f58b922
Showing 16 changed files with 350 additions and 118 deletions.
79 changes: 79 additions & 0 deletions Sunrise.Client/Controllers/Api/SalesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Results;
using Sunrise.Client.Domains.Models;
using Sunrise.Client.Domains.ViewModels;
using Sunrise.Client.Persistence.Repositories;

namespace Sunrise.Client.Controllers.Api
{
[RoutePrefix("api/sales")]
public class SalesController : ApiController
{
private readonly UnitOfWork _unitOfWork;

public SalesController(UnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}

[HttpGet]
[Route("create/{villaId?}")]
public async Task<IHttpActionResult> Create(int villaId)
{
var villa = await _unitOfWork.Villas.FindAsync(villaId);
var selections = await _unitOfWork.Selections.GetSelections(new string[] { "TenantType", "RentalType", "ContractStatus" });

var vmVilla = VillaViewModel.Create(villa);
var vmTransaction = new TransactionViewModel(selections, vmVilla);

return Ok(vmTransaction);
}


[HttpPost]
[Route("update")]
public async Task<IHttpActionResult> Update(TransactionViewModel vm)
{
if (ModelState.IsValid)
return BadRequest();

var vmTenant = vm.Tenant;
var vmSales = vm.Sales;

//register tenant
var tenant = Tenant.Create(
vmTenant.Type,vmTenant.Code,vmTenant.Name,
vmTenant.EmailAddress,vmTenant.TelNo,vmTenant.
MobileNo,vmTenant.FaxNo,vmTenant.Address1,vmTenant.Address2,
vmTenant.City,vmTenant.PostalCode);

if (vmTenant.Type == "ttin")
{
tenant.AddIndividual(vmTenant.Individual.Birthday, vmTenant.Individual.Gender,
vmTenant.Individual.QatarId, vmTenant.Individual.Company);
}
else
{
tenant.AddCompany(vmTenant.Company.CrNo,vmTenant.Company.BusinessType,vmTenant.Company.ValidityDate,vmTenant.Company.Representative);
}


//add sales
tenant.AddSalesTransaction(vm.Sales.Villa.Id,vmSales.RentalType,
vmSales.ContractStatus,
vmSales.PeriodStart,
vmSales.PeriodEnd,vmSales.Amount);

_unitOfWork.Tenants.Add(tenant);
await _unitOfWork.SaveChangesAsync();


return Ok();
}
}
}
11 changes: 3 additions & 8 deletions Sunrise.Client/Controllers/SalesController.cs
Original file line number Diff line number Diff line change
@@ -32,15 +32,10 @@ public async Task<ActionResult> Index()
}

[Route("checkout/{villaId?}")]
public async Task<ViewResult> Checkout(int villaId)
public ViewResult Checkout(int villaId)
{
var villa = await _unitOfWork.Villas.FindAsync(villaId);
var selections = await _unitOfWork.Selections.GetSelections(new string[] {"TenantType", "RentalType", "ContractStatus"});

var vmVilla = VillaViewModel.Create(villa);
var salesVm = SalesViewModel.Create(vmVilla, selections);

return View(salesVm);
ViewBag.Id = villaId;
return View();
}


10 changes: 4 additions & 6 deletions Sunrise.Client/Controllers/TenantController.cs
Original file line number Diff line number Diff line change
@@ -27,13 +27,11 @@ public ActionResult Index()
return View();
}

[Route("Template/Register/{tv?}")]
public async Task<PartialViewResult> Register(string tv = "ttin")
[Route("Register/{tv?}")]
public PartialViewResult Register(string tv = "ttin")
{
var selections = await _uw.Selections.GetSelections(new string[] { "TenantType" });
var vmTenant = new TenantRegisterViewModel(selections);
vmTenant.Type = tv;
return PartialView("_Register",vmTenant);
ViewBag.Type = tv;
return PartialView("_Register");
}


14 changes: 13 additions & 1 deletion Sunrise.Client/Domains/Models/SalesTransaction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations.Model;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -9,19 +10,30 @@ namespace Sunrise.Client.Domains.Models
public class SalesTransaction
{

public SalesTransaction(string rentalType,string contractStatus,

public static SalesTransaction CreateTransaction(int villaId, string rentalType, string contractStatus,
DateTime periodStart, DateTime periodEnd, decimal amount)
{
return new SalesTransaction(villaId,rentalType,contractStatus,periodStart,periodEnd,amount);
}



public SalesTransaction(int villaId,string rentalType,string contractStatus,
DateTime periodStart,DateTime periodEnd,decimal amount) : this()
{

this.RentalType = rentalType;
this.ContractStatus = contractStatus;
this.PeriodStart = periodStart;
this.PeriodEnd = periodEnd;
this.VillaId = villaId;
}

public SalesTransaction()
{
this.DateCreated = DateTime.Today;
this.Status = "Waiting";
}

public int Id { get; set; }
23 changes: 11 additions & 12 deletions Sunrise.Client/Domains/Models/Tenant.cs
Original file line number Diff line number Diff line change
@@ -3,12 +3,14 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ninject.Infrastructure.Language;
using Sunrise.Client.Domains.Enum;

namespace Sunrise.Client.Domains.Models
{
public class Tenant
{

public static Tenant Create(string type, string code, string name, string emailAddress, string telNo,
string mobileNo,
string faxNo,string address1,string address2, string city,string postalCode)
@@ -34,14 +36,13 @@ public Tenant(string type, string code, string name, string emailAddress, string

public Tenant()
{
this.SalesTransaction = new HashSet<SalesTransaction>();
this.SalesTransactions = new HashSet<SalesTransaction>();
this.DateRegistered = DateTime.Today;
this.Individual = null;
this.Company = null;
}

public int Id { get; private set; }

public string Name { get; set; }
public string Code { get; set; }
public string TenantType { get; set; }
@@ -52,25 +53,23 @@ public Tenant()
public string FaxNo { get; set; }
public bool IsActive { get; set; }

public Individual Individual { get; private set; }
public Company Company { get; private set; }
public Address Address { get; private set; }

public ICollection<SalesTransaction> SalesTransaction { get; private set; }
public virtual Individual Individual { get; private set; }
public virtual Company Company { get; private set; }
public virtual Address Address { get; private set; }


public void AddSalesTransaction(string rentalType, string contractStatus,
public virtual ICollection<SalesTransaction> SalesTransactions { get; private set; }
public void AddSalesTransaction(int villaId,string rentalType, string contractStatus,
DateTime periodStart, DateTime periodEnd, decimal amount)
{

SalesTransaction.Add(new SalesTransaction(rentalType,contractStatus,periodStart,periodEnd,amount));
var sales = SalesTransaction.CreateTransaction(villaId, rentalType, contractStatus, periodStart, periodEnd, amount);
SalesTransactions.Add(sales);
}

public void AddIndividual(DateTime bday,GenderEnum gender,string qatarId,string company)
{

this.Individual = new Individual(bday,gender,qatarId,company);
}

public void AddCompany(string crNo,string businessType, DateTime validityDate,string representative)
{

14 changes: 8 additions & 6 deletions Sunrise.Client/Domains/ViewModels/SalesViewModel.cs
Original file line number Diff line number Diff line change
@@ -12,20 +12,19 @@ public class SalesViewModel
private readonly IEnumerable<Selection> _selections;



public static SalesViewModel Create(VillaViewModel vm,
IEnumerable<Selection> selections)
{
var sales = new SalesViewModel(selections);
sales.Tenant = new TenantRegisterViewModel(selections);
sales.Villa = vm;
return sales;
}



public SalesViewModel(IEnumerable<Selection> selections)
{
_selections = selections;

this.RentalType = _selections.Where(t => t.Type == "RentalType").FirstOrDefault()?.Code;
this.ContractStatus = _selections.Where(t => t.Type == "ContractStatus").FirstOrDefault()?.Code;
}
@@ -55,13 +54,13 @@ public SalesViewModel()

public VillaViewModel Villa { get; set; }

public TenantRegisterViewModel Tenant { get; set; }


public IEnumerable<SelectListItem> RentalTypes
{
get
{
if (_selections == null)
return new List<SelectListItem>();

var types = _selections
.Where(s => s.Type == "RentalType")
.Select(s => new SelectListItem() { Text = s.Description, Value = s.Code });
@@ -73,6 +72,9 @@ public IEnumerable<SelectListItem> ContractStatuses
{
get
{
if (_selections == null)
return new List<SelectListItem>();

var statuses = _selections
.Where(s => s.Type == "ContractStatus")
.Select(s => new SelectListItem() { Text = s.Description, Value = s.Code });
18 changes: 11 additions & 7 deletions Sunrise.Client/Domains/ViewModels/TenantRegisterViewModel.cs
Original file line number Diff line number Diff line change
@@ -36,6 +36,9 @@ public string FullType
{
get
{
if(_selections == null)
return String.Empty;

var fullType = _selections.SingleOrDefault(t => t.Code == Type);
return fullType.Description;
}
@@ -46,11 +49,14 @@ public IEnumerable<SelectListItem> TenantTypes
get
{
var tenantTypes = new List<SelectListItem>();

foreach (var selection in _selections)
if (_selections != null)
{
tenantTypes.Add(new SelectListItem() { Text = selection.Description, Value = selection.Code});
foreach (var selection in _selections)
{
tenantTypes.Add(new SelectListItem() {Text = selection.Description, Value = selection.Code});
}
}

return tenantTypes;
}
}
@@ -82,12 +88,10 @@ public IEnumerable<SelectListItem> TenantTypes
[Required]
public string City { get; set; }


public IndividualViewModel Individual { get; set; }

public CompanyViewModel Company { get; set; }



}

public class IndividualViewModel
@@ -117,7 +121,7 @@ public string FullGender
public IEnumerable<SelectListItem> Genders
{
get
{
{
return new List<SelectListItem>
{
new SelectListItem() { Text = "Male", Value= GenderEnum.Male.ToString() ,Selected = true},
37 changes: 37 additions & 0 deletions Sunrise.Client/Domains/ViewModels/TransactionViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sunrise.Client.Domains.Models;

namespace Sunrise.Client.Domains.ViewModels
{
public class TransactionViewModel
{

public TransactionViewModel(IEnumerable<Selection> selections,VillaViewModel villa)
{

//get for tenant
var tenantSelections = selections.Where(s => s.Type == "TenantType");
this.Tenant = new TenantRegisterViewModel(tenantSelections);

//get for sales
var salesSelections = selections.Where(s => s.Type.Contains("RentalType") || s.Type.Contains("ContractStatus"));
this.Sales = SalesViewModel.Create(villa,salesSelections);
}

public TransactionViewModel()
{

}


public TenantRegisterViewModel Tenant { get; set; }
public SalesViewModel Sales { get; set; }
public string Template { get; set; }


}
}
28 changes: 28 additions & 0 deletions Sunrise.Client/Helpers/Extension/AngularBootstrap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace Sunrise.Client.Helpers.Extension
{
public static class AngularBootstrap
{
public static MvcHtmlString NgInput(this HtmlHelper helper, string name, string value, string[] cssAttribute)
{
StringBuilder builder = new StringBuilder();

builder.Append("<div class='form-group'>");
builder.Append("<div class='" + cssAttribute[0] + "'>");

builder.Append("</div>");
builder.Append("<div class='form-group'>");

return MvcHtmlString.Create(builder.ToString());
}


}
}
Loading

0 comments on commit f58b922

Please sign in to comment.