public void Update(TenantModel modelTenant) { FirstName = modelTenant.FirstName; LastName = modelTenant.LastName; Telephone = modelTenant.Telephone; EmailAddress = modelTenant.EmailAddress; Address.Update(modelTenant.Address); }
public IHttpActionResult PutTenant(int id, TenantModel modelTenant) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != modelTenant.TenantId) { return BadRequest(); } // 1. Grab endtry from database by id //var dbTenant = db.Tenants.Find(id); Tenant dbTenant = db.Tenants.FirstOrDefault(t => t.User.UserName == User.Identity.Name && t.TenantId == id); if (dbTenant == null) { return BadRequest(); } // 2. Update entry fetched from the database dbTenant.Update(modelTenant); // 3. Mark entry as modified db.Entry(dbTenant).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TenantExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostTenant(TenantModel tenant) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbTenant = new Tenant(tenant); dbTenant.User = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); db.Tenants.Add(dbTenant); db.SaveChanges(); tenant.TenantId = dbTenant.TenantId; return CreatedAtRoute("DefaultApi", new { id = tenant.TenantId }, tenant); }
public Tenant(TenantModel tenant) { Address = new Address(); this.Update(tenant); }