public IHttpActionResult PutRoom(int id, Room room) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != room.Id) { return BadRequest(); } unitOfWork.Rooms.Update(room); try { unitOfWork.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!unitOfWork.Rooms.IsExist(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostRoom(Room room, string name) { if (!ModelState.IsValid) { return BadRequest(ModelState); } unitOfWork.Rooms.Add(room); unitOfWork.SaveChanges(); //string userName = User.Identity.GetUserName(); IdentityUser user = await _repo.FindUserByName(name); string userId = user.Id; var link = new UserRoomLink() { RoomId = room.Id, UserId = userId, IsAdmin = true }; unitOfWork.Links.Add(link); unitOfWork.SaveChanges(); //return CreatedAtRoute("DefaultApi", new { id = room.Id }, room); return Ok(room.Id); }