Пример #1
0
        public bool GetUnitTenants(ref BRBUser user)
        {
            var gotTenants = false;

            var soapRequest = new SoapRequest
            {
                Source         = "GetPropertyTenants",
                StaticDataFile = "GetPropertyAndUnitDetails_Response.xml",
                Url            = "GetPropertyAndUnitDetails/RTSClientPortalAPI_API_WSD_GetPropertyAndUnitDetails_Port",
                Action         = "RTSClientPortalAPI_API_WSD_GetPropertyAndUnitDetails_Binder_getPropertyAndUnitDetails"
            };

            try
            {
                user.CurrentUnit.Tenants = new List <BRBTenant>();

                soapRequest.Body.Append("<api:getPropertyAndUnitDetails>");
                soapRequest.Body.AppendFormat("<propertyId>{0}</propertyId>", SafeString(user.CurrentProperty.PropertyID));
                soapRequest.Body.Append("<request>");
                soapRequest.Body.AppendFormat("<!--Optional:--><userId>{0}</userId>", SafeString(user.UserCode));
                soapRequest.Body.AppendFormat("<!--Optional:--><billingCode>{0}</billingCode>", SafeString(user.BillingCode));
                soapRequest.Body.Append("</request>");
                soapRequest.Body.Append("</api:getPropertyAndUnitDetails>");

                var xmlDoc = GetXmlResponse(soapRequest);

                foreach (XmlElement detail in xmlDoc.DocumentElement.GetElementsByTagName("propertyAndUnitsRes"))
                {
                    foreach (XmlElement detailUnits in detail.GetElementsByTagName("units"))
                    {
                        var unitID = detailUnits.SelectSingleNode("unitId").InnerText;

                        if (user.CurrentUnit.UnitID == detailUnits.SelectSingleNode("unitId").InnerText)
                        {
                            //
                            // OCCUPANCY
                            //

                            if (detailUnits.SelectNodes("occupancy").Count > 0) // some Rented Units have no Occupants -- bad data?
                            {
                                if (detailUnits.GetElementsByTagName("noOfOccupants").Item(0) != null)
                                {
                                    user.CurrentUnit.TenantCount = int.Parse(detailUnits.GetElementsByTagName("noOfOccupants").Item(0).InnerText);
                                }

                                if (detailUnits.GetElementsByTagName("initialRent").Item(0) != null)
                                {
                                    user.CurrentUnit.InitialRent = detailUnits.GetElementsByTagName("initialRent").Item(0).InnerText;
                                }

                                if (detailUnits.GetElementsByTagName("datePriorTenancyEnded").Item(0) != null)
                                {
                                    user.CurrentUnit.DatePriorTenancyEnded = DateTime.Parse(detailUnits.GetElementsByTagName("datePriorTenancyEnded").Item(0).InnerText);
                                }

                                if (detailUnits.GetElementsByTagName("reasonPriorTenancyEnded").Item(0) != null)
                                {
                                    user.CurrentUnit.ReasonPriorTenancyEnded = detailUnits.GetElementsByTagName("reasonPriorTenancyEnded").Item(0).InnerText;
                                }

                                if (detailUnits.GetElementsByTagName("smokingProhibitionInLeaseStatus").Item(0) != null)
                                {
                                    user.CurrentUnit.SmokingProhibitionInLeaseStatus = detailUnits.GetElementsByTagName("smokingProhibitionInLeaseStatus").Item(0).InnerText;
                                }

                                if (detailUnits.GetElementsByTagName("smokingProhibitionEffectiveDate").Item(0) != null)
                                {
                                    DateTime dtSmokingProhibitionEffectiveDate = DateTime.MinValue;

                                    if (DateTime.TryParse(detailUnits.GetElementsByTagName("smokingProhibitionEffectiveDate").Item(0).InnerText, out dtSmokingProhibitionEffectiveDate))
                                    {
                                        user.CurrentUnit.SmokingProhibitionEffectiveDate = dtSmokingProhibitionEffectiveDate;
                                    }
                                }

                                //
                                // TENANTS
                                //

                                foreach (XmlElement detailOccBy in detailUnits.GetElementsByTagName("occupants"))
                                {
                                    var tenant = new BRBTenant();

                                    tenant.TenantID    = detailOccBy.SelectSingleNode("occupantId").InnerText;
                                    tenant.FirstName   = detailOccBy.SelectSingleNode("name").SelectSingleNode("firstName").InnerText;
                                    tenant.LastName    = detailOccBy.SelectSingleNode("name").SelectSingleNode("lastName").InnerText;
                                    tenant.PhoneNumber = detailOccBy.SelectSingleNode("contactInfo").SelectSingleNode("phoneNumber").InnerText;
                                    tenant.Email       = detailOccBy.SelectSingleNode("contactInfo").SelectSingleNode("emailAddress").InnerText;

                                    user.CurrentUnit.Tenants.Add(tenant);
                                }
                            }
                        }
                    }
                }

                gotTenants = true;
            }
            catch (Exception ex)
            {
                SetErrorMessage("GetUnitTenants", ex);
            }

            return(gotTenants);
        }
