Beispiel #1
0
        public void Update(TenantModel model)
        {
            TenantId = model.TenantId;
            FirstName = model.FirstName;
            LastName = model.LastName;
            TelephoneNumber = model.TelephoneNumber;
            Email = model.Email;

        }
        public IHttpActionResult PutTenant(int id, TenantModel tenant)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            // 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();
            }

            dbTenant.Update(tenant);
            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);
        }
Beispiel #4
0
 public Tenant(TenantModel model)
 {
     this.Update(model);
 }