public ActionResult GetConnection() { try { var getComp = db.companies.Where(c => c.CompanyID == 27).FirstOrDefault(); getComp.LeadSourceCompanyID = 0; db.SaveChanges(); } catch (Exception any) { SendUsEmail error = new SendUsEmail(); error.sendError(any.ToString(), "Error MySQL Timeout"); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public ActionResult verifyPayments() { try { var getStripes = (from s in db.stripes join p in db.properties on s.PropertyID equals p.PropertyID join c in db.companies on p.CompanyID equals c.CompanyID where c.Active == 1 select s).ToList(); foreach (var stripe in getStripes) { // Villa Nueva for test StripeConfiguration.SetApiKey(stripe.SecretKey); // Get Payments for a month date range DateTime today = DateTime.Now; var chargeService = new StripeChargeService(); StripeList <StripeCharge> chargeItems = chargeService.List( new StripeChargeListOptions() { Limit = 1000, Created = new StripeDateFilter { GreaterThanOrEqual = today.AddMonths(-1), LessThanOrEqual = today } } ); foreach (var item in chargeItems) { if (item.Refunded) { // Remove it from tenant ledger if there int tenantID = 0; if (!string.IsNullOrEmpty(item.CustomerId)) { var getStripeCustomer = db.stripe_customer.Where(x => x.StripeCustomer == item.CustomerId).FirstOrDefault(); if (getStripeCustomer != null) { tenantID = (int)getStripeCustomer.TenantID; } } else { TenantModel tm = new TenantModel(); tenantID = tm.getTenantID(item.Description); } double amount = (double)item.Amount / 100; SourceType source = item.Source.Type; if (source.ToString() == "Card") { amount = (amount - 0.3) * 0.971; } else { double achAmount = amount * 0.008; if (achAmount > 5) { amount -= 5; } else { amount -= achAmount; } } amount = Math.Round(amount, 2); Decimal paidAmount = (decimal)amount; var getTenantTransaction = (from tt in db.tenanttransactions where tt.TenantID == tenantID && tt.TenantTransactionDate == item.Created.Date && tt.TransactionAmount == paidAmount && (tt.Comment == "Tenant Payment - Online ACH Payment" || tt.Comment == "Tenant Payment - Online Tenant Credit Card Payment" || tt.Comment == "Tenant Payment via ACH" || tt.Comment == "Tenant Payment via Credit Card") select tt).FirstOrDefault(); if (getTenantTransaction != null) { Decimal transactionAmount = getTenantTransaction.TransactionAmount; // Send PM Email var getTenant = db.tenants.Where(x => x.TenantID == tenantID).FirstOrDefault(); var getUnit = db.units.Find(getTenant.UnitID); Email email = new Email(); string ToEmail = ""; ToEmail = email.getPropertyManagerEmail((int)getTenant.PropertyID); if (string.IsNullOrEmpty(ToEmail)) { ToEmail = email.getAdminEmail((int)getTenant.PropertyID); } string emailBody = "The payment of " + string.Format("{0:C}", transactionAmount) + " made on " + item.Created.Date.ToString("MM/dd/yyyy") + " was deleted from "; emailBody += "tenant: " + getTenant.TenantFName + " " + getTenant.TenantLName + ". Unit: " + getUnit.UnitName + ".\n\n"; emailBody += "Reason: Refunded"; string subject = "Tenant Payment Refunded"; int checkRegisterID = getTenantTransaction.CheckRegisterID; var getCR = db.checkregisters.Find(checkRegisterID); if (getCR != null) { db.checkregisters.Remove(getCR); } db.tenanttransactions.Remove(getTenantTransaction); db.SaveChanges(); email.sendEmail(ToEmail, "*****@*****.**", subject, emailBody); } } } } SendUsEmail emailOK = new SendUsEmail(); emailOK.sendAlert("Just run Verify payments", "Verify Payments"); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception any) { SendUsEmail email = new SendUsEmail(); email.sendError(any.ToString(), "Error Verify Refunded Payments"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult UpdateVacantUnits() { try { var getPostVacancies = db.postvacancies.Where(x => x.AutoPostVacancies == 1 || x.AutoRemoveNonVacancies == 1).ToList(); bool sendData = true; foreach (var post in getPostVacancies) { PostData dataPost = new PostData(); dataPost.PropertyID = post.PropertyID; if (post.AutoPostVacancies == 1 && post.AutoRemoveNonVacancies == 1) { // Get only vacant units var getUnits = db.units.Where(x => x.PropertyID == post.PropertyID && x.Occupied == 0).ToList(); List <int> units = new List <int>(); foreach (var unit in getUnits) { units.Add(unit.UnitID); } dataPost.Units = units; } else if (post.AutoPostVacancies == 1 && post.AutoRemoveNonVacancies == 0) { // Update vacant units var getUnits = (from u in db.units where u.PostToVacancies == 1 || u.Occupied == 0 select u).ToList(); List <int> units = new List <int>(); foreach (var unit in getUnits) { units.Add(unit.UnitID); } dataPost.Units = units; } else if (post.AutoPostVacancies == 0 && post.AutoRemoveNonVacancies == 1) { // Update vacant units var getUnits = (from u in db.units where u.PostToVacancies == 1 && u.Occupied == 0 select u).ToList(); List <int> units = new List <int>(); foreach (var unit in getUnits) { units.Add(unit.UnitID); } dataPost.Units = units; } else { sendData = false; } if (sendData) { // Send to apartments.com | apartmentFinder | apartamentos.com (Spanish) | apartmenthomeliving var json = JsonConvert.SerializeObject(dataPost); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(apartmentsComURL); var result = client.PostAsync("", content).Result; // Send to RentJungle var jsonRentJungle = JsonConvert.SerializeObject(dataPost); var contentRentJungle = new StringContent(jsonRentJungle, Encoding.UTF8, "application/json"); HttpClient clientRentJungle = new HttpClient(); clientRentJungle.BaseAddress = new Uri(rentJungleURl); var resultRentJungle = clientRentJungle.PostAsync("", contentRentJungle).Result; } } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception any) { SendUsEmail email = new SendUsEmail(); email.sendError(any.ToString(), "Error Weekly Post Vacancies"); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult PostVacancies() { try { var getPostVacancies = db.postvacancies.Where(x => x.UnitsUpdated == 1).ToList(); foreach (var post in getPostVacancies) { // Post to apartments.com (CoStar) PostData dataPost = new PostData(); dataPost.PropertyID = post.PropertyID; var getUnits = db.units.Where(x => x.PropertyID == post.PropertyID && x.PostToVacancies == 1).ToList(); List <int> units = new List <int>(); foreach (var unit in getUnits) { units.Add(unit.UnitID); } dataPost.Units = units; // Send to apartments.com | apartmentFinder | apartamentos.com (Spanish) | apartmenthomeliving var json = JsonConvert.SerializeObject(dataPost); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(apartmentsComURL); var result = client.PostAsync("", content).Result; // Send to RentJungle var jsonRentJungle = JsonConvert.SerializeObject(dataPost); var contentRentJungle = new StringContent(jsonRentJungle, Encoding.UTF8, "application/json"); HttpClient clientRentJungle = new HttpClient(); clientRentJungle.BaseAddress = new Uri(rentJungleURl); var resultRentJungle = clientRentJungle.PostAsync("", contentRentJungle).Result; // Send to Oodle var jsonOodle = JsonConvert.SerializeObject(dataPost); var contentOodle = new StringContent(jsonOodle, Encoding.UTF8, "application/json"); HttpClient clientOodle = new HttpClient(); clientOodle.BaseAddress = new Uri(oodleURL); var resultOodle = clientOodle.PostAsync("", contentOodle).Result; // Send to Zumper var jsonZumper = JsonConvert.SerializeObject(dataPost); var contentZumper = new StringContent(jsonZumper, Encoding.UTF8, "application/json"); HttpClient clientZumper = new HttpClient(); clientZumper.BaseAddress = new Uri(zumperURL); var resultZumper = clientZumper.PostAsync("", contentZumper).Result; // Send to Sublet /* * var jsonSublet = JsonConvert.SerializeObject(dataPost); * var contentSublet = new StringContent(jsonSublet, Encoding.UTF8, "application/json"); * HttpClient clientSublet = new HttpClient(); * clientSublet.BaseAddress = new Uri(subletURL); * var resultSublet = clientSublet.PostAsync("", contentSublet).Result; */ post.UnitsUpdated = 0; db.SaveChanges(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception any) { SendUsEmail email = new SendUsEmail(); email.sendError(any.ToString(), "Error Daily Post Vacancies"); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult chargeTenants() { try { DateTime dt = DateTime.Now; int d = dt.Day; // get properties var getProperties = (from p in db.properties join c in db.companies on p.CompanyID equals c.CompanyID join pe in db.properties_exclude on p.PropertyID equals pe.PropertyID where p.Active == 0 && c.Active == 1 && p.PropertyID != 9 && p.PropertyID != 1 && pe.AutoBill != '2' select p).ToList(); foreach (var prop in getProperties) { // Check if first day of month to apply rental charges if (d == 1) { int tenantCount = 0; decimal amountCount = 0; int emailCount = 0; int messageCount = 0; // get tenants var getProspects = (from t in db.tenants join p in db.properties on t.PropertyID equals p.PropertyID join tt in db.tenanttransactions on t.TenantID equals tt.TenantID into ps from tt in ps.DefaultIfEmpty() select new { t = t, p = p, tt = tt }) .Where(x => (x.t.PropertyID == prop.PropertyID) && (x.t.Prospect == 2)) .GroupBy(x => x.t.TenantID) .Select(x => new { tenantID = x.Key, tenantFirstName = x.FirstOrDefault().t.TenantFName, tenantLastName = x.FirstOrDefault().t.TenantLName, rentalAmount = x.FirstOrDefault().t.RentalAmount, petRent = x.FirstOrDefault().t.PetRent, houseingAmount = x.FirstOrDefault().t.HousingAmount, utilityCharge = x.FirstOrDefault().t.UtilityCharge, tvCharge = x.FirstOrDefault().t.TVCharge, sercurityDeposit = x.FirstOrDefault().t.SecurityDeposit, hoaFee = x.FirstOrDefault().t.HousingAmount, parkingCharge = x.FirstOrDefault().t.ParkingCharge, storageCharge = x.FirstOrDefault().t.StorageCharge, concessionAmount = x.FirstOrDefault().t.ConcessionAmount, concessionReason = x.FirstOrDefault().t.ConcessionReason, tenantEmail = x.FirstOrDefault().t.TenantEmail, tenantPhone = x.FirstOrDefault().t.TenantPhone, tenantCellPhoneProvider = x.FirstOrDefault().t.CellPhoneProviderID, tenantMoveInDate = x.FirstOrDefault().t.MoveInDate, propertyID = x.FirstOrDefault().p.PropertyID, propertyName = x.FirstOrDefault().p.PropertyName, totalDebit = x.Where(y => (y.tt.TransactionTypeID == 1) && (y.tt.ChargeTypeID != 6) && (y.tt.TenantTransactionDate <= DateTime.Now)).Sum(y => y.tt.TransactionAmount), housingDebit = x.Where(y => (y.tt.TransactionTypeID == 1) && (y.tt.ChargeTypeID == 6) && (y.tt.TenantTransactionDate <= DateTime.Now)).Sum(y => y.tt.TransactionAmount), totalCredit = x.Where(y => (y.tt.TransactionTypeID == 2) && (y.tt.ChargeTypeID != 6) && (y.tt.TenantTransactionDate <= DateTime.Now)).Sum(y => y.tt.TransactionAmount), housingCredit = x.Where(y => (y.tt.TransactionTypeID == 2) && (y.tt.ChargeTypeID == 6) && (y.tt.TenantTransactionDate <= DateTime.Now)).Sum(y => y.tt.TransactionAmount), }).ToList(); } } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception any) { SendUsEmail email = new SendUsEmail(); email.sendError(any.ToString(), "Error Processing Charge Tenants CRON Job"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }