public async Task <ActionResult <TenantProperty> > PostTenantProperty(TenantProperty tenantProperty) { _context.TenantProperty.Add(tenantProperty); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTenantProperty", new { id = tenantProperty.tenantPropertyID }, tenantProperty)); }
public async Task <IActionResult> PutTenantProperty(int id, TenantProperty tenantProperty) { if (id != tenantProperty.tenantPropertyID) { return(BadRequest()); } _context.Entry(tenantProperty).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TenantPropertyExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public JsonResult AddTenantToProperty(AddTenantToPropertyModel model) { var user = User.Identity.Name; var login = AccountService.GetLoginByEmail(user); var tenant = AccountService.GetLoginByEmail(model.TenantEmail); if (tenant == null) { var temPass = UtilService.GeneraterRandomKey(8); var createRes = AccountService.CreateTenantAccount(model, login, temPass); if (!createRes.IsSuccess) { tenant = createRes.NewObject as Login; return(Json(new { Success = false, NewPropId = model.Id })); } } var newTenantProperty = new TenantProperty { Id = model.Id, TenantId = tenant.Id, CreatedBy = User.Identity.Name, CreatedOn = DateTime.Now, UpdatedBy = User.Identity.Name, UpdatedOn = DateTime.Now, StartDate = model.StartDate, EndDate = model.EndDate, PaymentAmount = model.PaymentAmount, PaymentFrequencyId = model.PaymentFrequencyId, PropertyId = model.PropertyId, PaymentStartDate = model.PaymentStartDate, PaymentDueDate = model.PaymentDueDate, IsMainTenant = model.IsMainTenant, IsActive = tenant.IsActive }; if (model.Liabilities != null) { model.Liabilities.ForEach(x => { db.TenantPropertyLiability.Add(new TenantPropertyLiability { LiabilityName = x.Name, Amount = x.Amount, TenantProperty = newTenantProperty }); }); } db.TenantProperty.Add(newTenantProperty); db.SaveChanges(); return(Json(new { Success = true, NewId = newTenantProperty.Id })); }