-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change in saving in sales and registration - sales
- Loading branch information
1 parent
8f30416
commit f58b922
Showing
16 changed files
with
350 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.