Пример #2
0
        protected void UpdateTenancy_Click(object sender, EventArgs e)
        {
            var user    = Master.User;
            var unit    = user.CurrentUnit;
            var tenants = unit.Tenants;

            try
            {
                foreach (var id in hdnRemovedTenantIDs.Value.Split(','))
                {
                    var existingTenant = unit.Tenants.Where(x => x.TenantID == id).SingleOrDefault();

                    if (existingTenant != null)
                    {
                        unit.Tenants.Remove(existingTenant);
                    }
                }

                foreach (var str in hdnDelimitedTenants.Value.Split('|'))
                {
                    var fields = str.Split('^');

                    if (fields.Length > 1) // ignore "no tenants" entry
                    {
                        var tenant = new BRBTenant
                        {
                            TenantID    = fields[0],
                            FirstName   = fields[1],
                            LastName    = fields[2],
                            PhoneNumber = fields[3],
                            Email       = fields[4]
                        };

                        if (tenant.TenantID == "-1") // new Tenant
                        {
                            unit.Tenants.Add(tenant);
                        }
                    }
                }

                unit.InitialRent = InitRent.Text;

                if (!string.IsNullOrEmpty(TenStDt.Text))
                {
                    unit.TenancyStartDate = DateTime.Parse(TenStDt.Text);
                }

                var housingServices = new List <string>();

                foreach (ListItem item in HServs.Items)
                {
                    if (item.Selected && item.Text != "Other")
                    {
                        housingServices.Add(item.Text);
                    }
                }

                unit.HServices = string.Join(",", housingServices);

                if (!string.IsNullOrEmpty(HServOthrBox.Text))
                {
                    unit.OtherHServices = HServOthrBox.Text;
                }

                unit.SmokingProhibitionInLeaseStatus = RB1.SelectedValue;

                if (!string.IsNullOrEmpty(SmokeDt.Text))
                {
                    unit.SmokingProhibitionEffectiveDate = DateTime.Parse(SmokeDt.Text);
                }

                if (!string.IsNullOrEmpty(PTenDt.Text))
                {
                    unit.DatePriorTenancyEnded = DateTime.Parse(PTenDt.Text);
                }

                unit.TerminationReason      = TermReas.SelectedValue;
                unit.OtherTerminationReason = TermDescr.Text;

                unit.DeclarationInitials = DeclareInits.Text;

                if (Master.DataProvider.UpdateUnitTenancy(ref user))
                {
                    Session["ShowAfterRedirect"] = "Tenancy has been updated.|Update Tenancy";

                    Response.Redirect("~/MyProperties/MyUnits", false);
                }
                else
                {
                    Master.ShowErrorModal(Master.DataProvider.ErrorMessage, "Update Tenancy");
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("UpdateTenancy", ex);
                Master.ShowErrorModal("Error updating Tenancy.");
            }
        }