public Int32 PostMstCheckListRequirement(MstCheckListRequirement checklistRequirement) { try { Data.MstCheckListRequirement newMstCheckListRequirement = new Data.MstCheckListRequirement() { CheckListId = checklistRequirement.ChecklistId, RequirementNo = checklistRequirement.RequirementNo, Requirement = checklistRequirement.Requirement, Category = checklistRequirement.Category, Type = checklistRequirement.Type, WithAttachments = checklistRequirement.WithAttachments }; db.MstCheckListRequirements.InsertOnSubmit(newMstCheckListRequirement); db.SubmitChanges(); return(newMstCheckListRequirement.Id); } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public HttpResponseMessage AddSoldUnitOwner(TrnSoldUnitCoOwner objSoldUnitOwner) { try { HttpStatusCode responseStatusCode = HttpStatusCode.OK; String responseMessage = ""; var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (!currentUser.Any()) { responseStatusCode = HttpStatusCode.NotFound; responseMessage = "No current user logged in."; } else { Data.TrnSoldUnitCoOwner newSoldUnitCoOwner = new Data.TrnSoldUnitCoOwner { SoldUnitId = objSoldUnitOwner.SoldUnitId, CustomerId = objSoldUnitOwner.CustomerId }; db.TrnSoldUnitCoOwners.InsertOnSubmit(newSoldUnitCoOwner); db.SubmitChanges(); } return(Request.CreateResponse(responseStatusCode, responseMessage)); } catch (Exception ex) { Debug.WriteLine(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public Int32 PostTrnSoldUnitRequirementActivity(TrnSoldUnitRequirementActivity soldUnitRequirementActivity) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { Data.TrnSoldUnitRequirementActivity newTrnSoldUnitRequirementActivity = new Data.TrnSoldUnitRequirementActivity() { SoldUnitRequirementId = soldUnitRequirementActivity.SoldUnitRequirementId, ActivityDate = DateTime.Now, Activity = soldUnitRequirementActivity.Activity, Remarks = soldUnitRequirementActivity.Remarks, UserId = currentUser.FirstOrDefault().Id }; db.TrnSoldUnitRequirementActivities.InsertOnSubmit(newTrnSoldUnitRequirementActivity); db.SubmitChanges(); return(newTrnSoldUnitRequirementActivity.Id); } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public Int32 PostMstUserRight(MstUserRight userRight) { try { Data.MstUserRight newMstUserRight = new Data.MstUserRight() { UserId = userRight.UserId, PageId = userRight.PageId, CanEdit = userRight.CanEdit, CanSave = userRight.CanSave, CanLock = userRight.CanLock, CanUnlock = userRight.CanLock, CanPrint = userRight.CanPrint, CanDelete = userRight.CanDelete }; db.MstUserRights.InsertOnSubmit(newMstUserRight); db.SubmitChanges(); return(newMstUserRight.Id); } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public Int32 PostCollectionPayment(TrnCollectionPayment collectionPayment) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var collection = from d in db.TrnCollections where d.Id == collectionPayment.CollectionId select d; if (collection.Any()) { Data.TrnCollectionPayment newCollectionPayment = new Data.TrnCollectionPayment() { CollectionId = collectionPayment.CollectionId, SoldUnitId = collectionPayment.SoldUnitId, SoldUnitEquityScheduleId = collectionPayment.SoldUnitEquityScheduleId, PayType = collectionPayment.PayType, Amount = collectionPayment.Amount, CheckNumber = collectionPayment.CheckNumber, CheckDate = Convert.ToDateTime(collectionPayment.CheckDate), CheckBank = collectionPayment.CheckBank, OtherInformation = collectionPayment.OtherInformation }; db.TrnCollectionPayments.InsertOnSubmit(newCollectionPayment); db.SubmitChanges(); return(1); } else { return(0); } } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public Int32 PostMstCheckList(MstCheckList checklist) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { string checklistCode = "0001"; var checklists = from d in db.MstCheckLists.OrderByDescending(d => d.Id) select d; if (checklists.Any()) { Int32 nextChecklistCode = Convert.ToInt32(checklists.FirstOrDefault().CheckListCode) + 1; checklistCode = padNumWithZero(nextChecklistCode, 4); } Data.MstCheckList newMstChecList = new Data.MstCheckList() { CheckListCode = checklistCode, CheckList = checklist.Checklist, CheckListDate = Convert.ToDateTime(checklist.ChecklistDate), ProjectId = checklist.ProjectId, Remarks = checklist.Remarks, Status = checklist.Status, IsLocked = checklist.IsLocked, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now, }; db.MstCheckLists.InsertOnSubmit(newMstChecList); db.SubmitChanges(); return(newMstChecList.Id); } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public Int32 PostMstProject(MstProject project) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { string projectCode = "0001"; var projects = from d in db.MstProjects.OrderByDescending(d => d.Id) select d; if (projects.Any()) { Int32 nextProjectCode = Convert.ToInt32(projects.FirstOrDefault().ProjectCode) + 1; projectCode = padNumWithZero(nextProjectCode, 4); } Data.MstProject newMstProject = new Data.MstProject() { ProjectCode = projectCode, Project = project.Project, Address = project.Address, Status = project.Status, ProjectLogo = project.ProjectLogo, IsLocked = project.IsLocked, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.MstProjects.InsertOnSubmit(newMstProject); db.SubmitChanges(); return(newMstProject.Id); } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public Int32 PostMstUnit(MstUnit unit) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var defaultHouseModel = from d in db.MstHouseModels where d.ProjectId == unit.ProjectId select d; if (defaultHouseModel.Any()) { Data.MstUnit newMstUnit = new Data.MstUnit() { UnitCode = unit.UnitCode, Block = unit.Block, Lot = unit.Lot, ProjectId = unit.ProjectId, HouseModelId = defaultHouseModel.FirstOrDefault().Id, TLA = unit.TLA, TFA = unit.TFA, Price = unit.Price, MiscellaneousFeeRate = unit.MiscellaneousFeeRate, MiscellaneousFeeAmount = unit.MiscellaneousFeeAmount, VATRate = unit.VATRate, VATAmount = unit.VATAmount, TSP = unit.TSP, Status = unit.Status, IsLocked = unit.IsLocked, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.MstUnits.InsertOnSubmit(newMstUnit); db.SubmitChanges(); return(newMstUnit.Id); } else { return(0); } } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public Int32 PostSysPage(SysPage addSysPage) { try { Data.SysPage newSysPage = new Data.SysPage() { Page = addSysPage.Page, Url = addSysPage.Page }; db.SysPages.InsertOnSubmit(newSysPage); db.SubmitChanges(); return(newSysPage.Id); } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public Int32 PostSysDropDown(SysDropDown dropDown) { try { Data.SysDropDown newSysDropDown = new Data.SysDropDown() { Category = dropDown.Category, Description = dropDown.Description, Value = dropDown.Value }; db.SysDropDowns.InsertOnSubmit(newSysDropDown); db.SubmitChanges(); return(newSysDropDown.Id); } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public int PostMstHouseModel(MstHouseModel housemodel) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { Data.MstHouseModel newMstHouseModel = new Data.MstHouseModel() { HouseModelCode = housemodel.HouseModelCode, HouseModel = housemodel.HouseModel, ProjectId = housemodel.ProjectId, TFA = housemodel.TFA, Price = housemodel.Price, IsLocked = true, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.MstHouseModels.InsertOnSubmit(newMstHouseModel); db.SubmitChanges(); return(newMstHouseModel.Id); } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public Int32 PostMstUser(MstUser user) { try { Data.MstUser newMstUser = new Data.MstUser() { Username = user.Username, FullName = user.FullName, Password = user.Password, Status = user.Status, AspNetId = user.AspNetId }; db.MstUsers.InsertOnSubmit(newMstUser); db.SubmitChanges(); return(newMstUser.Id); } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public async Task <IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityUser user = new IdentityUser { UserName = model.UserName }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); IHttpActionResult errorResult = GetErrorResult(result); if (errorResult != null) { return(errorResult); } // =============== // DB Data Context // =============== Data.FilbrokerDBDataContext db = new Data.FilbrokerDBDataContext(); // ============================== // Get the registered ASP User Id // ============================== string registeredAspUserId = user.Id; // =============== // Insert New User // =============== Data.MstUser newUser = new Data.MstUser() { Username = model.UserName, FullName = model.FullName, Password = model.Password, Status = "ACTIVE", AspNetId = registeredAspUserId }; db.MstUsers.InsertOnSubmit(newUser); db.SubmitChanges(); return(Ok()); }
public HttpResponseMessage SaveSysSettings(SysSettings settings) { try { var SysSettingsData = from d in db.SysSettings where d.Id == Convert.ToInt32(settings.Id) select d; if (SysSettingsData.Any()) { var UpdateSysSettingsData = SysSettingsData.FirstOrDefault(); UpdateSysSettingsData.Company = settings.Company; UpdateSysSettingsData.SoftwareVersion = settings.SoftwareVersion; UpdateSysSettingsData.SoftwareDeveloper = settings.SoftwareDeveloper; UpdateSysSettingsData.SoldUnitCheckedBy = settings.SoldUnitCheckedBy; UpdateSysSettingsData.SoldUnitApprovedBy = settings.SoldUnitApprovedBy; UpdateSysSettingsData.CommissionRequestCheckedBy = settings.CommissionRequestCheckedBy; UpdateSysSettingsData.CommissionRequestApprovedBy = settings.CommissionRequestApprovedBy; UpdateSysSettingsData.ProposalFootNote = settings.ProposalFootNote; UpdateSysSettingsData.BrokerFootNote = settings.BrokerFootNote; UpdateSysSettingsData.TotalInvestment = settings.TotalInvestment; UpdateSysSettingsData.PaymentOptions = settings.PaymentOptions; UpdateSysSettingsData.Financing = settings.Financing; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public Int32 PostMstCustomer(MstCustomer customer) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { string customerCode = "0001"; var customers = from d in db.MstCustomers.OrderByDescending(d => d.Id) select d; if (customers.Any()) { Int32 nextCustomerCode = Convert.ToInt32(customers.FirstOrDefault().CustomerCode) + 1; customerCode = padNumWithZero(nextCustomerCode, 4); } Data.MstCustomer newMstCustomer = new Data.MstCustomer() { CustomerCode = customerCode, LastName = customer.LastName, FirstName = customer.FirstName, MiddleName = customer.MiddleName, CivilStatus = customer.CivilStatus, Gender = customer.Gender, BirthDate = Convert.ToDateTime(customer.BirthDate), Citizen = customer.Citizen, TIN = customer.TIN, IdType = customer.IdType, IdNumber = customer.IdNumber, Address = customer.Address, City = customer.City, Province = customer.Province, Country = customer.Country, ZipCode = customer.ZipCode, EmailAddress = customer.EmailAddress, TelephoneNumber = customer.TelephoneNumber, MobileNumber = customer.MobileNumber, Employer = customer.Employer, EmployerIndustry = customer.EmployerIndustry, NoOfYearsEmployed = customer.NoOfYearsEmployed, Position = customer.Position, EmploymentStatus = customer.EmploymentStatus, EmployerAddress = customer.EmployerAddress, EmployerCity = customer.EmployerCity, EmployerProvince = customer.EmployerProvince, EmployerCountry = customer.EmployerCountry, EmployerZipCode = customer.EmployerZipCode, EmployerTelephoneNumber = customer.EmployerTelephoneNumber, EmployerMobileNumber = customer.EmployerMobileNumber, SpouseLastName = customer.SpouseLastName, SpouseFirstName = customer.SpouseFirstName, SpouseMiddleName = customer.SpouseMiddleName, SpouseBirthDate = Convert.ToDateTime(customer.SpouseBirthDate), SpouseCitizen = customer.SpouseCitizen, SpouseEmployer = customer.SpouseEmployer, SpouseTIN = customer.SpouseTIN, Remarks = customer.Remarks, Status = customer.Status, Picture = customer.Picture, Attachment1 = customer.Attachment1, Attachment2 = customer.Attachment2, Attachment3 = customer.Attachment3, Attachment4 = customer.Attachment4, Attachment5 = customer.Attachment5, IsLocked = customer.IsLocked, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now, BusinessName = customer.BusinessName, BusinessAddress = customer.BusinessAddress, BusinessType = customer.BusinessType, BusinessPosition = customer.BusinessPosition }; db.MstCustomers.InsertOnSubmit(newMstCustomer); db.SubmitChanges(); return(newMstCustomer.Id); } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public void UpdateAccountsReceivable(Int32 soldUnitId) { Decimal pricePayment = 0; var collectionPayments = from d in db.TrnCollectionPayments where d.SoldUnitId == soldUnitId && d.TrnCollection.IsLocked == true select d; if (collectionPayments.Any()) { pricePayment = collectionPayments.Sum(d => d.Amount); foreach (var collectionPayment in collectionPayments) { var equitySchedule = from d in db.TrnSoldUnitEquitySchedules where d.Id == collectionPayment.SoldUnitEquityScheduleId select d; if (equitySchedule.Any()) { var updateEquitySchedule = equitySchedule.FirstOrDefault(); updateEquitySchedule.CheckNumber = collectionPayment.CheckNumber; updateEquitySchedule.CheckDate = collectionPayment.CheckDate; updateEquitySchedule.CheckBank = collectionPayment.CheckBank; updateEquitySchedule.PaidAmount = collectionPayment.Amount; updateEquitySchedule.BalanceAmount = equitySchedule.FirstOrDefault().Amortization - collectionPayment.Amount; db.SubmitChanges(); } } } else { var unlockedCollectionPayments = from d in db.TrnCollectionPayments where d.SoldUnitId == soldUnitId && d.TrnCollection.IsLocked == false select d; if (unlockedCollectionPayments.Any()) { foreach (var unlockedCollectionPayment in unlockedCollectionPayments) { var equitySchedule = from d in db.TrnSoldUnitEquitySchedules where d.Id == unlockedCollectionPayment.SoldUnitEquityScheduleId select d; if (equitySchedule.Any()) { var updateEquitySchedule = equitySchedule.FirstOrDefault(); updateEquitySchedule.CheckNumber = ""; updateEquitySchedule.CheckDate = null; updateEquitySchedule.CheckBank = ""; updateEquitySchedule.PaidAmount = 0; updateEquitySchedule.BalanceAmount = equitySchedule.FirstOrDefault().Amortization; db.SubmitChanges(); } } } } var soldUnit = from d in db.TrnSoldUnits where d.Id == soldUnitId select d; if (soldUnit.Any()) { Decimal price = soldUnit.FirstOrDefault().Price; Decimal priceDiscount = soldUnit.FirstOrDefault().PriceDiscount; Decimal priceBalance = price - priceDiscount - pricePayment; var updateSoldUnit = soldUnit.FirstOrDefault(); updateSoldUnit.PricePayment = pricePayment; updateSoldUnit.PriceBalance = priceBalance; db.SubmitChanges(); } }
public Int32 PostMstBroker(MstBroker broker) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { string brokerCode = "0001"; var brokers = from d in db.MstBrokers.OrderByDescending(d => d.Id) select d; if (brokers.Any()) { Int32 nextBrokerCode = Convert.ToInt32(brokers.FirstOrDefault().BrokerCode) + 1; brokerCode = padNumWithZero(nextBrokerCode, 4); } Data.MstBroker newMstBroker = new Data.MstBroker() { BrokerCode = brokerCode, LastName = broker.LastName, FirstName = broker.FirstName, MiddleName = broker.MiddleName, LicenseNumber = broker.LicenseNumber, LicenseNumberValidUntil = broker.LicenseNumberValidUntil, BirthDate = Convert.ToDateTime(broker.BirthDate), CivilStatus = broker.CivilStatus, Gender = broker.Gender, Address = broker.Address, TelephoneNumber = broker.TelephoneNumber, MobileNumber = broker.MobileNumber, Religion = broker.Religion, EmailAddress = broker.EmailAddress, Facebook = broker.Facebook, TIN = broker.TIN, HLURBRegistrationNumber = broker.HLURBRegistrationNumber, RealtyFirm = broker.RealtyFirm, RealtyFirmAddress = broker.RealtyFirmAddress, RealtyFirmTelephoneNumber = broker.RealtyFirmTelephoneNumber, RealtyFirmMobileNumber = broker.RealtyFirmMobileNumber, RealtyFirmFaxNumber = broker.RealtyFirmFaxNumber, RealtyFirmEmailAddress = broker.RealtyFirmEmailAddress, RealtyFirmWebsite = broker.RealtyFirmWebsite, RealtyFirmTIN = broker.RealtyFirmTIN, RealtyFirmLicenseNumber = broker.RealtyFirmLicenseNumber, RealtyFirmLicenseNumberValidUntil = broker.RealtyFirmLicenseNumberValidUntil, RealtyFormHLURBRegistrationNumber = broker.RealtyFormHLURBRegistrationNumber, Organization = broker.Organization, Remarks = broker.Remarks, Picture = broker.Picture, Attachment1 = broker.Attachment1, Attachment2 = broker.Attachment2, Attachment3 = broker.Attachment3, Attachment4 = broker.Attachment4, Attachment5 = broker.Attachment5, Status = broker.Status, IsLocked = broker.IsLocked, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now, Type = broker.Type, AssociatedBroker = broker.AssociatedBroker, AssociatedFirm = broker.AssociatedFirm }; db.MstBrokers.InsertOnSubmit(newMstBroker); db.SubmitChanges(); return(newMstBroker.Id); } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public List <TrnSoldUnitRequirement> GetNewTrnSoldUnitRequirements(string soldUnitId, string checklistId) { // Remove existing requirements var deleteRequirements = from d in db.TrnSoldUnitRequirements where d.SoldUnitId == Convert.ToInt32(soldUnitId) select d; if (deleteRequirements.Any()) { foreach (var deleteRequirement in deleteRequirements) { db.TrnSoldUnitRequirements.DeleteOnSubmit(deleteRequirement); } db.SubmitChanges(); } // Insert new requirements var checklistRequirements = from d in db.MstCheckListRequirements where d.CheckListId == Convert.ToInt32(checklistId) select d; if (checklistRequirements.Any()) { foreach (var checklistRequirement in checklistRequirements) { Data.TrnSoldUnitRequirement insertRequirement = new Data.TrnSoldUnitRequirement() { SoldUnitId = Convert.ToInt32(soldUnitId), CheckListRequirementId = checklistRequirement.Id, Remarks = "", Status = "NOT OK", StatusDate = DateTime.Now }; db.TrnSoldUnitRequirements.InsertOnSubmit(insertRequirement); } db.SubmitChanges(); } // Return new requirements var newRequirements = from d in db.TrnSoldUnitRequirements where d.SoldUnitId == Convert.ToInt32(soldUnitId) select new TrnSoldUnitRequirement { Id = d.Id, SoldUnitId = d.SoldUnitId, ChecklistRequirementId = d.CheckListRequirementId, ChecklistRequirement = d.MstCheckListRequirement.Requirement, ChecklistRequirementNo = d.MstCheckListRequirement.RequirementNo, ChecklistCategory = d.MstCheckListRequirement.Category, ChecklistType = d.MstCheckListRequirement.Type, ChecklistWithAttachments = d.MstCheckListRequirement.WithAttachments, Attachment1 = d.Attachment1, Attachment2 = d.Attachment2, Attachment3 = d.Attachment3, Attachment4 = d.Attachment4, Attachment5 = d.Attachment5, Remarks = d.Remarks, Status = d.Status, StatusDate = d.StatusDate.ToShortDateString() }; return(newRequirements.ToList()); }
public Int32 PostTrnCommissionRequest(TrnCommissionRequest commissionRequest) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { string commissionRequestNumber = "0000000001"; var commissionRequests = from d in db.TrnCommissionRequests.OrderByDescending(d => d.Id) select d; if (commissionRequests.Any()) { Int32 nextCommissionRequestNumber = Convert.ToInt32(commissionRequests.FirstOrDefault().CommissionRequestNumber) + 1; commissionRequestNumber = padNumWithZero(nextCommissionRequestNumber, 10); } Int32 soldUnitId = 0; Int32 brokerId = 0; var soldUnits = from d in db.TrnSoldUnits where d.IsLocked == true select d; if (soldUnits.Any()) { var soldUnit = soldUnits.FirstOrDefault(); soldUnitId = soldUnit.Id; brokerId = soldUnit.BrokerId; } if (soldUnitId > 0 && brokerId > 0) { Data.TrnCommissionRequest newTrnCommissionRequest = new Data.TrnCommissionRequest() { CommissionRequestNumber = commissionRequestNumber, CommissionRequestDate = Convert.ToDateTime(commissionRequest.CommissionRequestDate), BrokerId = brokerId, SoldUnitId = soldUnitId, CommissionNumber = commissionRequest.CommissionNumber, Amount = commissionRequest.Amount, Remarks = commissionRequest.Remarks, PreparedBy = currentUser.FirstOrDefault().Id, CheckedBy = currentUser.FirstOrDefault().Id, ApprovedBy = currentUser.FirstOrDefault().Id, Status = commissionRequest.Status, IsLocked = commissionRequest.IsLocked, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.TrnCommissionRequests.InsertOnSubmit(newTrnCommissionRequest); db.SubmitChanges(); return(newTrnCommissionRequest.Id); } else { return(0); } } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public HttpResponseMessage GetNewTrnSoldUnitEquitySchedule(string id) { try { var soldUnits = from d in db.TrnSoldUnits where d.Id == Convert.ToInt32(id) select d; if (soldUnits.Any()) { // Remove existing schedule var deleteSchedules = from d in db.TrnSoldUnitEquitySchedules where d.SoldUnitId == Convert.ToInt32(id) select d; if (deleteSchedules.Any()) { foreach (var deleteSchedule in deleteSchedules) { db.TrnSoldUnitEquitySchedules.DeleteOnSubmit(deleteSchedule); } db.SubmitChanges(); } Data.TrnSoldUnitEquitySchedule insertReservationSchedule = new Data.TrnSoldUnitEquitySchedule() { SoldUnitId = Convert.ToInt32(id), PaymentDate = soldUnits.FirstOrDefault().SoldUnitDate, Amortization = soldUnits.FirstOrDefault().Reservation, PaidAmount = 0, BalanceAmount = soldUnits.FirstOrDefault().Reservation, Remarks = "Reservation Fee" }; db.TrnSoldUnitEquitySchedules.InsertOnSubmit(insertReservationSchedule); db.SubmitChanges(); Data.TrnSoldUnitEquitySchedule insertDownpaymentSchedule = new Data.TrnSoldUnitEquitySchedule() { SoldUnitId = Convert.ToInt32(id), PaymentDate = soldUnits.FirstOrDefault().SoldUnitDate, Amortization = soldUnits.FirstOrDefault().DownpaymentValue, PaidAmount = 0, BalanceAmount = soldUnits.FirstOrDefault().DownpaymentValue, Remarks = "Downpayment" }; db.TrnSoldUnitEquitySchedules.InsertOnSubmit(insertDownpaymentSchedule); db.SubmitChanges(); // Insert new schedules Int32 noOfPayments = Decimal.ToInt32(soldUnits.FirstOrDefault().NetEquityNoOfPayments); decimal amortization = soldUnits.FirstOrDefault().NetEquityAmortization; DateTime startDate = soldUnits.FirstOrDefault().SoldUnitDate; decimal equitySpotPayment1 = soldUnits.FirstOrDefault().EquitySpotPayment1; decimal equitySpotPayment2 = soldUnits.FirstOrDefault().EquitySpotPayment2; decimal equitySpotPayment3 = soldUnits.FirstOrDefault().EquitySpotPayment3; DateTime paymentDate = startDate; if (noOfPayments > 0) { for (Int32 p = 1; p <= noOfPayments; p++) { paymentDate = startDate.AddMonths(p); decimal monthlyAmortization = amortization; if (equitySpotPayment1 > 0 && p == 1) { monthlyAmortization = equitySpotPayment1; } if (equitySpotPayment2 > 0 && p == noOfPayments / 2) { monthlyAmortization = equitySpotPayment2; } if (equitySpotPayment3 > 0 && p == noOfPayments) { monthlyAmortization = equitySpotPayment3; } Data.TrnSoldUnitEquitySchedule insertSchedule = new Data.TrnSoldUnitEquitySchedule() { SoldUnitId = Convert.ToInt32(id), PaymentDate = paymentDate, Amortization = monthlyAmortization, PaidAmount = 0, BalanceAmount = monthlyAmortization, Remarks = "Equity " + p }; db.TrnSoldUnitEquitySchedules.InsertOnSubmit(insertSchedule); db.SubmitChanges(); } } else { Data.TrnSoldUnitEquitySchedule insertSchedule = new Data.TrnSoldUnitEquitySchedule() { SoldUnitId = Convert.ToInt32(id), PaymentDate = paymentDate, Amortization = soldUnits.FirstOrDefault().NetEquityBalance, PaidAmount = 0, BalanceAmount = soldUnits.FirstOrDefault().NetEquityBalance, Remarks = "Equity" }; db.TrnSoldUnitEquitySchedules.InsertOnSubmit(insertSchedule); db.SubmitChanges(); } Data.TrnSoldUnitEquitySchedule insertMiscFeeSchedule = new Data.TrnSoldUnitEquitySchedule() { SoldUnitId = Convert.ToInt32(id), PaymentDate = paymentDate.AddMonths(noOfPayments + 1), Amortization = soldUnits.FirstOrDefault().MiscellaneousFeeAmount, PaidAmount = 0, BalanceAmount = soldUnits.FirstOrDefault().MiscellaneousFeeAmount, Remarks = "Miscellaneous Fee" }; db.TrnSoldUnitEquitySchedules.InsertOnSubmit(insertMiscFeeSchedule); db.SubmitChanges(); Data.TrnSoldUnitEquitySchedule insertBalanceSchedule = new Data.TrnSoldUnitEquitySchedule() { SoldUnitId = Convert.ToInt32(id), PaymentDate = paymentDate.AddMonths(noOfPayments + 1), Amortization = soldUnits.FirstOrDefault().Balance, PaidAmount = 0, BalanceAmount = soldUnits.FirstOrDefault().Balance, Remarks = "Balance" }; db.TrnSoldUnitEquitySchedules.InsertOnSubmit(insertBalanceSchedule); db.SubmitChanges(); } return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }