예제 #1
0
 public void Update(TenantsModel t)
 {
     FirstName = t.FirstName;
     LastName = t.LastName;
     AddressId = t.AddressId;
     Telephone = t.Telephone;
     EmailAddress = t.EmailAddress;
     Address.Update(t.Address);
 }
예제 #2
0
 public Tenant(TenantsModel tenant)
 {
     this.Update(tenant);
 }
        public IHttpActionResult PutTenant(int id, TenantsModel tenant)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != tenant.TenantId)
            {
                return BadRequest();
            }

            //var dbTenants = db.Tenants.Find(id);
            var dbTenants = db.Tenants.FirstOrDefault(p => p.User.UserName == User.Identity.Name && p.TenantId == id);
            if (dbTenants == null)
            {
                return BadRequest();
            }

            dbTenants.Update(tenant);

            db.Entry(dbTenants).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TenantExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }